2332 |
2332 |
assert '2012-02-12' in resp.text
|
2333 |
2333 |
|
2334 |
2334 |
|
2335 |
|
def test_form_draft_from_prefill(pub):
|
|
2335 |
@pytest.mark.parametrize('field_type', ['string', 'item'])
|
|
2336 |
@pytest.mark.parametrize('logged_in', ['anonymous', 'logged-in'])
|
|
2337 |
def test_form_draft_from_prefill(pub, field_type, logged_in):
|
|
2338 |
create_user(pub)
|
|
2339 |
|
2336 |
2340 |
formdef = create_formdef()
|
2337 |
|
formdef.fields = [
|
2338 |
|
fields.StringField(id='0', label='string'),
|
2339 |
|
]
|
|
2341 |
if field_type == 'string':
|
|
2342 |
formdef.fields = [fields.StringField(id='0', label='string')]
|
|
2343 |
else:
|
|
2344 |
formdef.fields = [fields.ItemField(id='0', label='item', type='item', items=['foo', 'bar', 'hello'])]
|
2340 |
2345 |
formdef.enable_tracking_codes = True
|
2341 |
2346 |
formdef.store()
|
2342 |
2347 |
formdef.data_class().wipe()
|
2343 |
2348 |
|
|
2349 |
app = get_app(pub)
|
|
2350 |
if logged_in == 'logged-in':
|
|
2351 |
login(app, username='foo', password='foo')
|
|
2352 |
|
2344 |
2353 |
# no draft
|
2345 |
|
get_app(pub).get('/test/')
|
|
2354 |
app.get('/test/')
|
2346 |
2355 |
assert formdef.data_class().count() == 0
|
2347 |
2356 |
formdef.data_class().wipe()
|
2348 |
2357 |
|
2349 |
2358 |
# draft created if there's been some prefilled fields
|
2350 |
2359 |
formdef.fields[0].prefill = {'type': 'string', 'value': '{{request.GET.test|default:""}}'}
|
2351 |
2360 |
formdef.store()
|
2352 |
|
get_app(pub).get('/test/?test=hello')
|
|
2361 |
app.get('/test/?test=hello')
|
2353 |
2362 |
assert formdef.data_class().count() == 1
|
2354 |
2363 |
formdef.data_class().wipe()
|
2355 |
2364 |
|
2356 |
2365 |
# unless the call was made from an application
|
2357 |
|
get_app(pub).get('/test/?test=hello', headers={'User-agent': 'python-requests/0'})
|
|
2366 |
app.get('/test/?test=hello', headers={'User-agent': 'python-requests/0'})
|
2358 |
2367 |
assert formdef.data_class().count() == 0
|
2359 |
2368 |
|
2360 |
2369 |
# or a bot
|
2361 |
|
get_app(pub).get('/test/?test=hello', headers={'User-agent': 'Googlebot'})
|
|
2370 |
app.get('/test/?test=hello', headers={'User-agent': 'Googlebot'})
|
2362 |
2371 |
assert formdef.data_class().count() == 0
|
2363 |
2372 |
|
|
2373 |
# check there's no leftover draft after submission
|
|
2374 |
for with_tracking_code in (False, True):
|
|
2375 |
formdef.enable_tracking_codes = with_tracking_code
|
|
2376 |
formdef.store()
|
|
2377 |
formdef.data_class().wipe()
|
|
2378 |
resp = app.get('/test/?test=hello')
|
|
2379 |
resp = resp.form.submit('submit') # -> validation
|
|
2380 |
resp = resp.form.submit('submit') # -> submit
|
|
2381 |
assert formdef.data_class().count() == 1
|
|
2382 |
|
2364 |
2383 |
|
2365 |
2384 |
@pytest.mark.parametrize('tracking_code', [True, False])
|
2366 |
2385 |
def test_form_direct_draft_access(pub, tracking_code):
|