1 |
1 |
# -*- coding: utf-8 -*-
|
2 |
2 |
|
3 |
3 |
from __future__ import unicode_literals
|
|
4 |
import copy
|
4 |
5 |
import json
|
5 |
6 |
|
6 |
7 |
from django.contrib.auth.models import User, Group
|
... | ... | |
1546 |
1547 |
resp = app.get('/manage/agendas/%s/settings' % agenda.id)
|
1547 |
1548 |
resp = resp.click('Export')
|
1548 |
1549 |
assert resp.headers['content-type'] == 'application/json'
|
1549 |
|
agenda_export = resp.body
|
|
1550 |
agenda_export = resp.text
|
1550 |
1551 |
|
1551 |
1552 |
# invalid json
|
1552 |
1553 |
resp = app.get('/manage/', status=200)
|
... | ... | |
1565 |
1566 |
# existing agenda
|
1566 |
1567 |
resp = app.get('/manage/', status=200)
|
1567 |
1568 |
resp = resp.click('Import')
|
1568 |
|
resp.form['agendas_json'] = Upload('export.json', agenda_export, 'application/json')
|
|
1569 |
resp.form['agendas_json'] = Upload('export.json', agenda_export.encode('utf-8'), 'application/json')
|
1569 |
1570 |
resp = resp.form.submit().follow()
|
1570 |
1571 |
assert 'No agenda created. An agenda has been updated.' in resp.text
|
1571 |
1572 |
assert Agenda.objects.count() == 1
|
... | ... | |
1574 |
1575 |
Agenda.objects.all().delete()
|
1575 |
1576 |
resp = app.get('/manage/', status=200)
|
1576 |
1577 |
resp = resp.click('Import')
|
1577 |
|
resp.form['agendas_json'] = Upload('export.json', agenda_export, 'application/json')
|
|
1578 |
resp.form['agendas_json'] = Upload('export.json', agenda_export.encode('utf-8'), 'application/json')
|
1578 |
1579 |
resp = resp.form.submit().follow()
|
1579 |
1580 |
assert 'An agenda has been created. No agenda updated.' in resp.text
|
1580 |
1581 |
assert Agenda.objects.count() == 1
|
1581 |
1582 |
|
|
1583 |
# multiple agendas
|
|
1584 |
agendas = json.loads(agenda_export)
|
|
1585 |
agendas['agendas'].append(copy.copy(agendas['agendas'][0]))
|
|
1586 |
agendas['agendas'].append(copy.copy(agendas['agendas'][0]))
|
|
1587 |
agendas['agendas'][1]['label'] = 'Foo bar 2'
|
|
1588 |
agendas['agendas'][1]['slug'] = 'foo-bar-2'
|
|
1589 |
agendas['agendas'][2]['label'] = 'Foo bar 3'
|
|
1590 |
agendas['agendas'][2]['slug'] = 'foo-bar-3'
|
|
1591 |
|
|
1592 |
resp = app.get('/manage/', status=200)
|
|
1593 |
resp = resp.click('Import')
|
|
1594 |
resp.form['agendas_json'] = Upload('export.json', json.dumps(agendas).encode('utf-8'), 'application/json')
|
|
1595 |
resp = resp.form.submit().follow()
|
|
1596 |
assert '2 agendas have been created. An agenda has been updated.' in resp.text
|
|
1597 |
assert Agenda.objects.count() == 3
|
|
1598 |
|
|
1599 |
Agenda.objects.all().delete()
|
|
1600 |
resp = app.get('/manage/', status=200)
|
|
1601 |
resp = resp.click('Import')
|
|
1602 |
resp.form['agendas_json'] = Upload('export.json', json.dumps(agendas).encode('utf-8'), 'application/json')
|
|
1603 |
resp = resp.form.submit().follow()
|
|
1604 |
assert '3 agendas have been created. No agenda updated.' in resp.text
|
|
1605 |
assert Agenda.objects.count() == 3
|
|
1606 |
|
1582 |
1607 |
# reference to unknown group
|
1583 |
1608 |
agenda_export_dict = json.loads(force_text(agenda_export))
|
1584 |
1609 |
agenda_export_dict['agendas'][0]['permissions']['view'] = u'gé1'
|
1585 |
|
-
|