2018-05-28 20:41:53 +00:00
|
|
|
from bs4 import BeautifulSoup as Soup
|
2018-05-31 13:40:30 +00:00
|
|
|
from .fixtures import ( # noqa
|
2018-05-28 20:41:53 +00:00
|
|
|
app_client,
|
|
|
|
)
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
def test_plugins_dir_plugin(app_client):
|
|
|
|
response = app_client.get(
|
2018-06-17 18:34:16 +00:00
|
|
|
"/fixtures.json?sql=select+convert_units(100%2C+'m'%2C+'ft')"
|
2018-05-28 20:41:53 +00:00
|
|
|
)
|
|
|
|
assert pytest.approx(328.0839) == response.json['rows'][0][0]
|
|
|
|
|
|
|
|
|
2018-05-28 21:23:48 +00:00
|
|
|
def test_plugin_extra_css_urls(app_client):
|
2018-06-05 03:53:12 +00:00
|
|
|
response = app_client.get('/')
|
2018-05-28 21:23:48 +00:00
|
|
|
links = Soup(response.body, 'html.parser').findAll('link')
|
|
|
|
assert [
|
|
|
|
l for l in links
|
|
|
|
if l.attrs == {
|
|
|
|
'rel': ['stylesheet'],
|
|
|
|
'href': 'https://example.com/app.css'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def test_plugin_extra_js_urls(app_client):
|
2018-06-05 03:53:12 +00:00
|
|
|
response = app_client.get('/')
|
2018-05-28 21:23:48 +00:00
|
|
|
scripts = Soup(response.body, 'html.parser').findAll('script')
|
|
|
|
assert [
|
|
|
|
s for s in scripts
|
|
|
|
if s.attrs == {
|
|
|
|
'integrity': 'SRIHASH',
|
|
|
|
'crossorigin': 'anonymous',
|
|
|
|
'src': 'https://example.com/jquery.js'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2018-05-28 20:41:53 +00:00
|
|
|
def test_plugins_with_duplicate_js_urls(app_client):
|
|
|
|
# If two plugins both require jQuery, jQuery should be loaded only once
|
|
|
|
response = app_client.get(
|
2018-06-17 18:34:16 +00:00
|
|
|
"/fixtures"
|
2018-05-28 20:41:53 +00:00
|
|
|
)
|
|
|
|
# This test is a little tricky, as if the user has any other plugins in
|
|
|
|
# their current virtual environment those may affect what comes back too.
|
|
|
|
# What matters is that https://example.com/jquery.js is only there once
|
|
|
|
# and it comes before plugin1.js and plugin2.js which could be in either
|
|
|
|
# order
|
|
|
|
scripts = Soup(response.body, 'html.parser').findAll('script')
|
|
|
|
srcs = [s['src'] for s in scripts if s.get('src')]
|
|
|
|
# No duplicates allowed:
|
|
|
|
assert len(srcs) == len(set(srcs))
|
|
|
|
# jquery.js loaded once:
|
|
|
|
assert 1 == srcs.count('https://example.com/jquery.js')
|
|
|
|
# plugin1.js and plugin2.js are both there:
|
|
|
|
assert 1 == srcs.count('https://example.com/plugin1.js')
|
|
|
|
assert 1 == srcs.count('https://example.com/plugin2.js')
|
|
|
|
# jquery comes before them both
|
|
|
|
assert srcs.index(
|
|
|
|
'https://example.com/jquery.js'
|
|
|
|
) < srcs.index(
|
|
|
|
'https://example.com/plugin1.js'
|
|
|
|
)
|
|
|
|
assert srcs.index(
|
|
|
|
'https://example.com/jquery.js'
|
|
|
|
) < srcs.index(
|
|
|
|
'https://example.com/plugin2.js'
|
|
|
|
)
|