| author | ymh <ymh.work@gmail.com> |
| Tue, 29 Mar 2022 11:23:56 +0200 | |
| changeset 211 | 244a90638e80 |
| parent 142 | 56850f5c73f6 |
| permissions | -rw-r--r-- |
| 31 | 1 |
""" |
2 |
Tests the core api for sessions |
|
3 |
""" |
|
|
119
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
4 |
import datetime |
| 31 | 5 |
import logging |
| 142 | 6 |
from unittest import skip |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
7 |
from uuid import uuid4 |
| 31 | 8 |
|
9 |
from django.contrib.auth import get_user_model |
|
|
131
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
10 |
from django.contrib.auth.models import Group |
| 31 | 11 |
from django.urls import reverse |
12 |
from django.utils import timezone |
|
13 |
from rest_framework import status |
|
14 |
from rest_framework.test import APITransactionTestCase |
|
15 |
||
| 142 | 16 |
from notes import constants |
17 |
from notes.models import GroupProfile, Note, Session |
|
| 31 | 18 |
|
19 |
logger = logging.getLogger(__name__) |
|
20 |
||
21 |
class SessionApiTests(APITransactionTestCase): |
|
22 |
||
23 |
def setUp(self): |
|
24 |
User = get_user_model() |
|
|
131
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
25 |
self.user1 = User.objects.create_user( |
| 31 | 26 |
username='test_user1', |
27 |
email='test_user@emial.com', |
|
28 |
password='top_secret' |
|
29 |
) |
|
|
131
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
30 |
self.user2 = User.objects.create_user( |
| 31 | 31 |
username='test_user2', |
32 |
email='test_user@emial.com', |
|
33 |
password='top_secret' |
|
34 |
) |
|
35 |
user3 = User.objects.create_user( |
|
36 |
username='test_user3', |
|
37 |
email='test_user@emial.com', |
|
38 |
password='top_secret' |
|
39 |
) |
|
40 |
||
|
131
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
41 |
self.group1 = Group(name='group1') |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
42 |
self.group1.save() |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
43 |
self.group1.user_set.add(self.user1) |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
44 |
self.group1.user_set.add(self.user2) |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
45 |
self.group1.profile.owner = self.user1 |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
46 |
self.group1.profile.description = "This is the group 1" |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
47 |
self.group1.profile.save() |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
48 |
|
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
49 |
self.user2.profile.default_group = self.group1 |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
50 |
self.user2.profile.save() |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
51 |
|
| 31 | 52 |
self.session1 = Session.objects.create( |
53 |
title="a new session 1", |
|
54 |
description="Description 1", |
|
|
131
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
55 |
group=self.user1.profile.default_group, |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
56 |
owner=self.user1 |
| 31 | 57 |
) |
58 |
||
59 |
self.session2 = Session.objects.create( |
|
60 |
title="a new session 2", |
|
61 |
description="Description 2", |
|
|
131
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
62 |
group=self.user2.profile.default_group, |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
63 |
owner=self.user2 |
| 31 | 64 |
) |
65 |
||
|
119
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
66 |
self.session3 = Session.objects.create( |
| 31 | 67 |
title="a new session 3", |
68 |
description="Description 3", |
|
|
131
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
69 |
group=user3.profile.default_group, |
| 31 | 70 |
owner=user3 |
71 |
) |
|
72 |
||
|
119
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
73 |
self.session4 = Session.objects.create( |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
74 |
title="a new session 4", |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
75 |
description="Description 4", |
|
131
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
76 |
group=user3.profile.default_group, |
|
119
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
77 |
owner=user3 |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
78 |
) |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
79 |
|
| 31 | 80 |
Note.objects.create( |
81 |
tc_start=timezone.now(), |
|
82 |
tc_end=timezone.now(), |
|
83 |
session=self.session1, |
|
84 |
plain="example note 1", |
|
85 |
html="<i>example note 1</i>", |
|
86 |
raw="<i>example note 1</i>", |
|
87 |
margin_note="margin note 1", |
|
88 |
categorization="[]" |
|
89 |
) |
|
90 |
||
91 |
Note.objects.create( |
|
92 |
tc_start=timezone.now(), |
|
93 |
tc_end=timezone.now(), |
|
94 |
session=self.session2, |
|
95 |
plain="example note 2", |
|
96 |
html="<i>example note</i>", |
|
97 |
raw="<i>example note</i>", |
|
98 |
margin_note="margin note", |
|
99 |
categorization="[]" |
|
100 |
) |
|
101 |
||
102 |
||
103 |
def test_list_session_no_user(self): |
|
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
104 |
url = reverse('notes:session-list') |
| 31 | 105 |
response = self.client.post(url) |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
106 |
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) |
| 31 | 107 |
|
108 |
||
109 |
def test_list_session(self): |
|
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
110 |
url = reverse('notes:session-list') |
| 31 | 111 |
self.client.login(username='test_user1', password='top_secret') |
112 |
response = self.client.get(url) |
|
113 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
114 |
json = response.json() |
|
|
119
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
115 |
self.assertIn('results', json, "must have results") |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
116 |
self.assertIn('count', json, "must have count") |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
117 |
self.assertEqual(json['count'], 1, "must have one session") |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
118 |
self.assertEqual(len(json['results']), 1, "must have one session") |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
119 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
120 |
for session in json['results']: |
| 31 | 121 |
self.assertEqual(session['owner'], 'test_user1') |
122 |
||
123 |
||
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
124 |
def test_list_session_filter(self): |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
125 |
url = reverse('notes:session-list') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
126 |
self.client.login(username='test_user1', password='top_secret') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
127 |
response = self.client.get(url, {"ext_id__in": ",".join([str(self.session1.ext_id)])}) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
128 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
129 |
json = response.json() |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
130 |
self.assertIn('results', json, "must have results") |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
131 |
self.assertIn('count', json, "must have count") |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
132 |
self.assertEqual(json['count'], 1, "must have one session") |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
133 |
self.assertEqual(len(json['results']), 1, "must have one session") |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
134 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
135 |
for session in json['results']: |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
136 |
self.assertEqual(session['owner'], 'test_user1') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
137 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
138 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
139 |
def test_list_session_filter_bad(self): |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
140 |
url = reverse('notes:session-list') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
141 |
self.client.login(username='test_user1', password='top_secret') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
142 |
response = self.client.get(url, {"ext_id__in": ",".join([str(uuid4())])}) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
143 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
144 |
json = response.json() |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
145 |
self.assertIn('results', json, "must have results") |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
146 |
self.assertIn('count', json, "must have count") |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
147 |
self.assertEqual(json['count'], 0, "must have no session") |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
148 |
self.assertEqual(len(json['results']), 0, "must have no session") |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
149 |
|
| 31 | 150 |
def test_create_session_no_user(self): |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
151 |
url = reverse('notes:session-list') |
| 31 | 152 |
response = self.client.post(url, { |
153 |
'title': "a new session", |
|
154 |
'description': "description of the session", |
|
155 |
'protocol': "[]" |
|
156 |
}, format='json') |
|
157 |
||
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
158 |
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) |
| 31 | 159 |
|
160 |
||
161 |
def test_create_session(self): |
|
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
162 |
url = reverse('notes:session-list') |
| 31 | 163 |
self.client.login(username='test_user1', password='top_secret') |
164 |
response = self.client.post(url, { |
|
165 |
'title': "a new session", |
|
166 |
'description': "description of the session", |
|
|
131
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
167 |
'group': 'group1' |
| 31 | 168 |
}, format='json') |
169 |
||
| 142 | 170 |
self.assertEqual(response.status_code, status.HTTP_201_CREATED, "error msg: %r" % response.content) |
171 |
json = response.json() |
|
172 |
self.assertIn('ext_id', json) |
|
173 |
||
174 |
session = Session.objects.get(ext_id=json['ext_id']) |
|
175 |
self.assertIsNotNone(session) |
|
176 |
self.assertEqual(self.group1, session.group) |
|
177 |
self.assertEqual(self.group1.profile.protocol, session.protocol) |
|
178 |
||
179 |
||
180 |
def test_create_session_protocol(self): |
|
181 |
url = reverse('notes:session-list') |
|
182 |
self.client.login(username='test_user1', password='top_secret') |
|
183 |
response = self.client.post(url, { |
|
184 |
'title': "a new session", |
|
185 |
'description': "description of the session", |
|
186 |
'group': 'group1', |
|
187 |
'protocol': {} |
|
188 |
}, format='json') |
|
189 |
||
190 |
self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.json()) |
|
191 |
json = response.json() |
|
192 |
self.assertIn('ext_id', json) |
|
193 |
||
194 |
session = Session.objects.get(ext_id=json['ext_id']) |
|
195 |
self.assertIsNotNone(session) |
|
196 |
self.assertEqual(self.group1, session.group) |
|
197 |
self.assertNotEqual(self.group1.profile.protocol, session.protocol) |
|
198 |
||
199 |
||
200 |
def test_create_session_protocol_as_str(self): |
|
201 |
url = reverse('notes:session-list') |
|
202 |
self.client.login(username='test_user1', password='top_secret') |
|
203 |
group1 = Group.objects.get(id=self.group1.id) |
|
204 |
response = self.client.post(url, { |
|
205 |
'title': "a new session", |
|
206 |
'description': "description of the session", |
|
207 |
'group': 'group1', |
|
208 |
'protocol': group1.profile.protocol |
|
209 |
}, format='json') |
|
210 |
||
211 |
self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.json()) |
|
| 31 | 212 |
json = response.json() |
213 |
self.assertIn('ext_id', json) |
|
214 |
||
|
131
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
215 |
session = Session.objects.get(ext_id=json['ext_id']) |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
216 |
self.assertIsNotNone(session) |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
217 |
self.assertEqual(self.group1, session.group) |
| 142 | 218 |
self.assertEqual(self.group1.profile.protocol, session.protocol) |
219 |
||
220 |
||
221 |
def test_create_session_protocol_as_str_unknown(self): |
|
222 |
url = reverse('notes:session-list') |
|
223 |
self.client.login(username='test_user1', password='top_secret') |
|
224 |
group1 = Group.objects.get(id=self.group1.id) |
|
225 |
response = self.client.post(url, { |
|
226 |
'title': "a new session", |
|
227 |
'description': "description of the session", |
|
228 |
'group': 'group1', |
|
229 |
'protocol': constants.PROTOCOL_URN_PREFIX + str(uuid4()) + ".1" |
|
230 |
}, format='json') |
|
231 |
||
232 |
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.json()) |
|
233 |
json = response.json() |
|
234 |
self.assertIn('protocol', json) |
|
235 |
self.assertIn('Incorrect protocol', json['protocol'][0]) |
|
236 |
self.assertIn('does not exists', json['protocol'][0]) |
|
237 |
||
238 |
||
239 |
def test_create_session_protocol_as_str_bad(self): |
|
240 |
url = reverse('notes:session-list') |
|
241 |
self.client.login(username='test_user1', password='top_secret') |
|
242 |
group1 = Group.objects.get(id=self.group1.id) |
|
243 |
response = self.client.post(url, { |
|
244 |
'title': "a new session", |
|
245 |
'description': "description of the session", |
|
246 |
'group': 'group1', |
|
247 |
'protocol': constants.PROTOCOL_URN_PREFIX + "foo" |
|
248 |
}, format='json') |
|
249 |
||
250 |
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.json()) |
|
251 |
json = response.json() |
|
252 |
self.assertIn('protocol', json) |
|
253 |
self.assertEqual('Incorrect format. Expected `urn:protocol:<ext_id>.<version>`.', json['protocol'][0]) |
|
254 |
||
255 |
||
256 |
def test_create_session_protocol_as_other_type_bad(self): |
|
257 |
url = reverse('notes:session-list') |
|
258 |
self.client.login(username='test_user1', password='top_secret') |
|
259 |
group1 = Group.objects.get(id=self.group1.id) |
|
260 |
response = self.client.post(url, { |
|
261 |
'title': "a new session", |
|
262 |
'description': "description of the session", |
|
263 |
'group': 'group1', |
|
264 |
'protocol': True |
|
265 |
}, format='json') |
|
266 |
||
267 |
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.json()) |
|
268 |
json = response.json() |
|
269 |
self.assertIn('protocol', json) |
|
270 |
self.assertEqual('Incorrect format. Expected `urn:protocol:<ext_id>.<version>` or dict.', json['protocol'][0]) |
|
|
131
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
271 |
|
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
272 |
|
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
273 |
def test_create_session_no_group(self): |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
274 |
url = reverse('notes:session-list') |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
275 |
self.client.login(username='test_user1', password='top_secret') |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
276 |
response = self.client.post(url, { |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
277 |
'title': "a new session", |
| 142 | 278 |
'description': "description of the session" |
|
131
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
279 |
}, format='json') |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
280 |
|
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
281 |
self.assertEqual(response.status_code, status.HTTP_201_CREATED, "Error when creating session %r" % response.json()) |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
282 |
json = response.json() |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
283 |
self.assertIn('ext_id', json) |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
284 |
|
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
285 |
session = Session.objects.get(ext_id=json['ext_id']) |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
286 |
self.assertIsNotNone(session) |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
287 |
user1_personal_group = Group.objects.get(profile__owner_personal=self.user1) |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
288 |
self.assertEqual(user1_personal_group, session.group) |
| 142 | 289 |
self.assertEqual(user1_personal_group.profile.protocol, session.protocol) |
|
131
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
290 |
|
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
291 |
def test_create_session_no_group_default(self): |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
292 |
url = reverse('notes:session-list') |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
293 |
self.client.login(username='test_user2', password='top_secret') |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
294 |
response = self.client.post(url, { |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
295 |
'title': "a new session", |
| 142 | 296 |
'description': "description of the session" |
|
131
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
297 |
}, format='json') |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
298 |
|
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
299 |
self.assertEqual(response.status_code, status.HTTP_201_CREATED, "Error when creating session %r" % response.json()) |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
300 |
json = response.json() |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
301 |
self.assertIn('ext_id', json) |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
302 |
|
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
303 |
session = Session.objects.get(ext_id=json['ext_id']) |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
304 |
self.assertIsNotNone(session) |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
305 |
self.assertEqual(self.group1, session.group) |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
306 |
|
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
307 |
|
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
308 |
def test_create_session_bad_group(self): |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
309 |
url = reverse('notes:session-list') |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
310 |
self.client.login(username='test_user3', password='top_secret') |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
311 |
response = self.client.post(url, { |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
312 |
'title': "a new session", |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
313 |
'description': "description of the session", |
| 142 | 314 |
'protocol': { 'owner': 'group1' }, |
|
131
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
315 |
'group': "group1" |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
316 |
}, format='json') |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
317 |
|
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
318 |
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
319 |
json = response.json() |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
320 |
self.assertIn('non_field_errors', json) |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
321 |
self.assertIn('Owner must be in group', json['non_field_errors']) |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
322 |
|
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
323 |
|
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
324 |
def test_create_session_with_ext_id(self): |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
325 |
url = reverse('notes:session-list') |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
326 |
self.client.login(username='test_user1', password='top_secret') |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
327 |
ext_id = str(uuid4()) |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
328 |
response = self.client.post(url, { |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
329 |
'ext_id': ext_id, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
330 |
'title': "a new session", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
331 |
'description': "description of the session", |
| 142 | 332 |
'group': 'group1' |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
333 |
}, format='json') |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
334 |
|
| 142 | 335 |
self.assertEqual(response.status_code, status.HTTP_201_CREATED, "response content: %r" % response.content) |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
336 |
json = response.json() |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
337 |
self.assertIn('ext_id', json) |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
338 |
self.assertEqual(json['ext_id'], ext_id) |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
339 |
|
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
340 |
|
| 31 | 341 |
def test_detail_session(self): |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
342 |
url = reverse('notes:session-detail', kwargs={'ext_id':str(self.session1.ext_id)}) |
| 31 | 343 |
self.client.login(username='test_user1', password='top_secret') |
344 |
response = self.client.get(url, format='json') |
|
345 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
346 |
||
347 |
def test_list_notes(self): |
|
|
119
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
348 |
url = reverse('notes:notes-session-list', kwargs={'session_ext_id':str(self.session1.ext_id)}) |
| 31 | 349 |
self.client.login(username='test_user1', password='top_secret') |
350 |
response = self.client.get(url, format='json') |
|
351 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
352 |
||
353 |
def test_detail_session_bad(self): |
|
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
354 |
url = reverse('notes:session-detail', kwargs={'ext_id':str(self.session2.ext_id)}) |
| 31 | 355 |
self.client.login(username='test_user1', password='top_secret') |
356 |
response = self.client.get(url, format='json') |
|
357 |
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) |
|
358 |
||
359 |
def test_list_notes_bad(self): |
|
|
119
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
360 |
url = reverse('notes:notes-session-list', kwargs={'session_ext_id':str(self.session2.ext_id)}) |
| 31 | 361 |
self.client.login(username='test_user1', password='top_secret') |
362 |
response = self.client.get(url, format='json') |
|
363 |
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) |
|
|
119
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
364 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
365 |
def test_filter_modified_since(self): |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
366 |
url = reverse('notes:session-list') |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
367 |
self.client.login(username='test_user3', password='top_secret') |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
368 |
nexthour = \ |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
369 |
datetime.datetime.utcnow().replace(tzinfo=timezone.utc) +\ |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
370 |
datetime.timedelta(hours=1) |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
371 |
Session.objects.filter(pk=self.session4.id).update(updated=nexthour) |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
372 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
373 |
response = self.client.get( |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
374 |
url, |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
375 |
{'modified_since': (nexthour - datetime.timedelta(minutes=30)).timestamp()}, |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
376 |
format='json' |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
377 |
) |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
378 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
379 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
380 |
json = response.json() |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
381 |
self.assertIn('results', json, "must have results") |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
382 |
self.assertIn('count', json, "must have count") |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
383 |
self.assertEqual(json['count'], 1, "must have one session") |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
384 |
self.assertEqual(len(json['results']), 1, "must have one session") |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
385 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
386 |
self.assertEqual(json['results'][0].get('title'), "a new session 4") |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
387 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
388 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
389 |
def test_filter_modified_since_zero(self): |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
390 |
url = reverse('notes:session-list') |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
391 |
self.client.login(username='test_user3', password='top_secret') |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
392 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
393 |
response = self.client.get(url, {'modified_since': 0}, format='json') |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
394 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
395 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
396 |
json = response.json() |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
397 |
self.assertIn('results', json, "must have results") |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
398 |
self.assertIn('count', json, "must have count") |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
399 |
self.assertEqual(json['count'], 2, "must have two sessions") |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
400 |
self.assertEqual(len(json['results']), 2, "must have two sessions") |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
401 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
402 |
for session_json in json['results']: |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
403 |
self.assertIn(session_json.get('title'), ['a new session 3', 'a new session 4']) |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
404 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
405 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
406 |
def test_filter_modified_seconds(self): |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
407 |
url = reverse('notes:session-list') |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
408 |
self.client.login(username='test_user3', password='top_secret') |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
409 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
410 |
prevmoment = \ |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
411 |
datetime.datetime.utcnow().replace(tzinfo=timezone.utc) -\ |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
412 |
datetime.timedelta(seconds=5) |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
413 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
414 |
response = self.client.get(url, {'modified_since': prevmoment.timestamp()}, format='json') |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
415 |
|
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
416 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
417 |
json = response.json() |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
418 |
self.assertIn('results', json, "must have results") |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
419 |
self.assertIn('count', json, "must have count") |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
420 |
self.assertEqual(json['count'], 2, "must have two sessions") |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
421 |
self.assertEqual(len(json['results']), 2, "must have two sessions") |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
422 |
for session_json in json['results']: |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
423 |
self.assertIn(session_json.get('title'), ['a new session 3', 'a new session 4']) |
|
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
424 |
|
| 142 | 425 |
def test_update_session(self): |
426 |
url = reverse('notes:session-detail', kwargs={'ext_id': self.session1.ext_id}) |
|
427 |
||
428 |
self.client.login(username='test_user1', password='top_secret') |
|
429 |
response = self.client.put(url, { |
|
430 |
'title': "a new session", |
|
431 |
'description': "description of the session", |
|
432 |
'group': 'group1' |
|
433 |
}, format='json') |
|
434 |
||
435 |
self.assertEqual(response.status_code, status.HTTP_200_OK, "response content: %r" % response.content) |
|
436 |
json = response.json() |
|
437 |
self.assertIn('ext_id', json) |
|
438 |
||
439 |
session = Session.objects.get(ext_id=json['ext_id']) |
|
440 |
self.assertIsNotNone(session) |
|
441 |
self.assertEqual(self.group1, session.group) |
|
442 |
self.assertEqual(self.group1.profile.protocol, session.protocol) |
|
443 |
||
444 |
@skip("Protocol update not yet implemented") |
|
445 |
def test_update_session_protocol(self): |
|
446 |
url = reverse('notes:session-detail', kwargs={'ext_id': self.session1.ext_id}) |
|
447 |
||
448 |
self.client.login(username='test_user1', password='top_secret') |
|
449 |
response = self.client.put(url, { |
|
450 |
'title': "an updated session", |
|
451 |
'description': "description of the session", |
|
452 |
'group': 'group1', |
|
453 |
'protocol': "urn:protocol:845ac623-b85a-4ddd-91ee-a2deb1a9b54f.3" |
|
454 |
}, format='json') |
|
455 |
||
456 |
json = response.json() |
|
457 |
# self.assertIn('ext_id', json) |
|
458 |
session = Session.objects.get(ext_id=self.session1.ext_id) |
|
459 |
self.assertEqual(response.status_code, status.HTTP_200_OK, "response content: %r" % response.content) |
|
460 |
||
461 |
||
462 |
# session = Session.objects.get(ext_id=json['ext_id']) |
|
463 |
# self.assertIsNotNone(session) |
|
464 |
# self.assertEqual(self.group1, session.group) |
|
465 |
# self.assertEqual(self.group1.profile.protocol, session.protocol) |