add a test for updating nodes
authorymh <ymh.work@gmail.com>
Fri, 23 Jun 2017 18:20:50 +0200
changeset 85 e17899ced2b8
parent 84 bf35a7737f94
child 86 fa8ef84a1780
add a test for updating nodes
src/notes/tests/api/note.py
--- a/src/notes/tests/api/note.py	Fri Jun 23 18:01:40 2017 +0200
+++ b/src/notes/tests/api/note.py	Fri Jun 23 18:20:50 2017 +0200
@@ -14,6 +14,7 @@
 
 logger = logging.getLogger(__name__)
 
+
 class NoteApiTests(APITransactionTestCase):
 
     def setUp(self):
@@ -55,7 +56,7 @@
             owner=user3
         )
 
-        Note.objects.create(
+        self.note1 = Note.objects.create(
             tc_start=timezone.now(),
             tc_end=timezone.now(),
             session=self.session1,
@@ -77,9 +78,9 @@
             categorization="[]"
         )
 
-
     def test_create_note_no_user(self):
-        url = reverse('notes:notes-list', kwargs={'session_ext_id': self.session1.ext_id})
+        url = reverse('notes:notes-list',
+                      kwargs={'session_ext_id': self.session1.ext_id})
         response = self.client.post(url, {
             'tc_start': timezone.now(),
             'tc_end': timezone.now(),
@@ -92,9 +93,9 @@
 
         self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
 
-
     def test_create_note(self):
-        url = reverse('notes:notes-list', kwargs={'session_ext_id': self.session1.ext_id})
+        url = reverse('notes:notes-list',
+                      kwargs={'session_ext_id': self.session1.ext_id})
         self.client.login(username='test_user1', password='top_secret')
         response = self.client.post(url, {
             'tc_start': timezone.now(),
@@ -109,11 +110,13 @@
         self.assertEqual(response.status_code, status.HTTP_201_CREATED)
         json = response.json()
         self.assertIn('ext_id', json)
-        note = Note.objects.get(ext_id=json['ext_id'], session__id=self.session1.id)
+        note = Note.objects.get(
+            ext_id=json['ext_id'], session__id=self.session1.id)
         self.assertTrue(note)
 
     def test_create_note_with_ext_id(self):
-        url = reverse('notes:notes-list', kwargs={'session_ext_id': self.session1.ext_id})
+        url = reverse('notes:notes-list',
+                      kwargs={'session_ext_id': self.session1.ext_id})
         self.client.login(username='test_user1', password='top_secret')
         ext_id = str(uuid4())
         response = self.client.post(url, {
@@ -133,3 +136,41 @@
         self.assertEqual(json['ext_id'], ext_id)
         note = Note.objects.get(ext_id=ext_id)
         self.assertTrue(note)
+
+    def test_update_note(self):
+        url = reverse('notes:notes-detail',
+                      kwargs={'session_ext_id': self.session1.ext_id, 'ext_id': self.note1.ext_id})
+        self.client.login(username='test_user1', password='top_secret')
+        response = self.client.put(url, {
+            'plain': "example note 1 modified",
+            'html': "<i>example note modified</i>",
+            'raw': "<i>example note modified</i>",
+            'margin_note': "margin note",
+            'categorization': "[]"
+        }, format='json')
+
+        self.assertEqual(response.status_code, status.HTTP_200_OK)
+        json = response.json()
+        self.assertIn('plain', json)
+        self.assertEqual("example note 1 modified", json['plain'])
+        note = Note.objects.get(
+            ext_id=json['ext_id'], session__id=self.session1.id)
+        self.assertTrue(note)
+        self.assertEqual("example note 1 modified", note.plain)
+
+    #TODO: Fail if a tc_start, tc_end, session, ext_id updated, created are provided on update ?
+    # def test_update_note_tc_start(self):
+    #     url = reverse('notes:notes-detail',
+    #                   kwargs={'session_ext_id': self.session1.ext_id, 'ext_id': self.note1.ext_id})
+    #     self.client.login(username='test_user1', password='top_secret')
+    #     response = self.client.put(url, {
+    #         'tc_start': timezone.now(),
+    #         'tc_end': timezone.now(),
+    #         'plain': "example note 1 modified",
+    #         'html': "<i>example note modified</i>",
+    #         'raw': "<i>example note modified</i>",
+    #         'margin_note': "margin note",
+    #         'categorization': "[]"
+    #     }, format='json')
+
+    #     self.assertEqual(response.status_code, status.HTTP_200_OK)