misc: split test module and simplify test data
This commit is contained in:
parent
5cff35f63f
commit
d1557f0473
|
@ -3047,98 +3047,6 @@ def test_settings_geolocation(pub):
|
|||
assert pub.cfg['misc']['default-position'] == '1.234;-1.234'
|
||||
|
||||
|
||||
def test_wscalls_new(pub):
|
||||
create_superuser(pub)
|
||||
NamedWsCall.wipe()
|
||||
app = login(get_app(pub))
|
||||
|
||||
# go to the page and cancel
|
||||
resp = app.get('/backoffice/settings/wscalls/')
|
||||
resp = resp.click('New webservice call')
|
||||
resp = resp.forms[0].submit('cancel')
|
||||
assert resp.location == 'http://example.net/backoffice/settings/wscalls/'
|
||||
|
||||
# go to the page and add a webservice call
|
||||
resp = app.get('/backoffice/settings/wscalls/')
|
||||
resp = resp.click('New webservice call')
|
||||
resp.form['name'] = 'a new webservice call'
|
||||
resp.form['description'] = 'description'
|
||||
resp.form['request$url'] = 'http://remote.example.net/json'
|
||||
resp = resp.form.submit('submit')
|
||||
assert resp.location == 'http://example.net/backoffice/settings/wscalls/'
|
||||
resp = resp.follow()
|
||||
assert 'a new webservice call' in resp.text
|
||||
resp = resp.click('a new webservice call')
|
||||
assert 'Webservice Call - a new webservice call' in resp.text
|
||||
resp = resp.click('Edit')
|
||||
assert 'Edit webservice call' in resp.text
|
||||
|
||||
assert NamedWsCall.get('a_new_webservice_call').name == 'a new webservice call'
|
||||
|
||||
|
||||
def test_wscalls_view(pub):
|
||||
create_superuser(pub)
|
||||
NamedWsCall.wipe()
|
||||
|
||||
wscall = NamedWsCall(name='xxx')
|
||||
wscall.description = 'description'
|
||||
wscall.request = {
|
||||
'url': 'http://remote.example.net/json',
|
||||
'request_signature_key': 'xxx',
|
||||
'qs_data': {'a': 'b'},
|
||||
'method': 'POST',
|
||||
'post_data': {'c': 'd'},
|
||||
}
|
||||
wscall.store()
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/settings/wscalls/%s/' % wscall.id)
|
||||
assert 'http://remote.example.net/json' in resp.text
|
||||
|
||||
|
||||
def test_wscalls_edit(pub):
|
||||
test_wscalls_view(pub)
|
||||
|
||||
app = login(get_app(pub))
|
||||
|
||||
resp = app.get('/backoffice/settings/wscalls/xxx/')
|
||||
resp = resp.click(href='edit')
|
||||
assert resp.form['name'].value == 'xxx'
|
||||
assert 'slug' in resp.form.fields
|
||||
resp.form['description'] = 'bla bla bla'
|
||||
resp = resp.form.submit('submit')
|
||||
assert resp.location == 'http://example.net/backoffice/settings/wscalls/xxx/'
|
||||
resp = resp.follow()
|
||||
|
||||
assert NamedWsCall.get('xxx').description == 'bla bla bla'
|
||||
|
||||
resp = app.get('/backoffice/settings/wscalls/xxx/')
|
||||
resp = resp.click(href='edit')
|
||||
assert resp.form['name'].value == 'xxx'
|
||||
assert 'slug' in resp.form.fields
|
||||
resp.form['slug'] = 'yyy'
|
||||
resp = resp.form.submit('submit')
|
||||
assert resp.location == 'http://example.net/backoffice/settings/wscalls/yyy/'
|
||||
|
||||
|
||||
def test_wscalls_delete(pub):
|
||||
test_wscalls_view(pub)
|
||||
assert NamedWsCall.count() == 1
|
||||
|
||||
app = login(get_app(pub))
|
||||
|
||||
resp = app.get('/backoffice/settings/wscalls/xxx/')
|
||||
resp = resp.click(href='delete')
|
||||
resp = resp.form.submit('cancel')
|
||||
assert resp.location == 'http://example.net/backoffice/settings/wscalls/'
|
||||
|
||||
resp = app.get('/backoffice/settings/wscalls/xxx/')
|
||||
resp = resp.click(href='delete')
|
||||
resp = resp.form.submit('submit')
|
||||
assert resp.location == 'http://example.net/backoffice/settings/wscalls/'
|
||||
assert NamedWsCall.count() == 0
|
||||
|
||||
|
||||
def test_settings_permissions(pub):
|
||||
create_superuser(pub)
|
||||
role1 = create_role()
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import pytest
|
||||
|
||||
from wcs.qommon.http_request import HTTPRequest
|
||||
from wcs.wscalls import NamedWsCall
|
||||
|
||||
from utilities import get_app, login, create_temporary_pub, clean_temporary_pub
|
||||
from test_admin_pages import create_superuser
|
||||
|
||||
|
||||
def pytest_generate_tests(metafunc):
|
||||
if 'pub' in metafunc.fixturenames:
|
||||
metafunc.parametrize('pub', ['pickle', 'sql', 'pickle-templates'], indirect=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pub(request):
|
||||
pub = create_temporary_pub(
|
||||
sql_mode=bool('sql' in request.param),
|
||||
templates_mode=bool('templates' in request.param)
|
||||
)
|
||||
|
||||
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
|
||||
pub.set_app_dir(req)
|
||||
pub.cfg['identification'] = {'methods': ['password']}
|
||||
pub.cfg['language'] = {'language': 'en'}
|
||||
pub.write_cfg()
|
||||
|
||||
return pub
|
||||
|
||||
|
||||
def teardown_module(module):
|
||||
clean_temporary_pub()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def wscall():
|
||||
NamedWsCall.wipe()
|
||||
wscall = NamedWsCall(name='xxx')
|
||||
wscall.description = 'description'
|
||||
wscall.request = {
|
||||
'url': 'http://remote.example.net/json',
|
||||
'request_signature_key': 'xxx',
|
||||
'qs_data': {'a': 'b'},
|
||||
'method': 'POST',
|
||||
'post_data': {'c': 'd'},
|
||||
}
|
||||
wscall.store()
|
||||
return wscall
|
||||
|
||||
|
||||
def test_wscalls_new(pub):
|
||||
create_superuser(pub)
|
||||
NamedWsCall.wipe()
|
||||
app = login(get_app(pub))
|
||||
|
||||
# go to the page and cancel
|
||||
resp = app.get('/backoffice/settings/wscalls/')
|
||||
resp = resp.click('New webservice call')
|
||||
resp = resp.forms[0].submit('cancel')
|
||||
assert resp.location == 'http://example.net/backoffice/settings/wscalls/'
|
||||
|
||||
# go to the page and add a webservice call
|
||||
resp = app.get('/backoffice/settings/wscalls/')
|
||||
resp = resp.click('New webservice call')
|
||||
resp.form['name'] = 'a new webservice call'
|
||||
resp.form['description'] = 'description'
|
||||
resp.form['request$url'] = 'http://remote.example.net/json'
|
||||
resp = resp.form.submit('submit')
|
||||
assert resp.location == 'http://example.net/backoffice/settings/wscalls/'
|
||||
resp = resp.follow()
|
||||
assert 'a new webservice call' in resp.text
|
||||
resp = resp.click('a new webservice call')
|
||||
assert 'Webservice Call - a new webservice call' in resp.text
|
||||
resp = resp.click('Edit')
|
||||
assert 'Edit webservice call' in resp.text
|
||||
|
||||
assert NamedWsCall.get('a_new_webservice_call').name == 'a new webservice call'
|
||||
|
||||
|
||||
def test_wscalls_view(pub, wscall):
|
||||
create_superuser(pub)
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/settings/wscalls/%s/' % wscall.id)
|
||||
assert 'http://remote.example.net/json' in resp.text
|
||||
|
||||
|
||||
def test_wscalls_edit(pub, wscall):
|
||||
create_superuser(pub)
|
||||
|
||||
app = login(get_app(pub))
|
||||
|
||||
resp = app.get('/backoffice/settings/wscalls/xxx/')
|
||||
resp = resp.click(href='edit')
|
||||
assert resp.form['name'].value == 'xxx'
|
||||
assert 'slug' in resp.form.fields
|
||||
resp.form['description'] = 'bla bla bla'
|
||||
resp = resp.form.submit('submit')
|
||||
assert resp.location == 'http://example.net/backoffice/settings/wscalls/xxx/'
|
||||
resp = resp.follow()
|
||||
|
||||
assert NamedWsCall.get('xxx').description == 'bla bla bla'
|
||||
|
||||
resp = app.get('/backoffice/settings/wscalls/xxx/')
|
||||
resp = resp.click(href='edit')
|
||||
assert resp.form['name'].value == 'xxx'
|
||||
assert 'slug' in resp.form.fields
|
||||
resp.form['slug'] = 'yyy'
|
||||
resp = resp.form.submit('submit')
|
||||
assert resp.location == 'http://example.net/backoffice/settings/wscalls/yyy/'
|
||||
|
||||
|
||||
def test_wscalls_delete(pub, wscall):
|
||||
create_superuser(pub)
|
||||
|
||||
app = login(get_app(pub))
|
||||
|
||||
resp = app.get('/backoffice/settings/wscalls/xxx/')
|
||||
resp = resp.click(href='delete')
|
||||
resp = resp.form.submit('cancel')
|
||||
assert resp.location == 'http://example.net/backoffice/settings/wscalls/'
|
||||
|
||||
resp = app.get('/backoffice/settings/wscalls/xxx/')
|
||||
resp = resp.click(href='delete')
|
||||
resp = resp.form.submit('submit')
|
||||
assert resp.location == 'http://example.net/backoffice/settings/wscalls/'
|
||||
assert NamedWsCall.count() == 0
|
Loading…
Reference in New Issue