| author | ymh <ymh.work@gmail.com> |
| Mon, 31 Jul 2017 23:18:38 +0200 | |
| changeset 131 | adad5563603c |
| parent 128 | 34a75bd8d0b9 |
| child 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 |
|
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
|
6 |
from uuid import uuid4 |
| 31 | 7 |
|
8 |
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
|
9 |
from django.contrib.auth.models import Group |
| 31 | 10 |
from django.urls import reverse |
11 |
from django.utils import timezone |
|
12 |
from rest_framework import status |
|
13 |
from rest_framework.test import APITransactionTestCase |
|
14 |
||
|
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
|
15 |
from notes.models import Session, Note, GroupProfile |
| 31 | 16 |
|
17 |
logger = logging.getLogger(__name__) |
|
18 |
||
19 |
class SessionApiTests(APITransactionTestCase): |
|
20 |
||
21 |
def setUp(self): |
|
22 |
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
|
23 |
self.user1 = User.objects.create_user( |
| 31 | 24 |
username='test_user1', |
25 |
email='test_user@emial.com', |
|
26 |
password='top_secret' |
|
27 |
) |
|
|
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
|
28 |
self.user2 = User.objects.create_user( |
| 31 | 29 |
username='test_user2', |
30 |
email='test_user@emial.com', |
|
31 |
password='top_secret' |
|
32 |
) |
|
33 |
user3 = User.objects.create_user( |
|
34 |
username='test_user3', |
|
35 |
email='test_user@emial.com', |
|
36 |
password='top_secret' |
|
37 |
) |
|
38 |
||
|
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
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
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
|
45 |
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
|
46 |
|
|
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.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
|
48 |
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
|
49 |
|
| 31 | 50 |
self.session1 = Session.objects.create( |
51 |
title="a new session 1", |
|
52 |
description="Description 1", |
|
53 |
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
|
54 |
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
|
55 |
owner=self.user1 |
| 31 | 56 |
) |
57 |
||
58 |
self.session2 = Session.objects.create( |
|
59 |
title="a new session 2", |
|
60 |
description="Description 2", |
|
61 |
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
|
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", |
|
69 |
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
|
70 |
group=user3.profile.default_group, |
| 31 | 71 |
owner=user3 |
72 |
) |
|
73 |
||
|
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
|
74 |
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
|
75 |
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
|
76 |
description="Description 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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
) |
|
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
|
81 |
|
| 31 | 82 |
Note.objects.create( |
83 |
tc_start=timezone.now(), |
|
84 |
tc_end=timezone.now(), |
|
85 |
session=self.session1, |
|
86 |
plain="example note 1", |
|
87 |
html="<i>example note 1</i>", |
|
88 |
raw="<i>example note 1</i>", |
|
89 |
margin_note="margin note 1", |
|
90 |
categorization="[]" |
|
91 |
) |
|
92 |
||
93 |
Note.objects.create( |
|
94 |
tc_start=timezone.now(), |
|
95 |
tc_end=timezone.now(), |
|
96 |
session=self.session2, |
|
97 |
plain="example note 2", |
|
98 |
html="<i>example note</i>", |
|
99 |
raw="<i>example note</i>", |
|
100 |
margin_note="margin note", |
|
101 |
categorization="[]" |
|
102 |
) |
|
103 |
||
104 |
||
105 |
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
|
106 |
url = reverse('notes:session-list') |
| 31 | 107 |
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
|
108 |
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) |
| 31 | 109 |
|
110 |
||
111 |
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
|
112 |
url = reverse('notes:session-list') |
| 31 | 113 |
self.client.login(username='test_user1', password='top_secret') |
114 |
response = self.client.get(url) |
|
115 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
|
|
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
|
122 |
for session in json['results']: |
| 31 | 123 |
self.assertEqual(session['owner'], 'test_user1') |
124 |
||
125 |
||
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
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
|
131 |
json = response.json() |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
132 |
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
|
133 |
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
|
134 |
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
|
135 |
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
|
136 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
137 |
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
|
138 |
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
|
139 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
140 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
141 |
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
|
142 |
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
|
143 |
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
|
144 |
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
|
145 |
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
|
146 |
json = response.json() |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
147 |
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
|
148 |
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
|
149 |
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
|
150 |
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
|
151 |
|
| 31 | 152 |
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
|
153 |
url = reverse('notes:session-list') |
| 31 | 154 |
response = self.client.post(url, { |
155 |
'title': "a new session", |
|
156 |
'description': "description of the session", |
|
157 |
'protocol': "[]" |
|
158 |
}, format='json') |
|
159 |
||
|
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
|
160 |
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) |
| 31 | 161 |
|
162 |
||
163 |
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
|
164 |
url = reverse('notes:session-list') |
| 31 | 165 |
self.client.login(username='test_user1', password='top_secret') |
166 |
response = self.client.post(url, { |
|
167 |
'title': "a new session", |
|
168 |
'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
|
169 |
'protocol': "[]", |
|
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
|
170 |
'group': 'group1' |
| 31 | 171 |
}, format='json') |
172 |
||
173 |
self.assertEqual(response.status_code, status.HTTP_201_CREATED) |
|
174 |
json = response.json() |
|
175 |
self.assertIn('ext_id', json) |
|
176 |
||
|
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
|
177 |
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
|
178 |
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
|
179 |
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
|
180 |
|
|
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
|
181 |
|
|
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
|
182 |
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
|
183 |
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
|
184 |
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
|
185 |
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
|
186 |
'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
|
187 |
'description': "description of the 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
|
188 |
'protocol': "[]", |
|
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
|
189 |
}, 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
|
190 |
|
|
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
|
191 |
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
|
192 |
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
|
193 |
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
|
194 |
|
|
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
|
195 |
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
|
196 |
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
|
197 |
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
|
198 |
self.assertEqual(user1_personal_group, 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
|
199 |
|
|
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
|
200 |
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
|
201 |
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
|
202 |
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
|
203 |
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
|
204 |
'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
|
205 |
'description': "description of the 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
|
206 |
'protocol': "[]", |
|
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
|
207 |
}, 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
|
208 |
|
|
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
|
209 |
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
|
210 |
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
|
211 |
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
|
212 |
|
|
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
|
213 |
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
|
214 |
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
|
215 |
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
|
216 |
|
|
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 |
|
|
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
|
218 |
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
|
219 |
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
|
220 |
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
|
221 |
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
|
222 |
'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
|
223 |
'description': "description of the 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
|
224 |
'protocol': "[]", |
|
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
|
225 |
}, 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
|
226 |
|
|
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
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
|
|
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
|
231 |
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
|
232 |
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
|
233 |
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
|
234 |
|
|
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
|
235 |
|
|
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
|
236 |
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
|
237 |
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
|
238 |
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
|
239 |
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
|
240 |
'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
|
241 |
'description': "description of the 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
|
242 |
'protocol': "[]", |
|
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
|
243 |
'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
|
244 |
}, 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
|
245 |
|
|
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
|
246 |
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
|
247 |
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
|
248 |
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
|
249 |
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
|
250 |
|
|
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
|
251 |
|
|
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
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
'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
|
258 |
'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
|
259 |
'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
|
260 |
'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
|
261 |
'protocol': "[]" |
|
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
|
262 |
}, 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
|
263 |
|
|
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
|
264 |
self.assertEqual(response.status_code, status.HTTP_201_CREATED) |
|
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
|
265 |
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
|
266 |
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
|
267 |
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
|
268 |
|
|
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
|
269 |
|
| 31 | 270 |
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
|
271 |
url = reverse('notes:session-detail', kwargs={'ext_id':str(self.session1.ext_id)}) |
| 31 | 272 |
self.client.login(username='test_user1', password='top_secret') |
273 |
response = self.client.get(url, format='json') |
|
274 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
275 |
||
276 |
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
|
277 |
url = reverse('notes:notes-session-list', kwargs={'session_ext_id':str(self.session1.ext_id)}) |
| 31 | 278 |
self.client.login(username='test_user1', password='top_secret') |
279 |
response = self.client.get(url, format='json') |
|
280 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
281 |
||
282 |
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
|
283 |
url = reverse('notes:session-detail', kwargs={'ext_id':str(self.session2.ext_id)}) |
| 31 | 284 |
self.client.login(username='test_user1', password='top_secret') |
285 |
response = self.client.get(url, format='json') |
|
286 |
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) |
|
287 |
||
288 |
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
|
289 |
url = reverse('notes:notes-session-list', kwargs={'session_ext_id':str(self.session2.ext_id)}) |
| 31 | 290 |
self.client.login(username='test_user1', password='top_secret') |
291 |
response = self.client.get(url, format='json') |
|
292 |
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
|
293 |
|
|
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
|
294 |
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
|
295 |
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
|
296 |
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
|
297 |
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
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
|
|
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
|
302 |
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
|
303 |
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
|
304 |
{'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
|
305 |
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
|
306 |
) |
|
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
|
307 |
|
|
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
|
308 |
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
|
309 |
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
|
310 |
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
|
311 |
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
|
312 |
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
|
313 |
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
|
314 |
|
|
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
|
315 |
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
|
316 |
|
|
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
|
317 |
|
|
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
|
318 |
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
|
319 |
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
|
320 |
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
|
321 |
|
|
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
|
322 |
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
|
323 |
|
|
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
|
324 |
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
|
325 |
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
|
326 |
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
|
327 |
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
|
328 |
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
|
329 |
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
|
330 |
|
|
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
|
331 |
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
|
332 |
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
|
333 |
|
|
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
|
334 |
|
|
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
|
335 |
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
|
336 |
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
|
337 |
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
|
338 |
|
|
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
|
339 |
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
|
340 |
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
|
341 |
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
|
342 |
|
|
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
|
343 |
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
|
344 |
|
|
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
|
345 |
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
|
346 |
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
|
347 |
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
|
348 |
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
|
349 |
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
|
350 |
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
|
351 |
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
|
352 |
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
|
353 |