0002-make-tests-insensible-to-postgres-sqlite-39583.patch
chrono/manager/views.py | ||
---|---|---|
958 | 958 | |
959 | 959 |
def get_success_url(self): |
960 | 960 |
referer = self.request.META.get('HTTP_REFERER') |
961 |
success_url = reverse('chrono-manager-time-period-exception-list', kwargs={'pk': self.desk.agenda_id})
|
|
961 |
success_url = reverse('chrono-manager-time-period-exception-list', kwargs={'pk': self.desk.pk})
|
|
962 | 962 |
if success_url in referer: |
963 | 963 |
return success_url |
964 | 964 |
tests/test_api.py | ||
---|---|---|
65 | 65 |
event = Event(start_datetime=first_date + datetime.timedelta(days=i), places=20, agenda=agenda) |
66 | 66 |
event.save() |
67 | 67 | |
68 |
agenda2 = Agenda(label=u'Foo bar2') |
|
68 |
agenda2 = Agenda(label=u'Foo bar 2')
|
|
69 | 69 |
agenda2.save() |
70 | 70 |
first_date = localtime(now()).replace(hour=20, minute=0, second=0, microsecond=0) |
71 | 71 |
first_date += datetime.timedelta(days=1) |
... | ... | |
111 | 111 | |
112 | 112 |
def test_agendas_api(app, some_data, meetings_agenda): |
113 | 113 |
agenda1 = Agenda.objects.filter(label=u'Foo bar')[0] |
114 |
agenda2 = Agenda.objects.filter(label=u'Foo bar2')[0] |
|
114 |
agenda2 = Agenda.objects.filter(label=u'Foo bar 2')[0]
|
|
115 | 115 |
resp = app.get('/api/agenda/') |
116 | 116 |
assert resp.json == { |
117 | 117 |
'data': [ |
... | ... | |
127 | 127 |
'fillslots_url': 'http://testserver/api/agenda/%s/fillslots/' % agenda1.slug, |
128 | 128 |
}, |
129 | 129 |
}, |
130 |
{ |
|
131 |
'text': 'Foo bar 2', |
|
132 |
'id': u'foo-bar-2', |
|
133 |
'kind': 'events', |
|
134 |
'slug': 'foo-bar-2', |
|
135 |
'minimal_booking_delay': 1, |
|
136 |
'maximal_booking_delay': 56, |
|
137 |
'api': { |
|
138 |
'datetimes_url': 'http://testserver/api/agenda/%s/datetimes/' % agenda2.slug, |
|
139 |
'fillslots_url': 'http://testserver/api/agenda/%s/fillslots/' % agenda2.slug, |
|
140 |
}, |
|
141 |
}, |
|
130 | 142 |
{ |
131 | 143 |
'text': 'Foo bar Meeting', |
132 | 144 |
'id': u'foo-bar-meeting', |
... | ... | |
140 | 152 |
'fillslots_url': 'http://testserver/api/agenda/%s/fillslots/' % meetings_agenda.slug, |
141 | 153 |
}, |
142 | 154 |
}, |
143 |
{ |
|
144 |
'text': 'Foo bar2', |
|
145 |
'id': u'foo-bar2', |
|
146 |
'kind': 'events', |
|
147 |
'slug': 'foo-bar2', |
|
148 |
'minimal_booking_delay': 1, |
|
149 |
'maximal_booking_delay': 56, |
|
150 |
'api': { |
|
151 |
'datetimes_url': 'http://testserver/api/agenda/%s/datetimes/' % agenda2.slug, |
|
152 |
'fillslots_url': 'http://testserver/api/agenda/%s/fillslots/' % agenda2.slug, |
|
153 |
}, |
|
154 |
}, |
|
155 | 155 |
] |
156 | 156 |
} |
157 | 157 | |
... | ... | |
257 | 257 | |
258 | 258 | |
259 | 259 |
def test_datetime_api_label(app, some_data): |
260 |
agenda_id = Agenda.objects.filter(label=u'Foo bar2')[0].id |
|
260 |
agenda_id = Agenda.objects.filter(label=u'Foo bar 2')[0].id
|
|
261 | 261 |
event = Event.objects.filter(agenda=agenda_id)[0] |
262 | 262 |
event.label = 'Hello world' |
263 | 263 |
event.save() |
... | ... | |
266 | 266 | |
267 | 267 | |
268 | 268 |
def test_datetime_api_status_url(app, some_data): |
269 |
agenda = Agenda.objects.get(label=u'Foo bar2') |
|
269 |
agenda = Agenda.objects.get(label=u'Foo bar 2')
|
|
270 | 270 |
resp = app.get('/api/agenda/%s/datetimes/' % agenda.slug) |
271 | 271 |
for datum in resp.json['data']: |
272 | 272 |
assert urlparse.urlparse(datum['api']['status_url']).path == '/api/agenda/%s/status/%s/' % ( |
... | ... | |
468 | 468 | |
469 | 469 |
resp = app.post('/api/agenda/foobar/fillslot/%s/' % event.id, status=404) |
470 | 470 | |
471 |
resp = app.post('/api/agenda/233/fillslot/%s/' % event.id, status=404)
|
|
471 |
resp = app.post('/api/agenda/0/fillslot/%s/' % event.id, status=404)
|
|
472 | 472 | |
473 | 473 | |
474 | 474 |
def test_booking_ics(app, some_data, meetings_agenda, user): |
... | ... | |
614 | 614 |
assert urlparse.urlparse(resp.json['api']['cancel_url']).netloc |
615 | 615 |
assert Booking.objects.count() == 3 |
616 | 616 |
# these 3 bookings are related, the first is the primary one |
617 |
bookings = Booking.objects.all().order_by('primary_booking')
|
|
617 |
bookings = Booking.objects.all().order_by('pk')
|
|
618 | 618 |
assert bookings[0].primary_booking is None |
619 | 619 |
assert bookings[1].primary_booking.id == bookings[0].id == primary_booking_id |
620 | 620 |
assert bookings[2].primary_booking.id == bookings[0].id == primary_booking_id |
... | ... | |
698 | 698 | |
699 | 699 |
# unknown agendas |
700 | 700 |
resp = app.post('/api/agenda/foobar/fillslots/', status=404) |
701 |
resp = app.post('/api/agenda/233/fillslots/', status=404)
|
|
701 |
resp = app.post('/api/agenda/0/fillslots/', status=404)
|
|
702 | 702 | |
703 | 703 | |
704 | 704 |
def test_booking_api_fillslots_slots_string_param(app, some_data, user): |
... | ... | |
1144 | 1144 |
assert Booking.objects.filter(cancellation_datetime__isnull=False).count() == 1 |
1145 | 1145 | |
1146 | 1146 |
# cancel an object that doesn't exist |
1147 |
resp = app.post('/api/booking/%s/cancel/' % 9999, status=404)
|
|
1147 |
resp = app.post('/api/booking/%s/cancel/' % 0, status=404)
|
|
1148 | 1148 | |
1149 | 1149 |
# cancel an event that was already cancelled |
1150 | 1150 |
resp = app.post('/api/booking/%s/cancel/' % booking_id, status=200) |
... | ... | |
1208 | 1208 |
resp = app.get('/api/agenda/%s/status/%s/' % (agenda_id, event.id), status=401) |
1209 | 1209 | |
1210 | 1210 |
app.authorization = ('Basic', ('john.doe', 'password')) |
1211 |
resp = app.get('/api/agenda/%s/status/%s/' % (agenda_id, 9999), status=404)
|
|
1211 |
resp = app.get('/api/agenda/%s/status/%s/' % (agenda_id, 0), status=404)
|
|
1212 | 1212 |
resp = app.get('/api/agenda/%s/status/%s/' % (agenda_id, 'xx'), status=404) |
1213 | 1213 | |
1214 | 1214 |
resp = app.get('/api/agenda/%s/status/%s/' % (agenda_id, event.id)) |
... | ... | |
1324 | 1324 |
assert Booking.objects.filter(in_waiting_list=False).count() == 1 |
1325 | 1325 | |
1326 | 1326 |
# accept a booking that doesn't exist |
1327 |
resp = app.post('/api/booking/%s/accept/' % 9999, status=404)
|
|
1327 |
resp = app.post('/api/booking/%s/accept/' % 0, status=404)
|
|
1328 | 1328 | |
1329 | 1329 |
# accept a booking that was not in the waiting list |
1330 | 1330 |
resp = app.post('/api/booking/%s/accept/' % booking.id, status=200) |
... | ... | |
1636 | 1636 | |
1637 | 1637 |
def test_agenda_api_date_range(app, some_data): |
1638 | 1638 |
# test range limitation |
1639 |
agenda2 = Agenda.objects.get(slug='foo-bar2') |
|
1639 |
agenda2 = Agenda.objects.get(slug='foo-bar-2')
|
|
1640 | 1640 |
base_date = agenda2.event_set.last().start_datetime.date() |
1641 | 1641 |
base_date = base_date + datetime.timedelta(days=1) |
1642 | 1642 |
tests/test_data_migrations.py | ||
---|---|---|
1 |
import datetime |
|
2 |
import pytest |
|
3 | ||
4 |
import django |
|
5 |
from django.db import connection |
|
6 |
from django.db.migrations.executor import MigrationExecutor |
|
7 |
from django.utils.timezone import make_aware |
|
8 | ||
9 |
from chrono.agendas.models import MeetingType |
|
10 | ||
11 |
pytestmark = pytest.mark.django_db |
|
12 | ||
13 | ||
14 |
def test_meeting_type_slug_migration(): |
|
15 |
if connection.vendor == 'sqlite' and django.VERSION > (1, 11, 0): |
|
16 |
pytest.skip('SQLite schema editor cannot be used while foreign key constraint checks are enabled.') |
|
17 |
return |
|
18 |
executor = MigrationExecutor(connection) |
|
19 |
migrate_from = [('agendas', '0011_meetingtype_slug')] |
|
20 |
migrate_to = [('agendas', '0013_auto_20161028_1603')] |
|
21 |
executor.migrate(migrate_from) |
|
22 |
executor.loader.build_graph() |
|
23 | ||
24 |
old_apps = executor.loader.project_state(migrate_from).apps |
|
25 |
OldAgenda = old_apps.get_model('agendas', 'Agenda') |
|
26 |
OldMeetingType = old_apps.get_model('agendas', 'MeetingType') |
|
27 | ||
28 |
agenda = OldAgenda(label=u'Foo bar') |
|
29 |
agenda.save() |
|
30 | ||
31 |
meeting_type = OldMeetingType(agenda=agenda, label=u'Baz') |
|
32 |
meeting_type.save() |
|
33 | ||
34 |
executor.migrate(migrate_to) |
|
35 | ||
36 |
assert MeetingType.objects.get(id=meeting_type.id).slug == 'baz' |
|
37 | ||
38 | ||
39 |
def test_timeperiod_data_migrations(): |
|
40 |
if connection.vendor == 'sqlite' and django.VERSION > (1, 11, 0): |
|
41 |
pytest.skip('SQLite schema editor cannot be used while foreign key constraint checks are enabled.') |
|
42 |
return |
|
43 |
executor = MigrationExecutor(connection) |
|
44 |
app = 'agendas' |
|
45 |
migrate_from = [(app, '0016_desk')] |
|
46 |
migrate_to = [(app, '0018_event_desk')] |
|
47 |
executor.migrate(migrate_from) |
|
48 |
old_apps = executor.loader.project_state(migrate_from).apps |
|
49 |
Agenda = old_apps.get_model(app, 'Agenda') |
|
50 |
MeetingType = old_apps.get_model(app, 'MeetingType') |
|
51 |
TimePeriod = old_apps.get_model(app, 'TimePeriod') |
|
52 |
Event = old_apps.get_model(app, 'Event') |
|
53 |
agenda = Agenda.objects.create(label='foo', slug='foo', kind='meetings') |
|
54 |
agenda2 = Agenda.objects.create(label='bar', slug='bar', kind='events') |
|
55 |
TimePeriod.objects.create( |
|
56 |
agenda=agenda, weekday=1, start_time=datetime.time(8, 0), end_time=datetime.time(12, 0) |
|
57 |
) |
|
58 |
TimePeriod.objects.create( |
|
59 |
agenda=agenda, weekday=2, start_time=datetime.time(8, 0), end_time=datetime.time(10, 0) |
|
60 |
) |
|
61 |
TimePeriod.objects.create( |
|
62 |
agenda=agenda, weekday=3, start_time=datetime.time(9, 0), end_time=datetime.time(12, 0) |
|
63 |
) |
|
64 |
meeting_type = MeetingType.objects.create(agenda=agenda, label='foo', slug='foo', duration=60) |
|
65 |
Event.objects.create( |
|
66 |
agenda=agenda, |
|
67 |
places=1, |
|
68 |
meeting_type=meeting_type, |
|
69 |
start_datetime=make_aware(datetime.datetime(2017, 5, 22, 9, 30)), |
|
70 |
) |
|
71 |
Event.objects.create( |
|
72 |
agenda=agenda, |
|
73 |
places=1, |
|
74 |
meeting_type=meeting_type, |
|
75 |
start_datetime=make_aware(datetime.datetime(2017, 5, 22, 10, 0)), |
|
76 |
) |
|
77 |
Event.objects.create( |
|
78 |
agenda=agenda2, places=5, start_datetime=make_aware(datetime.datetime(2017, 5, 22, 10, 0)) |
|
79 |
) |
|
80 |
executor.loader.build_graph() |
|
81 |
executor.migrate(migrate_to) |
|
82 |
new_apps = executor.loader.project_state(migrate_to).apps |
|
83 |
Agenda = new_apps.get_model(app, 'Agenda') |
|
84 |
agenda = Agenda.objects.get(slug='foo') |
|
85 |
TimePeriod = new_apps.get_model(app, 'TimePeriod') |
|
86 |
for time_period in TimePeriod.objects.all(): |
|
87 |
assert time_period.desk.label == 'Guichet 1' |
|
88 |
assert time_period.desk.slug == 'guichet-1' |
|
89 | ||
90 |
Event = new_apps.get_model(app, 'Event') |
|
91 |
for event in Event.objects.filter(agenda=agenda): |
|
92 |
assert event.desk.label == 'Guichet 1' |
|
93 |
assert event.desk.slug == 'guichet-1' |
tests/test_import_export.py | ||
---|---|---|
91 | 91 | |
92 | 92 |
event = Event(agenda=agenda1, start_datetime=make_aware(datetime.datetime.now()), places=10) |
93 | 93 |
event.save() |
94 |
desk, _ = Desk.objects.get_or_create(agenda=agenda2, label='Desk A', slug='desk-a') |
|
94 | 95 |
timeperiod = TimePeriod( |
95 | 96 |
weekday=2, desk=desk, start_time=datetime.time(10, 0), end_time=datetime.time(11, 0) |
96 | 97 |
) |
97 |
- |