src/notes/tests/api/note.py
author ymh <ymh.work@gmail.com>
Tue, 25 Jul 2017 19:11:26 +0200
changeset 128 34a75bd8d0b9
parent 120 892980a3af09
child 131 adad5563603c
permissions -rw-r--r--
add filter on session and node list to recover specific objects
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
    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="[]",
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
            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
    47
        )
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
        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
    50
            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
    51
            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
    52
            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
    53
            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
    54
        )
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
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
        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
    57
            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
    58
            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
    59
            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
    60
            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
    61
        )
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
85
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
    63
        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
    64
            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
    65
            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
    66
            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
    67
            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
    68
            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
    69
            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
    70
            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
    71
            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
    72
        )
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
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
    74
        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
    75
            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
    76
            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
    77
            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
    78
            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
    79
            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
    80
            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
    81
            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
    82
            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
    83
        )
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
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
    85
        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
    86
            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
    87
            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
    88
            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
    89
            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
    90
            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
    91
            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
    92
            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
    93
            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
    94
        )
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_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
    97
        url = reverse('notes:notes-session-list',
85
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
    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
        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
   100
            '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
   101
            '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
   102
            '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
   103
            '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
   104
            '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
   105
            '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
   106
            '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
   107
        }, 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
   108
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
        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
   110
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
    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
   112
        url = reverse('notes:notes-session-list',
85
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   113
                      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
   114
        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
   115
        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
   116
            '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
   117
            '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
   118
            '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
   119
            '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
   120
            '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
   121
            '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
   122
            '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
   123
        }, 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
   124
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
        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
   126
        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
   127
        self.assertIn('ext_id', json)
85
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   128
        note = Note.objects.get(
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   129
            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
   130
        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
   131
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
    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
   133
        url = reverse('notes:notes-session-list',
85
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   134
                      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
   135
        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
   136
        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
   137
        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
   138
            '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
   139
            '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
   140
            '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
   141
            '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
   142
            '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
   143
            '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
   144
            '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
   145
            '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
   146
        }, 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
   147
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
        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
   149
        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
   150
        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
   151
        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
   152
        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
   153
        self.assertTrue(note)
85
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   154
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   155
    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
   156
        url = reverse('notes:notes-session-detail',
85
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   157
                      kwargs={'session_ext_id': self.session1.ext_id, 'ext_id': self.note1.ext_id})
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   158
        self.client.login(username='test_user1', password='top_secret')
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   159
        response = self.client.put(url, {
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   160
            'plain': "example note 1 modified",
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   161
            'html': "<i>example note modified</i>",
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   162
            'raw': "<i>example note modified</i>",
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   163
            'margin_note': "margin note",
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   164
            'categorization': "[]"
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   165
        }, format='json')
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   166
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   167
        self.assertEqual(response.status_code, status.HTTP_200_OK)
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   168
        json = response.json()
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   169
        self.assertIn('plain', json)
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   170
        self.assertEqual("example note 1 modified", json['plain'])
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   171
        note = Note.objects.get(
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   172
            ext_id=json['ext_id'], session__id=self.session1.id)
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   173
        self.assertTrue(note)
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   174
        self.assertEqual("example note 1 modified", note.plain)
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   175
128
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 120
diff changeset
   176
    # TODO: Fail if a tc_start, tc_end, session, ext_id updated, created are provided on update ?
85
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   177
    # 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
   178
    #     url = reverse('notes:notes-session-detail',
85
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   179
    #                   kwargs={'session_ext_id': self.session1.ext_id, 'ext_id': self.note1.ext_id})
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   180
    #     self.client.login(username='test_user1', password='top_secret')
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   181
    #     response = self.client.put(url, {
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   182
    #         'tc_start': timezone.now(),
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   183
    #         'tc_end': timezone.now(),
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   184
    #         'plain': "example note 1 modified",
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   185
    #         'html': "<i>example note modified</i>",
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   186
    #         'raw': "<i>example note modified</i>",
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   187
    #         'margin_note': "margin note",
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   188
    #         'categorization': "[]"
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   189
    #     }, format='json')
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   190
e17899ced2b8 add a test for updating nodes
ymh <ymh.work@gmail.com>
parents: 74
diff changeset
   191
    #     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
   192
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
   193
    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
   194
        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
   195
        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
   196
        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
   197
        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
   198
8ff8e2aee0f9 add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents: 85
diff changeset
   199
        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
   200
        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
   201
        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
   202
        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
   203
8ff8e2aee0f9 add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents: 85
diff changeset
   204
        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
   205
            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
   206
                             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
   207
            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
   208
            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
   209
            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
   210
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 120
diff changeset
   211
    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
   212
        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
   213
        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
   214
        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
   215
            [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
   216
        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
   217
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 120
diff changeset
   218
        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
   219
        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
   220
        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
   221
        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
   222
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 120
diff changeset
   223
        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
   224
        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
   225
        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
   226
        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
   227
        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
   228
        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
   229
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 120
diff changeset
   230
    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
   231
        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
   232
        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
   233
        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
   234
            [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
   235
        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
   236
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 120
diff changeset
   237
        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
   238
        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
   239
        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
   240
        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
   241
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 120
diff changeset
   242
        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
   243
            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
   244
            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
   245
            self.assertIn('plain', note_json)
892980a3af09 for notes api, the end point list all properties.
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   246
            self.assertIn('html', note_json)
892980a3af09 for notes api, the end point list all properties.
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   247
            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
   248
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
   249
128
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 120
diff changeset
   250
    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
   251
        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
   252
        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
   253
        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
   254
            [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
   255
        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
   256
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 120
diff changeset
   257
        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
   258
        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
   259
        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
   260
        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
   261
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 120
diff changeset
   262
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
   263
    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
   264
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
   265
        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
   266
            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
   267
            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
   268
        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
   269
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
        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
   271
        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
   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
        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
   274
            url,
128
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 120
diff changeset
   275
            {'modified_since': (
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 120
diff changeset
   276
                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
   277
            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
   278
        )
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
   279
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
        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
   281
        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
   282
        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
   283
        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
   284
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.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
   286
        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
   287
                         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
   288
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
   289
    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
   290
        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
   291
                      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
   292
        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
   293
        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
   294
        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
   295
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
        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
   297
        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
   298
        self.assertEqual('example note 1.1', json_resp.get('plain'))