tests: check form auth/tryauth/formdata URLs
This commit is contained in:
parent
7a8496a780
commit
19d938d9c1
|
@ -30,6 +30,19 @@ def create_formdef():
|
|||
formdef.store()
|
||||
return formdef
|
||||
|
||||
def create_user():
|
||||
pub.user_class.wipe()
|
||||
PasswordAccount.wipe()
|
||||
|
||||
user = pub.user_class()
|
||||
user.email = 'foo@localhost'
|
||||
user.store()
|
||||
account = PasswordAccount(id='foo')
|
||||
account.set_password('foo')
|
||||
account.user_id = user.id
|
||||
account.store()
|
||||
return user
|
||||
|
||||
def test_home():
|
||||
create_formdef()
|
||||
home = get_app(pub).get('/')
|
||||
|
@ -136,15 +149,24 @@ def test_form_multi_page():
|
|||
data = formdef.data_class().get(1)
|
||||
assert data.data == {'1': 'foo', '3': 'bar'}
|
||||
|
||||
def test_form_submit_with_user():
|
||||
user = pub.user_class()
|
||||
user.email = 'foo@localhost'
|
||||
user.store()
|
||||
account = PasswordAccount(id='foo')
|
||||
account.set_password('foo')
|
||||
account.user_id = user.id
|
||||
account.store()
|
||||
def test_form_multi_page_condition():
|
||||
formdef = create_formdef()
|
||||
formdef.data_class().wipe()
|
||||
formdef.fields = [fields.PageField(id='0', label='1st page', type='page'),
|
||||
fields.StringField(id='1', label='string'),
|
||||
fields.PageField(id='2', label='2nd page', type='page', condition='False'),
|
||||
fields.StringField(id='3', label='string 2')]
|
||||
formdef.store()
|
||||
resp = get_app(pub).get('/test/')
|
||||
resp.forms[0]['f1'] = 'foo'
|
||||
resp = resp.forms[0].submit('submit') # should go straight to validation
|
||||
assert 'Check values then click submit.' in resp.body
|
||||
assert resp.forms[0]['previous']
|
||||
resp = resp.forms[0].submit('previous')
|
||||
assert resp.forms[0]['f1']
|
||||
|
||||
def test_form_submit_with_user():
|
||||
create_user()
|
||||
formdef = create_formdef()
|
||||
formdef.data_class().wipe()
|
||||
page = login(get_app(pub), username='foo', password='foo').get('/test/')
|
||||
|
@ -158,3 +180,55 @@ def test_form_submit_with_user():
|
|||
# check the user received a copy by email
|
||||
assert emails.emails.get('New form (test)')
|
||||
assert emails.emails.get('New form (test)')['kwargs']['email_rcpt'] == ['foo@localhost']
|
||||
|
||||
def test_form_visit_existing():
|
||||
user = create_user()
|
||||
formdef = create_formdef()
|
||||
formdef.data_class().wipe()
|
||||
|
||||
formdata = formdef.data_class()()
|
||||
formdata.store()
|
||||
|
||||
formdata_user = formdef.data_class()()
|
||||
formdata_user.user_id = user.id
|
||||
formdata_user.store()
|
||||
|
||||
resp = get_app(pub).get('/test/%s/' % formdata.id)
|
||||
assert resp.location == 'http://example.net/login'
|
||||
|
||||
resp = get_app(pub).get('/test/%s/' % formdata_user.id)
|
||||
assert resp.location == 'http://example.net/login'
|
||||
|
||||
resp = login(get_app(pub), username='foo', password='foo').get('/test/%s/' % formdata_user.id)
|
||||
assert 'The form has been recorded on' in resp
|
||||
|
||||
def test_form_auth():
|
||||
create_user()
|
||||
formdef = create_formdef()
|
||||
formdef.data_class().wipe()
|
||||
resp = get_app(pub).get('/test/auth')
|
||||
assert resp.location == 'http://example.net/login/?ReturnUrl=http%3A//example.net/test/'
|
||||
|
||||
resp = login(get_app(pub), username='foo', password='foo').get('/test/auth')
|
||||
assert resp.location == 'http://example.net/test/'
|
||||
|
||||
def test_form_tryauth():
|
||||
create_user()
|
||||
formdef = create_formdef()
|
||||
formdef.data_class().wipe()
|
||||
resp = get_app(pub).get('/test/tryauth')
|
||||
assert resp.location == 'http://example.net/test/'
|
||||
|
||||
app = login(get_app(pub), username='foo', password='foo')
|
||||
pub.cfg['identification'] = {'methods': ['idp']}
|
||||
pub.write_cfg()
|
||||
# if the user is logged in, the form should be presented
|
||||
resp = app.get('/test/tryauth')
|
||||
assert resp.location == 'http://example.net/test/'
|
||||
|
||||
# if the user is unlogged, there should be a passive redirection to SSO
|
||||
resp = get_app(pub).get('/test/tryauth')
|
||||
assert 'IsPassive=true' in resp.location
|
||||
|
||||
pub.cfg['identification'] = {'methods': ['password']}
|
||||
pub.write_cfg()
|
||||
|
|
Loading…
Reference in New Issue