| author | ymh <ymh.work@gmail.com> |
| Fri, 23 Jun 2017 18:20:50 +0200 | |
| changeset 85 | e17899ced2b8 |
| parent 74 | 043477fd5c5c |
| child 119 | 8ff8e2aee0f9 |
| 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 |
""" |
|
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
|
4 |
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
|
5 |
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
|
6 |
|
|
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 |
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
|
8 |
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
|
9 |
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
|
10 |
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
|
11 |
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
|
12 |
|
|
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 |
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
|
14 |
|
|
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 |
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
|
16 |
|
| 85 | 17 |
|
|
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
|
18 |
class NoteApiTests(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
|
19 |
|
|
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
|
20 |
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
|
21 |
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
|
22 |
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
|
23 |
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
|
24 |
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
|
25 |
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
|
26 |
) |
|
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 |
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
|
28 |
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
|
29 |
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
|
30 |
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
|
31 |
) |
|
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 |
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
|
33 |
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
|
34 |
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
|
35 |
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
|
36 |
) |
|
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 |
|
|
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 |
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
|
39 |
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
|
40 |
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
|
41 |
protocol="[]", |
|
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 |
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
|
43 |
) |
|
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 |
|
|
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 |
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
|
46 |
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
|
47 |
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
|
48 |
protocol="[]", |
|
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 |
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
|
50 |
) |
|
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 |
|
|
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 |
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
|
53 |
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
|
54 |
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
|
55 |
protocol="[]", |
|
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 |
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
|
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 |
|
| 85 | 59 |
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
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
) |
|
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 |
|
|
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 |
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
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
) |
|
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
|
80 |
|
|
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
|
81 |
def test_create_note_no_user(self): |
| 85 | 82 |
url = reverse('notes:notes-list', |
83 |
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
|
84 |
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
|
85 |
'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
|
86 |
'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
|
87 |
'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
|
88 |
'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
|
89 |
'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
|
90 |
'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
|
91 |
'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
|
92 |
}, 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
|
93 |
|
|
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 |
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
|
95 |
|
|
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 |
def test_create_note(self): |
| 85 | 97 |
url = reverse('notes:notes-list', |
98 |
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
|
99 |
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
|
100 |
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
|
101 |
'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
|
102 |
'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
|
103 |
'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
|
104 |
'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
|
105 |
'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
|
106 |
'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
|
107 |
'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
|
108 |
}, 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
|
109 |
|
|
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 |
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
|
111 |
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
|
112 |
self.assertIn('ext_id', json) |
| 85 | 113 |
note = Note.objects.get( |
114 |
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
|
115 |
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
|
116 |
|
|
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 |
def test_create_note_with_ext_id(self): |
| 85 | 118 |
url = reverse('notes:notes-list', |
119 |
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
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
'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
|
124 |
'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
|
125 |
'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
|
126 |
'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
|
127 |
'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
|
128 |
'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
|
129 |
'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
|
130 |
'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
|
131 |
}, 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
|
132 |
|
|
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.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
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
self.assertTrue(note) |
| 85 | 139 |
|
140 |
def test_update_note(self): |
|
141 |
url = reverse('notes:notes-detail', |
|
142 |
kwargs={'session_ext_id': self.session1.ext_id, 'ext_id': self.note1.ext_id}) |
|
143 |
self.client.login(username='test_user1', password='top_secret') |
|
144 |
response = self.client.put(url, { |
|
145 |
'plain': "example note 1 modified", |
|
146 |
'html': "<i>example note modified</i>", |
|
147 |
'raw': "<i>example note modified</i>", |
|
148 |
'margin_note': "margin note", |
|
149 |
'categorization': "[]" |
|
150 |
}, format='json') |
|
151 |
||
152 |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
153 |
json = response.json() |
|
154 |
self.assertIn('plain', json) |
|
155 |
self.assertEqual("example note 1 modified", json['plain']) |
|
156 |
note = Note.objects.get( |
|
157 |
ext_id=json['ext_id'], session__id=self.session1.id) |
|
158 |
self.assertTrue(note) |
|
159 |
self.assertEqual("example note 1 modified", note.plain) |
|
160 |
||
161 |
#TODO: Fail if a tc_start, tc_end, session, ext_id updated, created are provided on update ? |
|
162 |
# def test_update_note_tc_start(self): |
|
163 |
# url = reverse('notes:notes-detail', |
|
164 |
# kwargs={'session_ext_id': self.session1.ext_id, 'ext_id': self.note1.ext_id}) |
|
165 |
# self.client.login(username='test_user1', password='top_secret') |
|
166 |
# response = self.client.put(url, { |
|
167 |
# 'tc_start': timezone.now(), |
|
168 |
# 'tc_end': timezone.now(), |
|
169 |
# 'plain': "example note 1 modified", |
|
170 |
# 'html': "<i>example note modified</i>", |
|
171 |
# 'raw': "<i>example note modified</i>", |
|
172 |
# 'margin_note': "margin note", |
|
173 |
# 'categorization': "[]" |
|
174 |
# }, format='json') |
|
175 |
||
176 |
# self.assertEqual(response.status_code, status.HTTP_200_OK) |