| author | ymh <ymh.work@gmail.com> |
| Wed, 19 Jul 2017 15:57:13 +0200 | |
| changeset 119 | 8ff8e2aee0f9 |
| parent 74 | 043477fd5c5c |
| child 128 | 34a75bd8d0b9 |
| 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 |
|
9 |
from django.urls import reverse |
|
10 |
from django.utils import timezone |
|
11 |
from rest_framework import status |
|
12 |
from rest_framework.test import APITransactionTestCase |
|
13 |
||
14 |
from notes.models import Session, Note |
|
15 |
||
16 |
logger = logging.getLogger(__name__) |
|
17 |
||
18 |
class SessionApiTests(APITransactionTestCase): |
|
19 |
||
20 |
def setUp(self): |
|
21 |
User = get_user_model() |
|
22 |
user1 = User.objects.create_user( |
|
23 |
username='test_user1', |
|
24 |
email='test_user@emial.com', |
|
25 |
password='top_secret' |
|
26 |
) |
|
27 |
user2 = User.objects.create_user( |
|
28 |
username='test_user2', |
|
29 |
email='test_user@emial.com', |
|
30 |
password='top_secret' |
|
31 |
) |
|
32 |
user3 = User.objects.create_user( |
|
33 |
username='test_user3', |
|
34 |
email='test_user@emial.com', |
|
35 |
password='top_secret' |
|
36 |
) |
|
37 |
||
38 |
self.session1 = Session.objects.create( |
|
39 |
title="a new session 1", |
|
40 |
description="Description 1", |
|
41 |
protocol="[]", |
|
42 |
owner=user1 |
|
43 |
) |
|
44 |
||
45 |
self.session2 = Session.objects.create( |
|
46 |
title="a new session 2", |
|
47 |
description="Description 2", |
|
48 |
protocol="[]", |
|
49 |
owner=user2 |
|
50 |
) |
|
51 |
||
|
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
|
52 |
self.session3 = Session.objects.create( |
| 31 | 53 |
title="a new session 3", |
54 |
description="Description 3", |
|
55 |
protocol="[]", |
|
56 |
owner=user3 |
|
57 |
) |
|
58 |
||
|
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
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
protocol="[]", |
|
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
|
63 |
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
|
64 |
) |
|
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
|
65 |
|
| 31 | 66 |
Note.objects.create( |
67 |
tc_start=timezone.now(), |
|
68 |
tc_end=timezone.now(), |
|
69 |
session=self.session1, |
|
70 |
plain="example note 1", |
|
71 |
html="<i>example note 1</i>", |
|
72 |
raw="<i>example note 1</i>", |
|
73 |
margin_note="margin note 1", |
|
74 |
categorization="[]" |
|
75 |
) |
|
76 |
||
77 |
Note.objects.create( |
|
78 |
tc_start=timezone.now(), |
|
79 |
tc_end=timezone.now(), |
|
80 |
session=self.session2, |
|
81 |
plain="example note 2", |
|
82 |
html="<i>example note</i>", |
|
83 |
raw="<i>example note</i>", |
|
84 |
margin_note="margin note", |
|
85 |
categorization="[]" |
|
86 |
) |
|
87 |
||
88 |
||
89 |
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
|
90 |
url = reverse('notes:session-list') |
| 31 | 91 |
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
|
92 |
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) |
| 31 | 93 |
|
94 |
||
95 |
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
|
96 |
url = reverse('notes:session-list') |
| 31 | 97 |
self.client.login(username='test_user1', password='top_secret') |
98 |
response = self.client.get(url) |
|
99 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
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
|
105 |
|
|
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
|
106 |
for session in json['results']: |
| 31 | 107 |
self.assertEqual(session['owner'], 'test_user1') |
108 |
||
109 |
||
110 |
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
|
111 |
url = reverse('notes:session-list') |
| 31 | 112 |
response = self.client.post(url, { |
113 |
'title': "a new session", |
|
114 |
'description': "description of the session", |
|
115 |
'protocol': "[]" |
|
116 |
}, format='json') |
|
117 |
||
|
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
|
118 |
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) |
| 31 | 119 |
|
120 |
||
121 |
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
|
122 |
url = reverse('notes:session-list') |
| 31 | 123 |
self.client.login(username='test_user1', password='top_secret') |
124 |
response = self.client.post(url, { |
|
125 |
'title': "a new session", |
|
126 |
'description': "description of the session", |
|
127 |
'protocol': "[]" |
|
128 |
}, format='json') |
|
129 |
||
130 |
||
131 |
self.assertEqual(response.status_code, status.HTTP_201_CREATED) |
|
132 |
json = response.json() |
|
133 |
self.assertIn('ext_id', json) |
|
134 |
||
|
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
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
'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
|
141 |
'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
|
142 |
'description': "description of the 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
|
143 |
'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
|
144 |
}, 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
|
145 |
|
|
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
|
146 |
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
|
147 |
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
|
148 |
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
|
149 |
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
|
150 |
|
|
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 |
|
| 31 | 152 |
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
|
153 |
url = reverse('notes:session-detail', kwargs={'ext_id':str(self.session1.ext_id)}) |
| 31 | 154 |
self.client.login(username='test_user1', password='top_secret') |
155 |
response = self.client.get(url, format='json') |
|
156 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
157 |
||
158 |
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
|
159 |
url = reverse('notes:notes-session-list', kwargs={'session_ext_id':str(self.session1.ext_id)}) |
| 31 | 160 |
self.client.login(username='test_user1', password='top_secret') |
161 |
response = self.client.get(url, format='json') |
|
162 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
163 |
||
164 |
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
|
165 |
url = reverse('notes:session-detail', kwargs={'ext_id':str(self.session2.ext_id)}) |
| 31 | 166 |
self.client.login(username='test_user1', password='top_secret') |
167 |
response = self.client.get(url, format='json') |
|
168 |
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) |
|
169 |
||
170 |
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
|
171 |
url = reverse('notes:notes-session-list', kwargs={'session_ext_id':str(self.session2.ext_id)}) |
| 31 | 172 |
self.client.login(username='test_user1', password='top_secret') |
173 |
response = self.client.get(url, format='json') |
|
174 |
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
|
175 |
|
|
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
|
176 |
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
|
177 |
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
|
178 |
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
|
179 |
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
|
180 |
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
|
181 |
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
|
182 |
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
|
183 |
|
|
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
|
184 |
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
|
185 |
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
|
186 |
{'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
|
187 |
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
|
188 |
) |
|
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
|
189 |
|
|
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
|
190 |
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
|
191 |
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
|
192 |
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
|
193 |
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
|
194 |
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
|
195 |
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
|
196 |
|
|
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
|
197 |
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
|
198 |
|
|
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
|
199 |
|
|
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
|
200 |
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
|
201 |
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
|
202 |
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
|
203 |
|
|
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
|
204 |
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
|
205 |
|
|
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
|
206 |
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
|
207 |
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
|
208 |
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
|
209 |
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
|
210 |
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
|
211 |
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
|
212 |
|
|
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
|
213 |
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
|
214 |
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
|
215 |
|
|
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
|
216 |
|
|
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
|
217 |
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
|
218 |
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
|
219 |
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
|
220 |
|
|
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
|
221 |
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
|
222 |
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
|
223 |
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
|
224 |
|
|
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
|
225 |
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
|
226 |
|
|
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
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
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
|
231 |
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
|
232 |
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
|
233 |
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
|
234 |
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
|
235 |