tests: update datasource tests to use a pub fixture
This commit is contained in:
parent
02094a491b
commit
60f215786a
|
@ -16,18 +16,14 @@ from wcs.data_sources import NamedDataSource, register_data_source_function
|
|||
|
||||
import mock
|
||||
from test_widgets import MockHtmlForm, mock_form_submission
|
||||
from utilities import create_temporary_pub
|
||||
from utilities import create_temporary_pub, clean_temporary_pub
|
||||
|
||||
|
||||
def setup_module(module):
|
||||
cleanup()
|
||||
|
||||
global pub
|
||||
|
||||
@pytest.fixture
|
||||
def pub():
|
||||
pub = create_temporary_pub()
|
||||
pub.cfg['debug'] = {'logger': True}
|
||||
pub.write_cfg()
|
||||
pub.set_config()
|
||||
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
|
||||
pub.set_app_dir(req)
|
||||
|
||||
open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w').write(
|
||||
'''
|
||||
|
@ -36,18 +32,22 @@ api.example.com = 1234
|
|||
'''
|
||||
)
|
||||
|
||||
pub.load_site_options()
|
||||
|
||||
return pub
|
||||
|
||||
|
||||
def teardown_module(module):
|
||||
shutil.rmtree(pub.APP_DIR)
|
||||
clean_temporary_pub()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def no_request_pub(request):
|
||||
def no_request_pub(pub, request):
|
||||
pub._request = None
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def requests_pub(request):
|
||||
def requests_pub(pub, request):
|
||||
req = HTTPRequest(None, {'SERVER_NAME': 'example.net', 'SCRIPT_NAME': ''})
|
||||
pub._set_request(req)
|
||||
return req
|
||||
|
@ -78,7 +78,7 @@ def test_item_field_python_datasource(requests_pub):
|
|||
assert widget.parse() == '1'
|
||||
|
||||
|
||||
def test_python_datasource():
|
||||
def test_python_datasource(pub):
|
||||
plain_list = [('1', 'foo'), ('2', 'bar')]
|
||||
datasource = {'type': 'formula', 'value': repr(plain_list)}
|
||||
assert data_sources.get_items(datasource) == [
|
||||
|
@ -132,7 +132,7 @@ def test_python_datasource():
|
|||
]
|
||||
|
||||
|
||||
def test_python_datasource_with_evalutils():
|
||||
def test_python_datasource_with_evalutils(pub):
|
||||
plain_list = [
|
||||
{'id': 'foo', 'text': 'Foo', 'value': '2017-01-01'},
|
||||
{'id': 'bar', 'text': 'Bar', 'value': '2015-01-01'},
|
||||
|
@ -146,7 +146,7 @@ def test_python_datasource_with_evalutils():
|
|||
]
|
||||
|
||||
|
||||
def test_json_datasource(requests_pub, http_requests):
|
||||
def test_json_datasource(pub, requests_pub, http_requests):
|
||||
req = get_request()
|
||||
get_request().datasources_cache = {}
|
||||
datasource = {'type': 'json', 'value': ''}
|
||||
|
@ -365,7 +365,7 @@ def test_json_datasource(requests_pub, http_requests):
|
|||
]
|
||||
|
||||
|
||||
def test_json_datasource_bad_url(http_requests, caplog):
|
||||
def test_json_datasource_bad_url(pub, http_requests, caplog):
|
||||
datasource = {'type': 'json', 'value': 'http://remote.example.net/404'}
|
||||
assert data_sources.get_items(datasource) == []
|
||||
assert 'Error loading JSON data source' in caplog.records[-1].message
|
||||
|
@ -386,7 +386,7 @@ def test_json_datasource_bad_url(http_requests, caplog):
|
|||
assert 'Error reading JSON data source output (err 1)' in caplog.records[-1].message
|
||||
|
||||
|
||||
def test_json_datasource_bad_url_scheme(caplog):
|
||||
def test_json_datasource_bad_url_scheme(pub, caplog):
|
||||
datasource = {'type': 'json', 'value': ''}
|
||||
assert data_sources.get_items(datasource) == []
|
||||
assert caplog.records[-1].message == 'Empty URL in JSON data source'
|
||||
|
@ -402,7 +402,7 @@ def test_json_datasource_bad_url_scheme(caplog):
|
|||
assert 'invalid scheme in URL' in caplog.records[-1].message
|
||||
|
||||
|
||||
def test_geojson_datasource(requests_pub, http_requests):
|
||||
def test_geojson_datasource(pub, requests_pub, http_requests):
|
||||
get_request()
|
||||
get_request().datasources_cache = {}
|
||||
datasource = {'type': 'geojson', 'value': ''}
|
||||
|
@ -741,7 +741,7 @@ def test_geojson_datasource(requests_pub, http_requests):
|
|||
]
|
||||
|
||||
|
||||
def test_geojson_datasource_bad_url(http_requests, caplog):
|
||||
def test_geojson_datasource_bad_url(pub, http_requests, caplog):
|
||||
datasource = {'type': 'geojson', 'value': 'http://remote.example.net/404'}
|
||||
assert data_sources.get_items(datasource) == []
|
||||
assert 'Error loading JSON data source' in caplog.records[-1].message
|
||||
|
@ -762,7 +762,7 @@ def test_geojson_datasource_bad_url(http_requests, caplog):
|
|||
assert 'Error reading JSON data source output (err 1)' in caplog.records[-1].message
|
||||
|
||||
|
||||
def test_geojson_datasource_bad_url_scheme(caplog):
|
||||
def test_geojson_datasource_bad_url_scheme(pub, caplog):
|
||||
datasource = {'type': 'geojson', 'value': ''}
|
||||
assert data_sources.get_items(datasource) == []
|
||||
assert caplog.records[-1].message == 'Empty URL in GeoJSON data source'
|
||||
|
@ -778,7 +778,7 @@ def test_geojson_datasource_bad_url_scheme(caplog):
|
|||
assert 'invalid scheme in URL' in caplog.records[-1].message
|
||||
|
||||
|
||||
def test_item_field_named_python_datasource():
|
||||
def test_item_field_named_python_datasource(requests_pub):
|
||||
NamedDataSource.wipe()
|
||||
data_source = NamedDataSource(name='foobar')
|
||||
data_source.data_source = {'type': 'formula', 'value': repr([('1', 'un'), ('2', 'deux')])}
|
||||
|
@ -796,7 +796,7 @@ def test_item_field_named_python_datasource():
|
|||
assert widget.options == [('1', 'un', '1'), ('2', 'deux', '2')]
|
||||
|
||||
|
||||
def test_register_data_source_function():
|
||||
def test_register_data_source_function(pub):
|
||||
def xxx():
|
||||
return [('1', 'foo'), ('2', 'bar')]
|
||||
|
||||
|
@ -813,7 +813,7 @@ def test_register_data_source_function():
|
|||
]
|
||||
|
||||
|
||||
def test_data_source_substitution_variables():
|
||||
def test_data_source_substitution_variables(pub):
|
||||
NamedDataSource.wipe()
|
||||
data_source = NamedDataSource(name='foobar')
|
||||
data_source.data_source = {'type': 'formula', 'value': repr(['un', 'deux'])}
|
||||
|
@ -823,14 +823,14 @@ def test_data_source_substitution_variables():
|
|||
assert context.get('data_source').foobar == [{'id': 'un', 'text': 'un'}, {'id': 'deux', 'text': 'deux'}]
|
||||
|
||||
|
||||
def test_data_source_slug_name():
|
||||
def test_data_source_slug_name(pub):
|
||||
NamedDataSource.wipe()
|
||||
data_source = NamedDataSource(name='foo bar')
|
||||
data_source.store()
|
||||
assert data_source.slug == 'foo_bar'
|
||||
|
||||
|
||||
def test_data_source_new_id():
|
||||
def test_data_source_new_id(pub):
|
||||
NamedDataSource.wipe()
|
||||
data_source = NamedDataSource(name='foo bar')
|
||||
data_source.store()
|
||||
|
@ -848,7 +848,7 @@ def test_data_source_new_id():
|
|||
assert data_source.id == '1'
|
||||
|
||||
|
||||
def test_optional_item_field_with_data_source():
|
||||
def test_optional_item_field_with_data_source(requests_pub):
|
||||
NamedDataSource.wipe()
|
||||
data_source = NamedDataSource(name='foobar')
|
||||
data_source.data_source = {'type': 'formula', 'value': repr([('1', 'un'), ('2', 'deux')])}
|
||||
|
@ -867,7 +867,7 @@ def test_optional_item_field_with_data_source():
|
|||
assert widget.options == [('1', 'un', '1'), ('2', 'deux', '2')]
|
||||
|
||||
|
||||
def test_data_source_unicode():
|
||||
def test_data_source_unicode(pub):
|
||||
NamedDataSource.wipe()
|
||||
data_source = NamedDataSource(name='foobar')
|
||||
data_source.data_source = {'type': 'formula', 'value': "['uné', 'deux']"}
|
||||
|
@ -1069,7 +1069,7 @@ def test_named_datasource_id_parameter(requests_pub):
|
|||
assert urlopen.call_count == 1 # no new call
|
||||
|
||||
|
||||
def test_named_datasource_in_formdef():
|
||||
def test_named_datasource_in_formdef(pub):
|
||||
from wcs.formdef import FormDef
|
||||
|
||||
NamedDataSource.wipe()
|
||||
|
|
Loading…
Reference in New Issue