| author | ymh <ymh.work@gmail.com> |
| Mon, 31 Jul 2017 23:18:38 +0200 | |
| changeset 131 | adad5563603c |
| parent 128 | 34a75bd8d0b9 |
| permissions | -rw-r--r-- |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
""" |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
Tests the core api for sessions |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
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:
85
diff
changeset
|
4 |
import datetime |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
import logging |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
from uuid import uuid4 |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
|
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
from django.contrib.auth import get_user_model |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
from django.urls import reverse |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
from django.utils import timezone |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
from rest_framework import status |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
from rest_framework.test import APITransactionTestCase |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
|
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
from notes.models import Session, Note |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
|
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
16 |
logger = logging.getLogger(__name__) |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
17 |
|
| 85 | 18 |
|
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
class NoteApiTests(APITransactionTestCase): |
|
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:
85
diff
changeset
|
20 |
''' |
|
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:
85
diff
changeset
|
21 |
Test Note api |
|
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:
85
diff
changeset
|
22 |
''' |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
|
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
def setUp(self): |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
25 |
User = get_user_model() |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
26 |
user1 = User.objects.create_user( |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
username='test_user1', |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
28 |
email='test_user@emial.com', |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
29 |
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:
diff
changeset
|
30 |
) |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
user2 = User.objects.create_user( |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
32 |
username='test_user2', |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
email='test_user@emial.com', |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
34 |
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:
diff
changeset
|
35 |
) |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
36 |
user3 = User.objects.create_user( |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
37 |
username='test_user3', |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
38 |
email='test_user@emial.com', |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
39 |
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:
diff
changeset
|
40 |
) |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
41 |
|
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
self.session1 = Session.objects.create( |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
43 |
title="a new session 1", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
44 |
description="Description 1", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
45 |
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
|
46 |
group=user1.profile.default_group, |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
47 |
owner=user1 |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
48 |
) |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
49 |
|
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
50 |
self.session2 = Session.objects.create( |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
51 |
title="a new session 2", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
52 |
description="Description 2", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
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=user2.profile.default_group, |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
55 |
owner=user2 |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
56 |
) |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
57 |
|
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
58 |
Session.objects.create( |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
59 |
title="a new session 3", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
60 |
description="Description 3", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
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=user3.profile.default_group, |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
63 |
owner=user3 |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
64 |
) |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
65 |
|
| 85 | 66 |
self.note1 = Note.objects.create( |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
67 |
tc_start=timezone.now(), |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
68 |
tc_end=timezone.now(), |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
69 |
session=self.session1, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
70 |
plain="example note 1", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
71 |
html="<i>example note 1</i>", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
72 |
raw="<i>example note 1</i>", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
73 |
margin_note="margin note 1", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
74 |
categorization="[]" |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
75 |
) |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
76 |
|
|
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:
85
diff
changeset
|
77 |
self.note2 = Note.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:
85
diff
changeset
|
78 |
tc_start=timezone.now(), |
|
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:
85
diff
changeset
|
79 |
tc_end=timezone.now(), |
|
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:
85
diff
changeset
|
80 |
session=self.session1, |
|
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:
85
diff
changeset
|
81 |
plain="example note 1.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:
85
diff
changeset
|
82 |
html="<i>example note 1,1</i>", |
|
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:
85
diff
changeset
|
83 |
raw="<i>example note 1.1</i>", |
|
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:
85
diff
changeset
|
84 |
margin_note="margin note 1.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:
85
diff
changeset
|
85 |
categorization="[]" |
|
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:
85
diff
changeset
|
86 |
) |
|
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:
85
diff
changeset
|
87 |
|
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
88 |
Note.objects.create( |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
89 |
tc_start=timezone.now(), |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
90 |
tc_end=timezone.now(), |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
91 |
session=self.session2, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
92 |
plain="example note 2", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
93 |
html="<i>example note</i>", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
94 |
raw="<i>example note</i>", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
95 |
margin_note="margin note", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
96 |
categorization="[]" |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
97 |
) |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
98 |
|
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
99 |
def test_create_note_no_user(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:
85
diff
changeset
|
100 |
url = reverse('notes:notes-session-list', |
| 85 | 101 |
kwargs={'session_ext_id': self.session1.ext_id}) |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
102 |
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:
diff
changeset
|
103 |
'tc_start': timezone.now(), |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
104 |
'tc_end': timezone.now(), |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
105 |
'plain': "example note 2", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
106 |
'html': "<i>example note</i>", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
107 |
'raw': "<i>example note</i>", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
108 |
'margin_note': "margin note", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
109 |
'categorization': "[]" |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
110 |
}, 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:
diff
changeset
|
111 |
|
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
112 |
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
113 |
|
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
114 |
def test_create_note(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:
85
diff
changeset
|
115 |
url = reverse('notes:notes-session-list', |
| 85 | 116 |
kwargs={'session_ext_id': self.session1.ext_id}) |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
117 |
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:
diff
changeset
|
118 |
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:
diff
changeset
|
119 |
'tc_start': timezone.now(), |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
120 |
'tc_end': timezone.now(), |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
121 |
'plain': "example note 2", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
122 |
'html': "<i>example note</i>", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
123 |
'raw': "<i>example note</i>", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
124 |
'margin_note': "margin note", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
125 |
'categorization': "[]" |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
126 |
}, 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:
diff
changeset
|
127 |
|
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
128 |
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:
diff
changeset
|
129 |
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:
diff
changeset
|
130 |
self.assertIn('ext_id', json) |
| 85 | 131 |
note = Note.objects.get( |
132 |
ext_id=json['ext_id'], session__id=self.session1.id) |
|
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
133 |
self.assertTrue(note) |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
134 |
|
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
135 |
def test_create_note_with_ext_id(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:
85
diff
changeset
|
136 |
url = reverse('notes:notes-session-list', |
| 85 | 137 |
kwargs={'session_ext_id': self.session1.ext_id}) |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
138 |
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:
diff
changeset
|
139 |
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:
diff
changeset
|
140 |
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:
diff
changeset
|
141 |
'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:
diff
changeset
|
142 |
'tc_start': timezone.now(), |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
143 |
'tc_end': timezone.now(), |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
144 |
'plain': "example note 2", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
145 |
'html': "<i>example note</i>", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
146 |
'raw': "<i>example note</i>", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
147 |
'margin_note': "margin note", |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
148 |
'categorization': "[]" |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
149 |
}, 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:
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:
diff
changeset
|
151 |
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:
diff
changeset
|
152 |
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:
diff
changeset
|
153 |
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:
diff
changeset
|
154 |
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:
diff
changeset
|
155 |
note = Note.objects.get(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:
diff
changeset
|
156 |
self.assertTrue(note) |
| 85 | 157 |
|
158 |
def test_update_note(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:
85
diff
changeset
|
159 |
url = reverse('notes:notes-session-detail', |
| 85 | 160 |
kwargs={'session_ext_id': self.session1.ext_id, 'ext_id': self.note1.ext_id}) |
161 |
self.client.login(username='test_user1', password='top_secret') |
|
162 |
response = self.client.put(url, { |
|
163 |
'plain': "example note 1 modified", |
|
164 |
'html': "<i>example note modified</i>", |
|
165 |
'raw': "<i>example note modified</i>", |
|
166 |
'margin_note': "margin note", |
|
167 |
'categorization': "[]" |
|
168 |
}, format='json') |
|
169 |
||
170 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
171 |
json = response.json() |
|
172 |
self.assertIn('plain', json) |
|
173 |
self.assertEqual("example note 1 modified", json['plain']) |
|
174 |
note = Note.objects.get( |
|
175 |
ext_id=json['ext_id'], session__id=self.session1.id) |
|
176 |
self.assertTrue(note) |
|
177 |
self.assertEqual("example note 1 modified", note.plain) |
|
178 |
||
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
179 |
# TODO: Fail if a tc_start, tc_end, session, ext_id updated, created are provided on update ? |
| 85 | 180 |
# def test_update_note_tc_start(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:
85
diff
changeset
|
181 |
# url = reverse('notes:notes-session-detail', |
| 85 | 182 |
# kwargs={'session_ext_id': self.session1.ext_id, 'ext_id': self.note1.ext_id}) |
183 |
# self.client.login(username='test_user1', password='top_secret') |
|
184 |
# response = self.client.put(url, { |
|
185 |
# 'tc_start': timezone.now(), |
|
186 |
# 'tc_end': timezone.now(), |
|
187 |
# 'plain': "example note 1 modified", |
|
188 |
# 'html': "<i>example note modified</i>", |
|
189 |
# 'raw': "<i>example note modified</i>", |
|
190 |
# 'margin_note': "margin note", |
|
191 |
# 'categorization': "[]" |
|
192 |
# }, format='json') |
|
193 |
||
194 |
# self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
|
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:
85
diff
changeset
|
195 |
|
|
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:
85
diff
changeset
|
196 |
def test_root_note_list(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:
85
diff
changeset
|
197 |
url = reverse('notes:note-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:
85
diff
changeset
|
198 |
self.client.login(username='test_user1', 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:
85
diff
changeset
|
199 |
response = self.client.get(url, 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:
85
diff
changeset
|
200 |
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:
85
diff
changeset
|
201 |
|
|
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:
85
diff
changeset
|
202 |
json_resp = 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:
85
diff
changeset
|
203 |
self.assertIn('results', json_resp) |
|
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:
85
diff
changeset
|
204 |
self.assertEqual(2, json_resp['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:
85
diff
changeset
|
205 |
self.assertEqual(2, len(json_resp['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:
85
diff
changeset
|
206 |
|
|
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:
85
diff
changeset
|
207 |
for note_json in json_resp['results']: |
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
208 |
self.assertEqual(str(self.session1.ext_id), |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
209 |
note_json.get('session')) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
210 |
self.assertIn('plain', note_json) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
211 |
self.assertIn('html', note_json) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
212 |
self.assertIn('raw', note_json) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
213 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
214 |
def test_root_note_list_filter(self): |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
215 |
url = reverse('notes:note-list') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
216 |
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:
120
diff
changeset
|
217 |
response = self.client.get(url, {'ext_id__in': ",".join( |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
218 |
[str(self.note1.ext_id), str(uuid4())])}, format='json') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
219 |
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:
120
diff
changeset
|
220 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
221 |
json_resp = response.json() |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
222 |
self.assertIn('results', json_resp) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
223 |
self.assertEqual(1, json_resp['count']) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
224 |
self.assertEqual(1, len(json_resp['results'])) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
225 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
226 |
note_json = json_resp['results'][0] |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
227 |
self.assertEqual(str(self.note1.ext_id), note_json.get('ext_id')) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
228 |
self.assertEqual(str(self.session1.ext_id), note_json.get('session')) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
229 |
self.assertIn('plain', note_json) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
230 |
self.assertIn('html', note_json) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
231 |
self.assertIn('raw', note_json) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
232 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
233 |
def test_root_note_list_filter_both(self): |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
234 |
url = reverse('notes:note-list') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
235 |
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:
120
diff
changeset
|
236 |
response = self.client.get(url, {'ext_id__in': ",".join( |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
237 |
[str(self.note1.ext_id), str(self.note2.ext_id)])}, format='json') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
238 |
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:
120
diff
changeset
|
239 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
240 |
json_resp = response.json() |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
241 |
self.assertIn('results', json_resp) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
242 |
self.assertEqual(2, json_resp['count']) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
243 |
self.assertEqual(2, len(json_resp['results'])) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
244 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
245 |
for note_json in json_resp['results']: |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
246 |
self.assertIn(note_json.get('ext_id'), [str(self.note1.ext_id), str(self.note2.ext_id)]) |
|
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:
85
diff
changeset
|
247 |
self.assertEqual(str(self.session1.ext_id), note_json.get('session')) |
|
120
892980a3af09
for notes api, the end point list all properties.
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
248 |
self.assertIn('plain', note_json) |
|
892980a3af09
for notes api, the end point list all properties.
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
249 |
self.assertIn('html', note_json) |
|
892980a3af09
for notes api, the end point list all properties.
ymh <ymh.work@gmail.com>
parents:
119
diff
changeset
|
250 |
self.assertIn('raw', note_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:
85
diff
changeset
|
251 |
|
|
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:
85
diff
changeset
|
252 |
|
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
253 |
def test_root_note_list_bad_filter(self): |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
254 |
url = reverse('notes:note-list') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
255 |
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:
120
diff
changeset
|
256 |
response = self.client.get(url, {'ext_id__in': ",".join( |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
257 |
[str(self.note1.ext_id), "foo"])}, format='json') |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
258 |
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:
120
diff
changeset
|
259 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
260 |
json_resp = response.json() |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
261 |
self.assertIn('results', json_resp) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
262 |
self.assertEqual(0, json_resp['count']) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
263 |
self.assertEqual(0, len(json_resp['results'])) |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
264 |
|
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
265 |
|
|
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:
85
diff
changeset
|
266 |
def test_root_note_list_modified(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:
85
diff
changeset
|
267 |
|
|
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:
85
diff
changeset
|
268 |
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:
85
diff
changeset
|
269 |
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:
85
diff
changeset
|
270 |
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:
85
diff
changeset
|
271 |
Note.objects.filter(pk=self.note2.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:
85
diff
changeset
|
272 |
|
|
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:
85
diff
changeset
|
273 |
url = reverse('notes:note-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:
85
diff
changeset
|
274 |
self.client.login(username='test_user1', 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:
85
diff
changeset
|
275 |
|
|
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:
85
diff
changeset
|
276 |
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:
85
diff
changeset
|
277 |
url, |
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
278 |
{'modified_since': ( |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
279 |
nexthour - datetime.timedelta(minutes=30)).timestamp()}, |
|
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:
85
diff
changeset
|
280 |
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:
85
diff
changeset
|
281 |
) |
|
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:
85
diff
changeset
|
282 |
|
|
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:
85
diff
changeset
|
283 |
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:
85
diff
changeset
|
284 |
json_resp = 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:
85
diff
changeset
|
285 |
self.assertIn('results', json_resp) |
|
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:
85
diff
changeset
|
286 |
self.assertEqual(1, json_resp['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:
85
diff
changeset
|
287 |
|
|
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:
85
diff
changeset
|
288 |
self.assertEqual(len(json_resp['results']), 1, "must have one note") |
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
289 |
self.assertEqual(str(self.session1.ext_id), |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
290 |
json_resp['results'][0].get('session')) |
|
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:
85
diff
changeset
|
291 |
|
|
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:
85
diff
changeset
|
292 |
def test_root_note_detail(self): |
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
293 |
url = reverse('notes:note-detail', |
|
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
120
diff
changeset
|
294 |
kwargs={'ext_id': self.note2.ext_id}) |
|
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:
85
diff
changeset
|
295 |
self.client.login(username='test_user1', 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:
85
diff
changeset
|
296 |
response = self.client.get(url, 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:
85
diff
changeset
|
297 |
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:
85
diff
changeset
|
298 |
|
|
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:
85
diff
changeset
|
299 |
json_resp = 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:
85
diff
changeset
|
300 |
self.assertEqual(str(self.session1.ext_id), json_resp.get('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:
85
diff
changeset
|
301 |
self.assertEqual('example note 1.1', json_resp.get('plain')) |