7168 |
7168 |
resp = resp.follow()
|
7169 |
7169 |
assert '<div class="value">card plop</div>' in resp
|
7170 |
7170 |
assert '<div class="value">card plop2</div>' in resp
|
7171 |
7171 |
|
7172 |
7172 |
# check cards are links in backoffice
|
7173 |
7173 |
resp = app.get('/backoffice/management' + resp.request.path)
|
7174 |
7174 |
assert '<div class="value"><a href="http://example.net/backoffice/data/foo/%s/">card plop</a></div></div>' % card.id in resp
|
7175 |
7175 |
assert '<div class="value"><a href="http://example.net/backoffice/data/foo/%s/">card plop2</a></div></div>' % card2.id in resp
|
|
7176 |
|
|
7177 |
|
|
7178 |
def test_backoffice_formdef_submit_only_allow_one(pub, local_user):
|
|
7179 |
user = create_user(pub)
|
|
7180 |
user.name_identifiers = ['ABCDEFGHIJ']
|
|
7181 |
user.store()
|
|
7182 |
app = login(get_app(pub))
|
|
7183 |
|
|
7184 |
FormDef.wipe()
|
|
7185 |
formdef = FormDef()
|
|
7186 |
formdef.backoffice_submission_roles = [x.id for x in Role.select() if x.name == 'foobar']
|
|
7187 |
formdef.name = 'form-only-allow-one'
|
|
7188 |
formdef.only_allow_one = True
|
|
7189 |
formdef.fields = [fields.StringField(id='0', label='foobar')]
|
|
7190 |
formdef.store()
|
|
7191 |
data_class = formdef.data_class()
|
|
7192 |
|
|
7193 |
# submit for a user
|
|
7194 |
resp = app.get(
|
|
7195 |
'/backoffice/submission/form-only-allow-one/?NameID=%s' % local_user.name_identifiers[0])
|
|
7196 |
# NameID query string: create a new draft with these parameters, and redirect to it
|
|
7197 |
assert 'backoffice/submission/form-only-allow-one/1/' in resp.location
|
|
7198 |
resp = resp.follow()
|
|
7199 |
assert '/backoffice/submission/form-only-allow-one/?mt=' in resp.location
|
|
7200 |
resp = resp.follow()
|
|
7201 |
resp.form['f0'] = 'some value'
|
|
7202 |
resp = resp.form.submit('submit') # -> validation page
|
|
7203 |
resp = resp.form.submit('submit') # -> final submit
|
|
7204 |
assert '/backoffice/submission/' in resp.location
|
|
7205 |
assert len([x for x in data_class.select() if not x.is_draft()]) == 1
|
|
7206 |
|
|
7207 |
# cant re-submit for same user
|
|
7208 |
app = login(get_app(pub))
|
|
7209 |
resp = app.get(
|
|
7210 |
'/backoffice/submission/form-only-allow-one/?NameID=%s' % local_user.name_identifiers[0])
|
|
7211 |
assert 'backoffice/submission/form-only-allow-one/2/' in resp.location
|
|
7212 |
resp = resp.follow()
|
|
7213 |
assert '/backoffice/submission/form-only-allow-one/?mt=' in resp.location
|
|
7214 |
resp = resp.follow()
|
|
7215 |
assert 'backoffice/submission/form-only-allow-one/1/' in resp.location
|
|
7216 |
resp = resp.follow()
|
|
7217 |
assert '/backoffice/submission/' in resp.location
|
|
7218 |
resp = resp.follow()
|
|
7219 |
assert resp.html.find('li', {'class': 'error'}).text == 'This form has already been submitted.'
|
|
7220 |
assert len([x for x in data_class.select() if not x.is_draft()]) == 1
|
7176 |
|
-
|