7 |
7 |
pytestmark = pytest.mark.django_db
|
8 |
8 |
|
9 |
9 |
|
|
10 |
def test_api_list_subscription(app, user):
|
|
11 |
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
|
12 |
subscription = Subscription.objects.create(
|
|
13 |
agenda=agenda,
|
|
14 |
user_external_id='xxx',
|
|
15 |
user_first_name='Foo',
|
|
16 |
user_last_name='BAR',
|
|
17 |
user_email='foo@bar.com',
|
|
18 |
user_phone_number='06',
|
|
19 |
extra_data={'foo': 'bar'},
|
|
20 |
date_start=datetime.date(year=2021, month=9, day=1),
|
|
21 |
date_end=datetime.date(year=2021, month=10, day=1),
|
|
22 |
)
|
|
23 |
|
|
24 |
resp = app.get('/api/agenda/%s/subscription/' % agenda.slug, status=401)
|
|
25 |
|
|
26 |
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
27 |
|
|
28 |
resp = app.get('/api/agenda/%s/subscription/' % agenda.slug)
|
|
29 |
assert len(resp.json['data']) == 1
|
|
30 |
assert resp.json['data'][0] == {
|
|
31 |
'id': subscription.pk,
|
|
32 |
'user_external_id': 'xxx',
|
|
33 |
'user_first_name': 'Foo',
|
|
34 |
'user_last_name': 'BAR',
|
|
35 |
'user_email': 'foo@bar.com',
|
|
36 |
'user_phone_number': '06',
|
|
37 |
'date_start': '2021-09-01',
|
|
38 |
'date_end': '2021-10-01',
|
|
39 |
'foo': 'bar',
|
|
40 |
}
|
|
41 |
|
|
42 |
|
|
43 |
def test_api_list_subscription_filter_user_external_id(app, user):
|
|
44 |
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
|
45 |
subscription1 = Subscription.objects.create(
|
|
46 |
agenda=agenda,
|
|
47 |
user_external_id='xxx',
|
|
48 |
user_first_name='Foo',
|
|
49 |
user_last_name='BAR',
|
|
50 |
user_email='foo@bar.com',
|
|
51 |
user_phone_number='06',
|
|
52 |
extra_data={'foo': 'bar'},
|
|
53 |
date_start=datetime.date(year=2021, month=9, day=1),
|
|
54 |
date_end=datetime.date(year=2021, month=10, day=1),
|
|
55 |
)
|
|
56 |
subscription2 = Subscription.objects.create(
|
|
57 |
agenda=agenda,
|
|
58 |
user_external_id='yyy',
|
|
59 |
date_start=datetime.date(year=2021, month=9, day=1),
|
|
60 |
date_end=datetime.date(year=2021, month=10, day=1),
|
|
61 |
)
|
|
62 |
other_agenda = Agenda.objects.create(label='Foo bar 2', kind='events')
|
|
63 |
Subscription.objects.create(
|
|
64 |
agenda=other_agenda,
|
|
65 |
user_external_id='xxx',
|
|
66 |
date_start=datetime.date(year=2000, month=1, day=1),
|
|
67 |
date_end=datetime.date(year=2099, month=12, day=31),
|
|
68 |
)
|
|
69 |
|
|
70 |
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
71 |
|
|
72 |
resp = app.get('/api/agenda/%s/subscription/' % agenda.slug, params={'user_external_id': 'xxx'})
|
|
73 |
assert [d['id'] for d in resp.json['data']] == [subscription1.pk]
|
|
74 |
resp = app.get('/api/agenda/%s/subscription/' % agenda.slug, params={'user_external_id': 'yyy'})
|
|
75 |
assert [d['id'] for d in resp.json['data']] == [subscription2.pk]
|
|
76 |
resp = app.get('/api/agenda/%s/subscription/' % agenda.slug, params={'user_external_id': 'zzz'})
|
|
77 |
assert [d['id'] for d in resp.json['data']] == []
|
|
78 |
|
|
79 |
|
|
80 |
def test_api_list_subscription_filter_date_start(app, user):
|
|
81 |
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
|
82 |
subscription1 = Subscription.objects.create(
|
|
83 |
agenda=agenda,
|
|
84 |
user_external_id='xxx',
|
|
85 |
user_first_name='Foo',
|
|
86 |
user_last_name='BAR',
|
|
87 |
user_email='foo@bar.com',
|
|
88 |
user_phone_number='06',
|
|
89 |
extra_data={'foo': 'bar'},
|
|
90 |
date_start=datetime.date(year=2021, month=9, day=1),
|
|
91 |
date_end=datetime.date(year=2021, month=10, day=1),
|
|
92 |
)
|
|
93 |
subscription2 = Subscription.objects.create(
|
|
94 |
agenda=agenda,
|
|
95 |
user_external_id='xxx',
|
|
96 |
date_start=datetime.date(year=2022, month=9, day=1),
|
|
97 |
date_end=datetime.date(year=2022, month=10, day=1),
|
|
98 |
)
|
|
99 |
|
|
100 |
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
101 |
|
|
102 |
resp = app.get('/api/agenda/%s/subscription/' % agenda.slug, params={'date_start': '2021-08-31'})
|
|
103 |
assert [d['id'] for d in resp.json['data']] == [subscription1.pk, subscription2.pk]
|
|
104 |
resp = app.get('/api/agenda/%s/subscription/' % agenda.slug, params={'date_start': '2021-09-02'})
|
|
105 |
assert [d['id'] for d in resp.json['data']] == [subscription2.pk]
|
|
106 |
resp = app.get('/api/agenda/%s/subscription/' % agenda.slug, params={'date_start': '2022-09-02'})
|
|
107 |
assert [d['id'] for d in resp.json['data']] == []
|
|
108 |
|
|
109 |
|
|
110 |
def test_api_list_subscription_filter_date_end(app, user):
|
|
111 |
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
|
112 |
subscription1 = Subscription.objects.create(
|
|
113 |
agenda=agenda,
|
|
114 |
user_external_id='xxx',
|
|
115 |
user_first_name='Foo',
|
|
116 |
user_last_name='BAR',
|
|
117 |
user_email='foo@bar.com',
|
|
118 |
user_phone_number='06',
|
|
119 |
extra_data={'foo': 'bar'},
|
|
120 |
date_start=datetime.date(year=2021, month=9, day=1),
|
|
121 |
date_end=datetime.date(year=2021, month=10, day=1),
|
|
122 |
)
|
|
123 |
subscription2 = Subscription.objects.create(
|
|
124 |
agenda=agenda,
|
|
125 |
user_external_id='xxx',
|
|
126 |
date_start=datetime.date(year=2022, month=9, day=1),
|
|
127 |
date_end=datetime.date(year=2022, month=10, day=1),
|
|
128 |
)
|
|
129 |
|
|
130 |
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
131 |
|
|
132 |
resp = app.get('/api/agenda/%s/subscription/' % agenda.slug, params={'date_end': '2022-10-02'})
|
|
133 |
assert [d['id'] for d in resp.json['data']] == [subscription1.pk, subscription2.pk]
|
|
134 |
resp = app.get('/api/agenda/%s/subscription/' % agenda.slug, params={'date_end': '2021-10-02'})
|
|
135 |
assert [d['id'] for d in resp.json['data']] == [subscription1.pk]
|
|
136 |
resp = app.get('/api/agenda/%s/subscription/' % agenda.slug, params={'date_end': '2021-09-30'})
|
|
137 |
assert [d['id'] for d in resp.json['data']] == []
|
|
138 |
|
|
139 |
|
10 |
140 |
def test_api_create_subscription(app, user):
|
11 |
141 |
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
12 |
142 |
|
13 |
|
-
|