| author | ymh <ymh.work@gmail.com> |
| Tue, 25 Jul 2017 19:11:26 +0200 | |
| changeset 128 | 34a75bd8d0b9 |
| parent 126 | ba8bc0199464 |
| child 129 | d48946d164c6 |
| permissions | -rw-r--r-- |
| 126 | 1 |
""" |
2 |
Tests the sync api |
|
3 |
""" |
|
4 |
import datetime |
|
5 |
import logging |
|
6 |
||
7 |
from django.contrib.auth import get_user_model |
|
8 |
from django.contrib.contenttypes.models import ContentType |
|
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 |
from auditlog.models import LogEntry |
|
16 |
||
17 |
logger = logging.getLogger(__name__) |
|
18 |
||
19 |
||
20 |
class SyncApiTests(APITransactionTestCase): |
|
21 |
''' |
|
22 |
Test Sync api |
|
23 |
''' |
|
24 |
||
25 |
def setUp(self): |
|
26 |
User = get_user_model() |
|
27 |
user1 = User.objects.create_user( |
|
28 |
username='test_user1', |
|
29 |
email='test_user@emial.com', |
|
30 |
password='top_secret' |
|
31 |
) |
|
32 |
user2 = User.objects.create_user( |
|
33 |
username='test_user2', |
|
34 |
email='test_user@emial.com', |
|
35 |
password='top_secret' |
|
36 |
) |
|
37 |
user3 = User.objects.create_user( |
|
38 |
username='test_user3', |
|
39 |
email='test_user@emial.com', |
|
40 |
password='top_secret' |
|
41 |
) |
|
42 |
||
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
43 |
url = reverse('notes:session-list') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
44 |
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:
126
diff
changeset
|
45 |
response = self.client.post(url, { |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
46 |
'title': "a new session 1", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
47 |
'description': "Description 1", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
48 |
'protocol': "[]" |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
49 |
}, format='json') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
50 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
51 |
logger.debug('REPOSNSE %r', response.json()) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
52 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
53 |
self.session1 = Session.objects.get(ext_id=response.json()['ext_id']) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
54 |
self.client.logout() |
| 126 | 55 |
|
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
56 |
self.client.login(username='test_user2', password='top_secret') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
57 |
response = self.client.post(url, { |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
58 |
'title': "a new session 2", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
59 |
'description': "Description 2", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
60 |
'protocol': "[]" |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
61 |
}, format='json') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
62 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
63 |
self.session2 = Session.objects.get(ext_id=response.json()['ext_id']) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
64 |
self.client.logout() |
| 126 | 65 |
|
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
66 |
self.client.login(username='test_user3', password='top_secret') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
67 |
response = self.client.post(url, { |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
68 |
'title': "a new session 3", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
69 |
'description': "Description 3", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
70 |
'protocol': "[]" |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
71 |
}, format='json') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
72 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
73 |
self.session3 = Session.objects.get(ext_id=response.json()['ext_id']) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
74 |
self.client.logout() |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
75 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
76 |
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:
126
diff
changeset
|
77 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
78 |
url = reverse('notes:notes-session-list', |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
79 |
kwargs={'session_ext_id': self.session1.ext_id}) |
| 126 | 80 |
|
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
81 |
response = self.client.post(url, { |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
82 |
'tc_start': timezone.now(), |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
83 |
'tc_end': timezone.now(), |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
84 |
'plain': "example note 1", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
85 |
'html': "<i>example note 1</i>", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
86 |
'raw': "<i>example note 1</i>", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
87 |
'margin_note': "margin note 1", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
88 |
'categorization': "[]" |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
89 |
}, format='json') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
90 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
91 |
self.note1 = Note.objects.get(ext_id=response.json()['ext_id']) |
| 126 | 92 |
|
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
93 |
response = self.client.post(url, { |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
94 |
'tc_start': timezone.now(), |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
95 |
'tc_end': timezone.now(), |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
96 |
'plain': "example note 2", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
97 |
'html': "<i>example note 2</i>", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
98 |
'raw': "<i>example note 2</i>", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
99 |
'margin_note': "margin note 2", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
100 |
'categorization': "[]" |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
101 |
}, format='json') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
102 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
103 |
self.note2 = Note.objects.get(ext_id=response.json()['ext_id']) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
104 |
self.client.logout() |
| 126 | 105 |
|
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
106 |
self.client.login(username='test_user2', password='top_secret') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
107 |
url = reverse('notes:notes-session-list', |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
108 |
kwargs={'session_ext_id': self.session2.ext_id}) |
| 126 | 109 |
|
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
110 |
response = self.client.post(url, { |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
111 |
'tc_start': timezone.now(), |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
112 |
'tc_end': timezone.now(), |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
113 |
'plain': "example note 3", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
114 |
'html': "<i>example note 3</i>", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
115 |
'raw': "<i>example note 3</i>", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
116 |
'margin_note': "margin note 3", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
117 |
'categorization': "[]" |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
118 |
}, format='json') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
119 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
120 |
self.note3 = Note.objects.get(ext_id=response.json()['ext_id']) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
121 |
self.client.logout() |
| 126 | 122 |
|
123 |
def test_not_authenticated(self): |
|
124 |
url = reverse('notes:sync-list') |
|
125 |
response = self.client.get(url) |
|
126 |
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) |
|
127 |
||
128 |
def test_simple(self): |
|
129 |
url = reverse('notes:sync-list') |
|
130 |
self.client.login(username='test_user1', password='top_secret') |
|
131 |
response = self.client.get(url) |
|
132 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
133 |
||
134 |
def test_bad_method(self): |
|
135 |
url = reverse('notes:sync-list') |
|
136 |
self.client.login(username='test_user1', password='top_secret') |
|
137 |
response = self.client.post(url) |
|
138 |
self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) |
|
139 |
||
140 |
def test_simple_output(self): |
|
141 |
url = reverse('notes:sync-list') |
|
142 |
self.client.login(username='test_user1', password='top_secret') |
|
143 |
response = self.client.get(url) |
|
144 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
145 |
json_resp = response.json() |
|
146 |
self.assertIn('sessions', json_resp) |
|
147 |
self.assertEqual(1, len(json_resp['sessions'])) |
|
148 |
self.assertEqual('session', json_resp['sessions'][0]['type']) |
|
149 |
self.assertEqual(0, json_resp['sessions'][0]['action']) |
|
150 |
self.assertEqual(str(self.session1.ext_id), json_resp['sessions'][0]['ext_id']) |
|
151 |
||
152 |
self.assertIn('notes', json_resp) |
|
153 |
self.assertEqual(2, len(json_resp['notes'])) |
|
154 |
for sync_def in json_resp['notes']: |
|
155 |
self.assertEqual('note', sync_def['type']) |
|
156 |
self.assertEqual(0, sync_def['action']) |
|
157 |
self.assertIn(sync_def['ext_id'],[str(self.note1.ext_id), str(self.note2.ext_id)]) |
|
158 |
||
159 |
def test_modified_since_empty(self): |
|
160 |
url = reverse('notes:sync-list') |
|
161 |
self.client.login(username='test_user1', password='top_secret') |
|
162 |
||
163 |
nexthour = \ |
|
164 |
datetime.datetime.utcnow().replace(tzinfo=timezone.utc) +\ |
|
165 |
datetime.timedelta(hours=1) |
|
166 |
||
167 |
response = self.client.get( |
|
168 |
url, |
|
169 |
{'modified_since': nexthour.timestamp()}, |
|
170 |
format='json' |
|
171 |
) |
|
172 |
||
173 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
174 |
json_resp = response.json() |
|
175 |
self.assertIn('sessions', json_resp) |
|
176 |
self.assertEqual(0, len(json_resp['sessions'])) |
|
177 |
self.assertIn('notes', json_resp) |
|
178 |
self.assertEqual(0, len(json_resp['notes'])) |
|
179 |
||
180 |
def test_modified_since_notes(self): |
|
181 |
url = reverse('notes:sync-list') |
|
182 |
self.client.login(username='test_user1', password='top_secret') |
|
183 |
||
184 |
nexthour = \ |
|
185 |
datetime.datetime.utcnow().replace(tzinfo=timezone.utc) +\ |
|
186 |
datetime.timedelta(hours=1) |
|
187 |
||
188 |
LogEntry.objects.filter(content_type=ContentType.objects.get_for_model(Note)).update(timestamp=nexthour) |
|
189 |
||
190 |
response = self.client.get( |
|
191 |
url, |
|
192 |
{'modified_since': (nexthour-datetime.timedelta(minutes=30)).timestamp()}, |
|
193 |
format='json' |
|
194 |
) |
|
195 |
||
196 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
197 |
json_resp = response.json() |
|
198 |
self.assertIn('sessions', json_resp) |
|
199 |
self.assertEqual(0, len(json_resp['sessions'])) |
|
200 |
self.assertIn('notes', json_resp) |
|
201 |
self.assertEqual(2, len(json_resp['notes'])) |
|
202 |
for sync_def in json_resp['notes']: |
|
203 |
self.assertEqual('note', sync_def['type']) |
|
204 |
self.assertEqual(0, sync_def['action']) |
|
205 |
self.assertIn(sync_def['ext_id'],[str(self.note1.ext_id), str(self.note2.ext_id)]) |
|
206 |
||
207 |
||
208 |
def test_modified_since_single_update(self): |
|
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
209 |
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:
126
diff
changeset
|
210 |
url = reverse('notes:notes-session-detail', |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
211 |
kwargs={'session_ext_id': self.session1.ext_id, 'ext_id': self.note2.ext_id}) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
212 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
213 |
self.client.put(url, { |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
214 |
'plain': "example note 2 modified", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
215 |
'html': "<i>example note 2 modified</i>", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
216 |
'raw': "<i>example note 2 modified</i>", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
217 |
'margin_note': "margin note 2 modified", |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
218 |
'categorization': "[]" |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
219 |
}, format='json') |
| 126 | 220 |
|
221 |
url = reverse('notes:sync-list') |
|
222 |
||
223 |
nexthour = \ |
|
224 |
datetime.datetime.utcnow().replace(tzinfo=timezone.utc) +\ |
|
225 |
datetime.timedelta(hours=1) |
|
226 |
||
227 |
LogEntry.objects.filter( |
|
228 |
content_type=ContentType.objects.get_for_model(Note), |
|
229 |
object_pk=self.note2.id, |
|
230 |
action=LogEntry.Action.UPDATE |
|
231 |
).update(timestamp=nexthour) |
|
232 |
||
233 |
response = self.client.get( |
|
234 |
url, |
|
235 |
{'modified_since': (nexthour-datetime.timedelta(minutes=30)).timestamp()}, |
|
236 |
format='json' |
|
237 |
) |
|
238 |
||
239 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
240 |
json_resp = response.json() |
|
241 |
self.assertIn('sessions', json_resp) |
|
242 |
self.assertEqual(0, len(json_resp['sessions'])) |
|
243 |
self.assertIn('notes', json_resp) |
|
244 |
self.assertEqual(1, len(json_resp['notes'])) |
|
245 |
sync_def = json_resp['notes'][0] |
|
246 |
self.assertEqual(LogEntry.Action.UPDATE, sync_def['action']) |
|
247 |
||
248 |
def test_note_delete(self): |
|
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
249 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
250 |
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:
126
diff
changeset
|
251 |
url = reverse('notes:notes-session-detail', |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
252 |
kwargs={'session_ext_id': self.session1.ext_id, 'ext_id': self.note2.ext_id}) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
253 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
254 |
self.client.delete(url) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
255 |
self.client.logout() |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
256 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
257 |
|
| 126 | 258 |
url = reverse('notes:sync-list') |
259 |
self.client.login(username='test_user1', password='top_secret') |
|
260 |
response = self.client.get(url) |
|
261 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
262 |
json_resp = response.json() |
|
263 |
self.assertIn('sessions', json_resp) |
|
264 |
self.assertEqual(1, len(json_resp['sessions'])) |
|
265 |
self.assertEqual('session', json_resp['sessions'][0]['type']) |
|
266 |
self.assertEqual(0, json_resp['sessions'][0]['action']) |
|
267 |
self.assertEqual(str(self.session1.ext_id), json_resp['sessions'][0]['ext_id']) |
|
268 |
||
269 |
self.assertIn('notes', json_resp) |
|
270 |
self.assertEqual(1, len(json_resp['notes'])) |
|
271 |
sync_def = json_resp['notes'][0] |
|
272 |
self.assertEqual('note', sync_def['type']) |
|
273 |
self.assertEqual(0, sync_def['action']) |
|
274 |
self.assertEqual(sync_def['ext_id'],str(self.note1.ext_id)) |
|
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
275 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
276 |
def test_note_delete_modified(self): |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
277 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
278 |
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:
126
diff
changeset
|
279 |
url = reverse('notes:notes-session-detail', |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
280 |
kwargs={'session_ext_id': self.session1.ext_id, 'ext_id': self.note2.ext_id}) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
281 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
282 |
self.client.delete(url) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
283 |
self.client.logout() |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
284 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
285 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
286 |
nexthour = \ |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
287 |
datetime.datetime.utcnow().replace(tzinfo=timezone.utc) +\ |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
288 |
datetime.timedelta(hours=1) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
289 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
290 |
LogEntry.objects.filter( |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
291 |
content_type=ContentType.objects.get_for_model(Note), |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
292 |
object_pk=self.note2.id, |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
293 |
action=LogEntry.Action.DELETE |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
294 |
).update(timestamp=nexthour) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
295 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
296 |
url = reverse('notes:sync-list') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
297 |
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:
126
diff
changeset
|
298 |
response = self.client.get(url, {'modified_since': (nexthour-datetime.timedelta(minutes=30)).timestamp()}) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
299 |
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:
126
diff
changeset
|
300 |
json_resp = response.json() |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
301 |
self.assertIn('sessions', json_resp) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
302 |
self.assertEqual(0, len(json_resp['sessions'])) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
303 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
304 |
self.assertIn('notes', json_resp) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
305 |
self.assertEqual(1, len(json_resp['notes'])) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
306 |
sync_def = json_resp['notes'][0] |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
307 |
self.assertEqual('note', sync_def['type']) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
308 |
self.assertEqual(2, sync_def['action']) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
309 |
self.assertEqual(sync_def['ext_id'],str(self.note2.ext_id)) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
310 |