0002-tests-fix-overly-confident-references-to-object-iden.patch
tests/test_dataviz.py | ||
---|---|---|
372 | 372 |
cell = ChartNgCell(page=page, order=1, placeholder='content') |
373 | 373 |
cell.data_reference = 'plop:example' |
374 | 374 |
cell.save() |
375 |
resp = app.get('/api/dataviz/graph/1/') # get data in cache |
|
375 |
location = '/api/dataviz/graph/%s/' % cell.id |
|
376 |
resp = app.get(location) # get data in cache |
|
376 | 377 |
resp = app.get('/') |
377 | 378 |
assert 'min-height: 250px' in resp.text |
378 |
assert '/api/dataviz/graph/1/' in resp.text
|
|
379 |
assert location in resp.text
|
|
379 | 380 | |
380 |
resp = app.get('/api/dataviz/graph/1/?width=400')
|
|
381 |
resp = app.get(location + '?width=400')
|
|
381 | 382 |
assert resp.content_type == 'image/svg+xml' |
382 | 383 | |
383 |
resp = app.get('/api/dataviz/graph/1/?width=') # no crash
|
|
384 |
resp = app.get(location + '?width=') # no crash
|
|
384 | 385 |
assert resp.content_type == 'image/svg+xml' |
385 | 386 | |
386 | 387 |
page.public = False |
387 | 388 |
page.save() |
388 |
resp = app.get('/api/dataviz/graph/1/?width=400', status=403)
|
|
389 |
resp = app.get(location + '?width=400', status=403)
|
|
389 | 390 | |
390 | 391 |
page.public = True |
391 | 392 |
page.save() |
... | ... | |
394 | 395 |
cell.public = False |
395 | 396 |
cell.groups.set([group]) |
396 | 397 |
cell.save() |
397 |
resp = app.get('/api/dataviz/graph/1/?width=400', status=403)
|
|
398 |
resp = app.get(location + '?width=400', status=403)
|
|
398 | 399 | |
399 | 400 |
app = login(app, username='normal-user', password='normal-user') |
400 |
resp = app.get('/api/dataviz/graph/1/?width=400', status=403)
|
|
401 |
resp = app.get(location + '?width=400', status=403)
|
|
401 | 402 | |
402 | 403 |
normal_user.groups.set([group]) |
403 | 404 |
normal_user.save() |
404 |
resp = app.get('/api/dataviz/graph/1/?width=400', status=200)
|
|
405 |
resp = app.get(location + '?width=400', status=200)
|
|
405 | 406 | |
406 | 407 |
# table visualization |
407 | 408 |
cell.chart_type = 'table' |
... | ... | |
412 | 413 |
# unsupported dataset |
413 | 414 |
cell.data_reference = 'plop:seventh' |
414 | 415 |
cell.save() |
415 |
resp = app.get('/api/dataviz/graph/1/') # get data in cache
|
|
416 |
resp = app.get(location) # get data in cache
|
|
416 | 417 |
resp = app.get('/') |
417 | 418 |
assert 'Unsupported dataset' in resp.text |
418 | 419 | |
419 | 420 |
cell.chart_type = 'bar' |
420 | 421 |
cell.save() |
421 |
resp = app.get('/api/dataviz/graph/1/?width=400', status=200)
|
|
422 |
resp = app.get(location + '?width=400', status=200)
|
|
422 | 423 |
assert 'Unsupported dataset' in resp.text |
423 | 424 | |
424 | 425 |
# durations |
425 | 426 |
cell.data_reference = 'plop:eighth' |
426 | 427 |
cell.chart_type = 'table' |
427 | 428 |
cell.save() |
428 |
resp = app.get('/api/dataviz/graph/1/') # get data in cache
|
|
429 |
resp = app.get(location) # get data in cache
|
|
429 | 430 |
resp = app.get('/') |
430 | 431 |
assert '<td>Less than an hour</td>' in resp.text |
431 | 432 |
assert '<td>1 day and 10 hours</td>' in resp.text |
... | ... | |
434 | 435 | |
435 | 436 |
cell.chart_type = 'bar' |
436 | 437 |
cell.save() |
437 |
resp = app.get('/api/dataviz/graph/1/?width=400', status=200)
|
|
438 |
resp = app.get(location + '?width=400', status=200)
|
|
438 | 439 |
assert '>Less than an hour<' in resp.text |
439 | 440 |
assert '>1 day and 10 hours<' in resp.text |
440 | 441 |
assert '>2 hours<' in resp.text |
... | ... | |
444 | 445 |
cell.data_reference = 'plop:tenth' |
445 | 446 |
cell.chart_type = 'table' |
446 | 447 |
cell.save() |
447 |
resp = app.get('/api/dataviz/graph/1/') # get data in cache
|
|
448 |
resp = app.get(location) # get data in cache
|
|
448 | 449 |
resp = app.get('/') |
449 | 450 |
assert '<td>10.0%</td>' in resp.text |
450 | 451 | |
451 | 452 |
cell.chart_type = 'bar' |
452 | 453 |
cell.save() |
453 |
resp = app.get('/api/dataviz/graph/1/?width=400', status=200)
|
|
454 |
resp = app.get(location + '?width=400', status=200)
|
|
454 | 455 |
assert '>10.0%<' in resp.text |
455 | 456 | |
456 | 457 |
# deleted visualization |
457 | 458 |
cell.data_reference = 'plop:eleventh' |
458 | 459 |
cell.save() |
459 |
resp = app.get('/api/dataviz/graph/1/')
|
|
460 |
resp = app.get(location)
|
|
460 | 461 |
assert 'not found' in resp.text |
461 | 462 | |
462 | 463 |
# cell with missing cached_json (probably after import and missing |
... | ... | |
511 | 512 |
cell.data_reference = 'plop:example' |
512 | 513 |
cell.chart_type = 'table' |
513 | 514 |
cell.save() |
514 |
resp = app.get('/api/dataviz/graph/1/') |
|
515 |
location = '/api/dataviz/graph/%s/' % cell.id |
|
516 |
resp = app.get(location) |
|
515 | 517 |
resp = app.get('/') |
516 | 518 |
assert resp.text.count('Total') == 1 |
517 | 519 | |
518 | 520 |
cell.data_reference = 'plop:second' |
519 | 521 |
cell.save() |
520 |
resp = app.get('/api/dataviz/graph/1/')
|
|
522 |
resp = app.get(location)
|
|
521 | 523 |
resp = app.get('/') |
522 | 524 |
assert resp.text.count('Total') == 1 |
523 | 525 | |
524 | 526 |
cell.data_reference = 'plop:third' |
525 | 527 |
cell.save() |
526 |
resp = app.get('/api/dataviz/graph/1/')
|
|
528 |
resp = app.get(location)
|
|
527 | 529 |
resp = app.get('/') |
528 | 530 |
assert '114' in resp.text |
529 | 531 |
assert resp.text.count('Total') == 2 |
530 | 532 | |
531 | 533 |
cell.data_reference = 'plop:fourth' |
532 | 534 |
cell.save() |
533 |
resp = app.get('/api/dataviz/graph/1/')
|
|
535 |
resp = app.get(location)
|
|
534 | 536 |
resp = app.get('/') |
535 | 537 |
assert resp.text.count('Total') == 0 |
536 | 538 | |
537 | 539 |
# total of durations is not computed |
538 | 540 |
cell.data_reference = 'plop:eigth' |
539 | 541 |
cell.save() |
540 |
resp = app.get('/api/dataviz/graph/1/')
|
|
542 |
resp = app.get(location)
|
|
541 | 543 |
resp = app.get('/') |
542 | 544 |
assert resp.text.count('Total') == 0 |
tests/test_manager.py | ||
---|---|---|
728 | 728 |
cells = CellBase.get_cells(page_id=page.id) |
729 | 729 |
assert len(cells) == 1 |
730 | 730 |
assert isinstance(cells[0], TextCell) |
731 |
assert resp.location.endswith('/manage/pages/1/#cell-%s' % cells[0].get_reference())
|
|
731 |
assert resp.location.endswith('/manage/pages/%s/#cell-%s' % (page.id, cells[0].get_reference()))
|
|
732 | 732 | |
733 | 733 |
resp = app.get('/manage/pages/%s/' % page.id) |
734 | 734 |
assert ('data-cell-reference="%s"' % cells[0].get_reference()) in resp.text |
735 | 735 |
resp.forms[0]['c%s-text' % cells[0].get_reference()].value = 'Hello world' |
736 | 736 |
resp = resp.forms[0].submit() |
737 | 737 |
assert resp.status_int == 302 |
738 |
assert resp.location.endswith('/manage/pages/1/#cell-%s' % cells[0].get_reference())
|
|
738 |
assert resp.location.endswith('/manage/pages/%s/#cell-%s' % (page.id, cells[0].get_reference()))
|
|
739 | 739 | |
740 | 740 |
resp = app.get('/manage/pages/%s/' % page.id) |
741 | 741 |
assert resp.forms[0]['c%s-text' % cells[0].get_reference()].value == 'Hello world' |
... | ... | |
1656 | 1656 |
# check with asynchronous cells |
1657 | 1657 |
resp = app.get('/manage/pages/%s/add-cell-to-content/data_jsoncell/default/' % page.id) |
1658 | 1658 |
resp = resp.follow() |
1659 |
resp.forms[3]['cdata_jsoncell-1-template_string'].value = 'A{{json.data.0.text}}B' |
|
1660 |
resp.forms[3]['cdata_jsoncell-1-url'].value = 'http://example.com' |
|
1659 |
cell_id = JsonCell.objects.last().id |
|
1660 |
resp.forms[3]['cdata_jsoncell-%s-template_string' % cell_id].value = 'A{{json.data.0.text}}B' |
|
1661 |
resp.forms[3]['cdata_jsoncell-%s-url' % cell_id].value = 'http://example.com' |
|
1661 | 1662 |
resp = resp.forms[3].submit().follow() |
1662 | 1663 |
assert PageSnapshot.objects.all().count() == 5 # add + change |
1663 | 1664 | |
1664 |
resp.forms[3]['cdata_jsoncell-1-template_string'].value = 'C{{json.data.0.text}}D'
|
|
1665 |
resp.forms[3]['cdata_jsoncell-%s-template_string' % cell_id].value = 'C{{json.data.0.text}}D'
|
|
1665 | 1666 |
resp = resp.forms[3].submit().follow() |
1666 | 1667 |
assert PageSnapshot.objects.all().count() == 6 |
1667 | 1668 | |
... | ... | |
1749 | 1750 |
# syntax error |
1750 | 1751 |
resp = app.get('/manage/pages/%s/add-cell-to-content/data_jsoncell/default/' % page.id) |
1751 | 1752 |
resp = resp.follow() |
1752 |
resp.forms[0]['cdata_jsoncell-1-template_string'].value = '{% syntax|error %}' |
|
1753 |
resp.forms[0]['cdata_jsoncell-1-url'].value = 'http://example.com' |
|
1753 |
cell_id = JsonCell.objects.last().id |
|
1754 |
resp.forms[0]['cdata_jsoncell-%s-template_string' % cell_id].value = '{% syntax|error %}' |
|
1755 |
resp.forms[0]['cdata_jsoncell-%s-url' % cell_id].value = 'http://example.com' |
|
1754 | 1756 |
resp = resp.forms[0].submit() |
1755 | 1757 |
assert 'syntax error: Invalid block tag' in resp.text |
1756 | 1758 |
assert JsonCell.objects.count() == 1 |
1757 | 1759 |
assert JsonCell.objects.first().template_string is None |
1758 | 1760 |
# valid syntax |
1759 | 1761 |
resp = app.get('/manage/pages/%s/' % page.id) |
1760 |
resp.forms[0]['cdata_jsoncell-1-template_string'].value = '{{ ok }}'
|
|
1761 |
resp.forms[0]['cdata_jsoncell-1-url'].value = 'http://example.com'
|
|
1762 |
resp.forms[0]['cdata_jsoncell-%s-template_string' % cell_id].value = '{{ ok }}'
|
|
1763 |
resp.forms[0]['cdata_jsoncell-%s-url' % cell_id].value = 'http://example.com'
|
|
1762 | 1764 |
resp = resp.forms[0].submit().follow() |
1763 | 1765 |
assert 'syntax error' not in resp.text |
1764 | 1766 |
assert JsonCell.objects.count() == 1 |
tests/test_maps_cells.py | ||
---|---|---|
146 | 146 |
assert 'data-max-zoom="19"' in rendered |
147 | 147 |
assert 'data-init-lat="48.83369263315934"' in rendered |
148 | 148 |
assert 'data-init-lng="2.3233688436448574"' in rendered |
149 |
assert '/ajax/mapcell/geojson/1/%s/' % layer.slug in rendered
|
|
149 |
assert '/ajax/mapcell/geojson/%s/%s/' % (cell.id, layer.slug) in rendered
|
|
150 | 150 |
assert 'data-group-markers="1"' not in rendered |
151 | 151 |
resp = app.get('/test_map_cell/') |
152 | 152 |
assert 'xstatic/leaflet.js' in resp.text |
tests/test_notification.py | ||
---|---|---|
146 | 146 | |
147 | 147 |
app = login_app(app, username='jane.doe', password='jane.doe') |
148 | 148 |
resp = app.get('/api/menu-badges/?page[]=%s' % page.id) |
149 |
assert resp.json == {'1': {'badge': '1'}}
|
|
149 |
assert resp.json == {'{}'.format(page.id): {'badge': '1'}}
|
|
150 | 150 | |
151 | 151 | |
152 | 152 |
def test_notification_ws(john_doe): |
153 | 153 | |
154 |
def notify(data, check_id, count):
|
|
154 |
def notify(data, count, check_id=None):
|
|
155 | 155 |
resp = client.post(reverse('api-notification-add'), json.dumps(data), |
156 | 156 |
content_type='application/json') |
157 | 157 |
assert resp.status_code == 200 |
158 | 158 |
result = json.loads(force_text(resp.content)) |
159 |
assert result == {'data': {'id': check_id}, 'err': 0} |
|
159 |
assert result['err'] == 0 |
|
160 |
if 'id' in data: |
|
161 |
assert check_id is not None and result['data']['id'] == check_id |
|
160 | 162 |
assert Notification.objects.filter(user=john_doe).count() == count |
161 |
return Notification.objects.find(john_doe, check_id).get()
|
|
163 |
return Notification.objects.filter(user=john_doe).order_by('id').last()
|
|
162 | 164 | |
163 | 165 |
login(john_doe) |
164 |
notify({'summary': 'foo'}, '1', 1)
|
|
165 |
notify({'summary': 'bar'}, '2', 2)
|
|
166 |
notify({'summary': 'bar', 'id': 'ns:noti3'}, 'ns:noti3', 3)
|
|
166 |
notify({'summary': 'foo'}, 1) |
|
167 |
notify({'summary': 'bar'}, 2) |
|
168 |
notify({'summary': 'bar', 'id': 'ns:noti3'}, 3, check_id='ns:noti3')
|
|
167 | 169 |
notif = { |
168 | 170 |
'summary': 'bar', |
169 | 171 |
'url': 'http://www.example.net', |
... | ... | |
172 | 174 |
'start_timestamp': '2016-11-11T11:11', |
173 | 175 |
'end_timestamp': '2016-12-12T12:12', |
174 | 176 |
} |
175 |
result = notify(notif, '4', 4)
|
|
177 |
result = notify(notif, 4) |
|
176 | 178 |
assert result.summary == notif['summary'] |
177 | 179 |
assert result.url == notif['url'] |
178 | 180 |
assert result.body == notif['body'] |
... | ... | |
182 | 184 | |
183 | 185 |
del notif['end_timestamp'] |
184 | 186 |
notif['duration'] = 3600 |
185 |
result = notify(notif, '5', 5)
|
|
187 |
result = notify(notif, 5) |
|
186 | 188 |
assert result.end_timestamp.isoformat()[:19] == '2016-11-11T12:11:00' |
187 | 189 | |
188 | 190 |
notif['duration'] = '3600' |
189 |
result = notify(notif, '6', 6)
|
|
191 |
result = notify(notif, 6) |
|
190 | 192 |
assert result.end_timestamp.isoformat()[:19] == '2016-11-11T12:11:00' |
191 | 193 | |
192 |
resp = client.get(reverse('api-notification-ack', kwargs={'notification_id': '6'})) |
|
194 |
notif_id = Notification.objects.order_by('id').last().id |
|
195 |
resp = client.get(reverse('api-notification-ack', kwargs={'notification_id': '%s' % notif_id})) |
|
193 | 196 |
assert resp.status_code == 200 |
194 | 197 |
assert Notification.objects.filter(acked=True).count() == 1 |
195 |
assert Notification.objects.filter(acked=True).get().public_id == '6'
|
|
198 |
assert Notification.objects.filter(acked=True).get().public_id == '%s' % notif_id
|
|
196 | 199 | |
197 |
resp = client.get(reverse('api-notification-forget', kwargs={'notification_id': '5'}))
|
|
200 |
resp = client.get(reverse('api-notification-forget', kwargs={'notification_id': '%s' % (notif_id - 1)}))
|
|
198 | 201 |
assert resp.status_code == 200 |
199 | 202 |
assert Notification.objects.filter(acked=True).count() == 2 |
200 |
notif = Notification.objects.find(john_doe, '5').get()
|
|
201 |
assert notif.public_id == '5'
|
|
203 |
notif = Notification.objects.find(john_doe, '%s' % (notif_id - 1)).get()
|
|
204 |
assert notif.public_id == '%s' % (notif_id - 1)
|
|
202 | 205 |
assert notif.acked is True |
203 | 206 |
assert notif.end_timestamp < now() |
204 | 207 | |
... | ... | |
206 | 209 |
assert resp.status_code == 200 |
207 | 210 |
assert json.loads(force_text(resp.content))['new'] == 3 |
208 | 211 |
assert json.loads(force_text(resp.content))['total'] == 3 |
209 |
resp = client.get(reverse('api-notification-ack', kwargs={'notification_id': '1'}))
|
|
212 |
resp = client.get(reverse('api-notification-ack', kwargs={'notification_id': '%s' % (notif_id - 5)}))
|
|
210 | 213 |
resp = client.get(reverse('api-notification-count')) |
211 | 214 |
assert resp.status_code == 200 |
212 | 215 |
assert json.loads(force_text(resp.content))['new'] == 2 |
213 | 216 |
assert json.loads(force_text(resp.content))['total'] == 3 |
214 |
resp = client.get(reverse('api-notification-forget', kwargs={'notification_id': '1'}))
|
|
217 |
resp = client.get(reverse('api-notification-forget', kwargs={'notification_id': '%s' % (notif_id - 5)}))
|
|
215 | 218 |
resp = client.get(reverse('api-notification-count')) |
216 | 219 |
assert resp.status_code == 200 |
217 | 220 |
assert json.loads(force_text(resp.content))['new'] == 2 |
218 |
- |