Projet

Général

Profil

0001-backoffice-keep-displaying-tracking-code-to-agent-fo.patch

Frédéric Péters, 14 mai 2017 20:20

Télécharger (3,71 ko)

Voir les différences:

Subject: [PATCH] backoffice: keep displaying tracking code to agent for 30
 minutes (#14898)

 tests/test_backoffice_pages.py | 52 ++++++++++++++++++++++++++++++++++++++++++
 wcs/backoffice/management.py   |  9 ++++++++
 2 files changed, 61 insertions(+)
tests/test_backoffice_pages.py
1293 1293
    resp = resp.form.submit('cancel')
1294 1294
    assert resp.location == 'http://example.net/backoffice/submission/'
1295 1295

  
1296
def test_backoffice_submission_with_tracking_code(pub):
1297
    user = create_user(pub)
1298
    create_environment(pub)
1299

  
1300
    formdef = FormDef.get_by_urlname('form-title')
1301
    formdef.backoffice_submission_roles = user.roles[:]
1302
    formdef.enable_tracking_codes = True
1303
    formdef.store()
1304

  
1305
    app = login(get_app(pub))
1306
    resp = app.get('/backoffice/submission/')
1307

  
1308
    resp = resp.click(formdef.name)
1309
    resp.form['f1'] = 'test submission'
1310
    resp.form['f2'] = 'baz'
1311
    resp.form['f3'] = 'C'
1312
    resp = resp.form.submit('submit')
1313
    assert 'Check values then click submit.' in resp.body
1314
    # final submit
1315
    validation_resp_body = resp.body
1316
    resp = resp.form.submit('submit')
1317

  
1318
    formdata_no = resp.location.split('/')[-2]
1319
    data_class = formdef.data_class()
1320
    formdata = data_class.get(formdata_no)
1321
    assert formdata.tracking_code in validation_resp_body
1322

  
1323
    formdata_location = resp.location
1324
    resp = resp.follow() # get to the formdata page
1325
    # check tracking code is still displayed in formdata page
1326
    assert 'test submission' in resp.body
1327
    assert formdata.tracking_code in resp.body
1328

  
1329
    # check access by different user
1330
    formdata.submission_context = {'agent_id': '10000'}
1331
    formdata.store()
1332
    resp = app.get(formdata_location)
1333
    assert 'test submission' in resp.body
1334
    assert not formdata.tracking_code in resp.body
1335

  
1336
    # restore user
1337
    formdata.submission_context = {'agent_id': user.id}
1338
    formdata.store()
1339
    resp = app.get(formdata_location)
1340
    assert formdata.tracking_code in resp.body
1341

  
1342
    # check access at a later time
1343
    formdata.receipt_time = time.localtime(time.time() - 3600)
1344
    formdata.store()
1345
    resp = app.get(formdata_location)
1346
    assert not formdata.tracking_code in resp.body
1347

  
1296 1348
def test_backoffice_submission_welco(pub, welco_url):
1297 1349
    user = create_user(pub)
1298 1350
    create_environment(pub)
wcs/backoffice/management.py
1878 1878

  
1879 1879
        if not formdata.is_draft():
1880 1880
            r += htmltext('<div class="extra-context">')
1881
            if (formdata.backoffice_submission and formdata.submission_context and
1882
                    formdata.submission_context.get('agent_id') == get_request().user.id and
1883
                    formdata.tracking_code and
1884
                    time.time() - time.mktime(formdata.receipt_time) < 30*60):
1885
                # keep displaying tracking code to submission agent for 30
1886
                # minutes after submission
1887
                r += htmltext('<h3>%s</h3>') % _('Tracking Code')
1888
                r += htmltext('<p>%s</p>') % formdata.tracking_code
1889

  
1881 1890
            r += htmltext('<h3>%s</h3>') % _('General Information')
1882 1891
            r += htmltext('<p>')
1883 1892
            tm = misc.localstrftime(formdata.receipt_time)
1884
-