14 |
14 |
|
15 |
15 |
app.authorization = ('Basic', ('john.doe', 'password'))
|
16 |
16 |
|
17 |
|
params = {'user_external_id': 'xxx', 'date_start': '2021-09-01', 'date_end': '2021-10-01'}
|
|
17 |
params = {
|
|
18 |
'user_external_id': 'xxx',
|
|
19 |
'user_first_name': 'Foo',
|
|
20 |
'user_last_name': 'BAR',
|
|
21 |
'user_email': 'foo@bar.com',
|
|
22 |
'user_phone_number': '06',
|
|
23 |
'date_start': '2021-09-01',
|
|
24 |
'date_end': '2021-10-01',
|
|
25 |
'foo': 'bar',
|
|
26 |
}
|
18 |
27 |
resp = app.post('/api/agenda/%s/subscription/' % agenda.slug, params=params)
|
19 |
28 |
subscription = Subscription.objects.get(pk=resp.json['id'])
|
20 |
29 |
assert subscription.agenda == agenda
|
21 |
30 |
assert subscription.user_external_id == 'xxx'
|
|
31 |
assert subscription.user_first_name == 'Foo'
|
|
32 |
assert subscription.user_last_name == 'BAR'
|
|
33 |
assert subscription.user_email == 'foo@bar.com'
|
|
34 |
assert subscription.user_phone_number == '06'
|
|
35 |
assert subscription.extra_data == {'foo': 'bar'}
|
|
36 |
assert subscription.date_start == datetime.date(year=2021, month=9, day=1)
|
|
37 |
assert subscription.date_end == datetime.date(year=2021, month=10, day=1)
|
|
38 |
|
|
39 |
params = {
|
|
40 |
'user_external_id': 'xxx',
|
|
41 |
'user_first_name': 'Foo',
|
|
42 |
'user_last_name': 'BAR',
|
|
43 |
'date_start': '2021-09-01',
|
|
44 |
'date_end': '2021-10-01',
|
|
45 |
}
|
|
46 |
resp = app.post('/api/agenda/%s/subscription/' % agenda.slug, params=params)
|
|
47 |
subscription = Subscription.objects.get(pk=resp.json['id'])
|
|
48 |
assert subscription.agenda == agenda
|
|
49 |
assert subscription.user_external_id == 'xxx'
|
|
50 |
assert subscription.user_first_name == 'Foo'
|
|
51 |
assert subscription.user_last_name == 'BAR'
|
|
52 |
assert subscription.user_email == ''
|
|
53 |
assert subscription.user_phone_number == ''
|
|
54 |
assert subscription.extra_data == {}
|
22 |
55 |
assert subscription.date_start == datetime.date(year=2021, month=9, day=1)
|
23 |
56 |
assert subscription.date_end == datetime.date(year=2021, month=10, day=1)
|
24 |
57 |
|
25 |
58 |
# check errors
|
26 |
59 |
resp = app.post('/api/agenda/%s/subscription/' % agenda.slug, params={}, status=400)
|
27 |
60 |
assert resp.json['err_class'] == 'invalid payload'
|
28 |
|
for field in ('user_external_id', 'date_start', 'date_end'):
|
|
61 |
for field in ('user_external_id', 'user_first_name', 'user_last_name', 'date_start', 'date_end'):
|
29 |
62 |
assert 'required' in resp.json['errors'][field][0]
|
30 |
63 |
|
31 |
|
params = {'user_external_id': 'xxx', 'date_start': 'wrong-format', 'date_end': 'wrong-format'}
|
|
64 |
params = {
|
|
65 |
'user_external_id': 'xxx',
|
|
66 |
'user_first_name': 'Foo',
|
|
67 |
'user_last_name': 'BAR',
|
|
68 |
'date_start': 'wrong-format',
|
|
69 |
'date_end': 'wrong-format',
|
|
70 |
}
|
32 |
71 |
resp = app.post('/api/agenda/%s/subscription/' % agenda.slug, params=params, status=400)
|
33 |
72 |
assert resp.json['err_class'] == 'invalid payload'
|
34 |
73 |
assert 'wrong format' in resp.json['errors']['date_start'][0]
|
35 |
74 |
assert 'wrong format' in resp.json['errors']['date_end'][0]
|
36 |
75 |
|
37 |
|
params = {'user_external_id': 'xxx', 'date_start': '2021-10-01', 'date_end': '2021-09-01'}
|
|
76 |
params = {
|
|
77 |
'user_external_id': 'xxx',
|
|
78 |
'user_first_name': 'Foo',
|
|
79 |
'user_last_name': 'BAR',
|
|
80 |
'date_start': '2021-10-01',
|
|
81 |
'date_end': '2021-09-01',
|
|
82 |
}
|
38 |
83 |
resp = app.post('/api/agenda/%s/subscription/' % agenda.slug, params=params, status=400)
|
39 |
84 |
assert resp.json['errors']['non_field_errors'][0] == 'start_datetime must be before end_datetime'
|
40 |
|
-
|