tests: revamp test datasource fixtures
This commit is contained in:
parent
2bb5875a6e
commit
bf2bc8a4c6
|
@ -21,22 +21,36 @@ from utilities import create_temporary_pub
|
|||
def setup_module(module):
|
||||
cleanup()
|
||||
|
||||
global pub, req
|
||||
global pub
|
||||
|
||||
pub = create_temporary_pub()
|
||||
pub.cfg['debug'] = {'logger': True}
|
||||
pub.write_cfg()
|
||||
pub.set_config()
|
||||
|
||||
req = HTTPRequest(None, {'SERVER_NAME': 'example.net', 'SCRIPT_NAME': ''})
|
||||
pub._set_request(req)
|
||||
open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w').write('''
|
||||
[wscall-secrets]
|
||||
api.example.com = 1234
|
||||
''')
|
||||
|
||||
|
||||
def teardown_module(module):
|
||||
shutil.rmtree(pub.APP_DIR)
|
||||
|
||||
|
||||
def test_item_field_python_datasource():
|
||||
@pytest.fixture
|
||||
def no_request_pub(request):
|
||||
pub._request = None
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def requests_pub(request):
|
||||
req = HTTPRequest(None, {'SERVER_NAME': 'example.net', 'SCRIPT_NAME': ''})
|
||||
pub._set_request(req)
|
||||
return req
|
||||
|
||||
def test_item_field_python_datasource(requests_pub):
|
||||
req = get_request()
|
||||
field = fields.ItemField()
|
||||
field.id = 1
|
||||
field.data_source = {
|
||||
|
@ -117,6 +131,7 @@ def test_python_datasource_with_evalutils():
|
|||
('foo', 'Foo', 'foo', {'id': 'foo', 'text': 'Foo', 'value': '2017-01-01'})]
|
||||
|
||||
def test_json_datasource(http_requests):
|
||||
req = get_request()
|
||||
get_request().datasources_cache = {}
|
||||
datasource = {'type': 'json', 'value': ''}
|
||||
assert data_sources.get_items(datasource) == []
|
||||
|
@ -382,17 +397,6 @@ def test_data_source_unicode():
|
|||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def no_request_pub(request):
|
||||
pub = create_temporary_pub()
|
||||
pub.app_dir = os.path.join(pub.APP_DIR, 'example.net')
|
||||
pub.set_config()
|
||||
open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w').write('''
|
||||
[wscall-secrets]
|
||||
api.example.com = 1234
|
||||
''')
|
||||
return pub
|
||||
|
||||
def test_data_source_signed(no_request_pub):
|
||||
NamedDataSource.wipe()
|
||||
data_source = NamedDataSource(name='foobar')
|
||||
|
@ -440,7 +444,7 @@ def test_data_source_signed(no_request_pub):
|
|||
unsigned_url = urlopen.call_args[0][0]
|
||||
assert unsigned_url == 'https://no-secret.example.com/json'
|
||||
|
||||
def test_named_datasource_json_cache():
|
||||
def test_named_datasource_json_cache(requests_pub):
|
||||
NamedDataSource.wipe()
|
||||
datasource = NamedDataSource(name='foobar')
|
||||
datasource.data_source = {'type': 'json', 'value': 'http://whatever/'}
|
||||
|
|
Loading…
Reference in New Issue