src/notes/tests/api/session.py
author ymh <ymh.work@gmail.com>
Wed, 28 Nov 2018 15:45:37 +0100
changeset 180 62bffc051e1c
parent 142 56850f5c73f6
permissions -rw-r--r--
Add first version of deploy scripts
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
"""
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
Tests the core api for sessions
63be3ce389f7 improve api
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: 74
diff changeset
     4
import datetime
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
import logging
142
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
     6
from unittest import skip
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 31
diff changeset
     7
from uuid import uuid4
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
from django.contrib.auth import get_user_model
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
    10
from django.contrib.auth.models import Group
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
from django.urls import reverse
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
from django.utils import timezone
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
from rest_framework import status
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
from rest_framework.test import APITransactionTestCase
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
142
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
    16
from notes import constants
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
    17
from notes.models import GroupProfile, Note, Session
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
logger = logging.getLogger(__name__)
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
class SessionApiTests(APITransactionTestCase):
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    def setUp(self):
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
        User = get_user_model()
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
    25
        self.user1 = User.objects.create_user(
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
            username='test_user1',
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
            email='test_user@emial.com',
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
            password='top_secret'
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
        )
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
    30
        self.user2 = User.objects.create_user(
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
            username='test_user2',
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
            email='test_user@emial.com',
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
            password='top_secret'
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
        )
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
        user3 = User.objects.create_user(
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
            username='test_user3',
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
            email='test_user@emial.com',
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
            password='top_secret'
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
        )
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
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
    41
        self.group1 = Group(name='group1')
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
    42
        self.group1.save()
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
    43
        self.group1.user_set.add(self.user1)
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
    44
        self.group1.user_set.add(self.user2)
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
    45
        self.group1.profile.owner = self.user1
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
        self.group1.profile.description = "This is the group 1"
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
    47
        self.group1.profile.save()
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
    48
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
    49
        self.user2.profile.default_group = self.group1
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
    50
        self.user2.profile.save()
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
    51
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
        self.session1 = Session.objects.create(
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
            title="a new session 1",
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
            description="Description 1",
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
    55
            group=self.user1.profile.default_group,
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
    56
            owner=self.user1
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
        )
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
        self.session2 = Session.objects.create(
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
            title="a new session 2",
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
            description="Description 2",
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=self.user2.profile.default_group,
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
    63
            owner=self.user2
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
        )
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
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: 74
diff changeset
    66
        self.session3 = Session.objects.create(
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
            title="a new session 3",
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
            description="Description 3",
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
    69
            group=user3.profile.default_group,
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
            owner=user3
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
        )
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
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: 74
diff changeset
    73
        self.session4 = Session.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: 74
diff changeset
    74
            title="a new session 4",
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: 74
diff changeset
    75
            description="Description 4",
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
    76
            group=user3.profile.default_group,
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: 74
diff changeset
    77
            owner=user3
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: 74
diff changeset
    78
        )
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: 74
diff changeset
    79
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
        Note.objects.create(
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
            tc_start=timezone.now(),
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
            tc_end=timezone.now(),
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
            session=self.session1,
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
            plain="example note 1",
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
            html="<i>example note 1</i>",
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
            raw="<i>example note 1</i>",
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
            margin_note="margin note 1",
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
            categorization="[]"
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
        )
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
        Note.objects.create(
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
            tc_start=timezone.now(),
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
            tc_end=timezone.now(),
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
            session=self.session2,
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
            plain="example note 2",
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
            html="<i>example note</i>",
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
            raw="<i>example note</i>",
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
            margin_note="margin note",
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
            categorization="[]"
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
        )
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
    def test_list_session_no_user(self):
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 31
diff changeset
   104
        url = reverse('notes:session-list')
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
        response = self.client.post(url)
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 31
diff changeset
   106
        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
    def test_list_session(self):
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 31
diff changeset
   110
        url = reverse('notes:session-list')
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
        self.client.login(username='test_user1', password='top_secret')
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
        response = self.client.get(url)
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
        self.assertEqual(response.status_code, status.HTTP_200_OK)
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
        json = response.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: 74
diff changeset
   115
        self.assertIn('results', json, "must have 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: 74
diff changeset
   116
        self.assertIn('count', json, "must have 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: 74
diff changeset
   117
        self.assertEqual(json['count'], 1, "must have one 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: 74
diff changeset
   118
        self.assertEqual(len(json['results']), 1, "must have one 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: 74
diff changeset
   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: 74
diff changeset
   120
        for session in json['results']:
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
            self.assertEqual(session['owner'], 'test_user1')
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
128
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   124
    def test_list_session_filter(self):
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   125
        url = reverse('notes:session-list')
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   126
        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: 119
diff changeset
   127
        response = self.client.get(url, {"ext_id__in": ",".join([str(self.session1.ext_id)])})
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   128
        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: 119
diff changeset
   129
        json = response.json()
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   130
        self.assertIn('results', json, "must have results")
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   131
        self.assertIn('count', json, "must have count")
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   132
        self.assertEqual(json['count'], 1, "must have one session")
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   133
        self.assertEqual(len(json['results']), 1, "must have one session")
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   134
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   135
        for session in json['results']:
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   136
            self.assertEqual(session['owner'], 'test_user1')
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   137
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   138
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   139
    def test_list_session_filter_bad(self):
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   140
        url = reverse('notes:session-list')
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   141
        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: 119
diff changeset
   142
        response = self.client.get(url, {"ext_id__in": ",".join([str(uuid4())])})
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   143
        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: 119
diff changeset
   144
        json = response.json()
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   145
        self.assertIn('results', json, "must have results")
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   146
        self.assertIn('count', json, "must have count")
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   147
        self.assertEqual(json['count'], 0, "must have no session")
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   148
        self.assertEqual(len(json['results']), 0, "must have no session")
34a75bd8d0b9 add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents: 119
diff changeset
   149
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
    def test_create_session_no_user(self):
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 31
diff changeset
   151
        url = reverse('notes:session-list')
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
        response = self.client.post(url, {
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
            'title': "a new session",
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
            'description': "description of the session",
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
            'protocol': "[]"
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
        }, format='json')
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 31
diff changeset
   158
        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
    def test_create_session(self):
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 31
diff changeset
   162
        url = reverse('notes:session-list')
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
        self.client.login(username='test_user1', password='top_secret')
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
        response = self.client.post(url, {
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
            'title': "a new session",
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
            'description': "description of the session",
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
   167
            'group': 'group1'
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
        }, format='json')
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
142
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   170
        self.assertEqual(response.status_code, status.HTTP_201_CREATED, "error msg: %r" % response.content)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   171
        json = response.json()
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   172
        self.assertIn('ext_id', json)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   173
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   174
        session = Session.objects.get(ext_id=json['ext_id'])
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   175
        self.assertIsNotNone(session)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   176
        self.assertEqual(self.group1, session.group)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   177
        self.assertEqual(self.group1.profile.protocol, session.protocol)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   178
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   179
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   180
    def test_create_session_protocol(self):
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   181
        url = reverse('notes:session-list')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   182
        self.client.login(username='test_user1', password='top_secret')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   183
        response = self.client.post(url, {
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   184
            'title': "a new session",
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   185
            'description': "description of the session",
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   186
            'group': 'group1',
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   187
            'protocol': {}
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   188
        }, format='json')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   189
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   190
        self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.json())
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   191
        json = response.json()
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   192
        self.assertIn('ext_id', json)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   193
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   194
        session = Session.objects.get(ext_id=json['ext_id'])
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   195
        self.assertIsNotNone(session)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   196
        self.assertEqual(self.group1, session.group)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   197
        self.assertNotEqual(self.group1.profile.protocol, session.protocol)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   198
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   199
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   200
    def test_create_session_protocol_as_str(self):
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   201
        url = reverse('notes:session-list')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   202
        self.client.login(username='test_user1', password='top_secret')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   203
        group1 = Group.objects.get(id=self.group1.id)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   204
        response = self.client.post(url, {
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   205
            'title': "a new session",
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   206
            'description': "description of the session",
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   207
            'group': 'group1',
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   208
            'protocol': group1.profile.protocol
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   209
        }, format='json')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   210
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   211
        self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.json())
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
        json = response.json()
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
        self.assertIn('ext_id', json)
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
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
   215
        session = Session.objects.get(ext_id=json['ext_id'])
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
   216
        self.assertIsNotNone(session)
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
   217
        self.assertEqual(self.group1, session.group)
142
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   218
        self.assertEqual(self.group1.profile.protocol, session.protocol)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   219
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   220
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   221
    def test_create_session_protocol_as_str_unknown(self):
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   222
        url = reverse('notes:session-list')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   223
        self.client.login(username='test_user1', password='top_secret')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   224
        group1 = Group.objects.get(id=self.group1.id)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   225
        response = self.client.post(url, {
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   226
            'title': "a new session",
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   227
            'description': "description of the session",
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   228
            'group': 'group1',
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   229
            'protocol': constants.PROTOCOL_URN_PREFIX + str(uuid4()) + ".1"
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   230
        }, format='json')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   231
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   232
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.json())
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   233
        json = response.json()
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   234
        self.assertIn('protocol', json)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   235
        self.assertIn('Incorrect protocol', json['protocol'][0])
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   236
        self.assertIn('does not exists', json['protocol'][0])
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   237
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   238
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   239
    def test_create_session_protocol_as_str_bad(self):
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   240
        url = reverse('notes:session-list')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   241
        self.client.login(username='test_user1', password='top_secret')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   242
        group1 = Group.objects.get(id=self.group1.id)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   243
        response = self.client.post(url, {
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   244
            'title': "a new session",
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   245
            'description': "description of the session",
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   246
            'group': 'group1',
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   247
            'protocol': constants.PROTOCOL_URN_PREFIX + "foo"
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   248
        }, format='json')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   249
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   250
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.json())
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   251
        json = response.json()
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   252
        self.assertIn('protocol', json)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   253
        self.assertEqual('Incorrect format. Expected `urn:protocol:<ext_id>.<version>`.', json['protocol'][0])
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   254
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   255
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   256
    def test_create_session_protocol_as_other_type_bad(self):
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   257
        url = reverse('notes:session-list')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   258
        self.client.login(username='test_user1', password='top_secret')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   259
        group1 = Group.objects.get(id=self.group1.id)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   260
        response = self.client.post(url, {
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   261
            'title': "a new session",
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   262
            'description': "description of the session",
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   263
            'group': 'group1',
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   264
            'protocol': True
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   265
        }, format='json')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   266
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   267
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.json())
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   268
        json = response.json()
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   269
        self.assertIn('protocol', json)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   270
        self.assertEqual('Incorrect format. Expected `urn:protocol:<ext_id>.<version>` or dict.', json['protocol'][0])
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
   271
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
   272
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
   273
    def test_create_session_no_group(self):
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
   274
        url = reverse('notes:session-list')
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
   275
        self.client.login(username='test_user1', password='top_secret')
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
   276
        response = self.client.post(url, {
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
   277
            'title': "a new session",
142
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   278
            'description': "description of the session"
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
   279
        }, format='json')
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
   280
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
   281
        self.assertEqual(response.status_code, status.HTTP_201_CREATED, "Error when creating session %r" % response.json())
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
   282
        json = response.json()
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
   283
        self.assertIn('ext_id', json)
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
   284
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
   285
        session = Session.objects.get(ext_id=json['ext_id'])
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
   286
        self.assertIsNotNone(session)
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
   287
        user1_personal_group = Group.objects.get(profile__owner_personal=self.user1)
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
   288
        self.assertEqual(user1_personal_group, session.group)
142
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   289
        self.assertEqual(user1_personal_group.profile.protocol, session.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
   290
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
   291
    def test_create_session_no_group_default(self):
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
   292
        url = reverse('notes:session-list')
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
   293
        self.client.login(username='test_user2', password='top_secret')
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
   294
        response = self.client.post(url, {
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
   295
            'title': "a new session",
142
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   296
            'description': "description of the session"
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
   297
        }, format='json')
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
   298
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
   299
        self.assertEqual(response.status_code, status.HTTP_201_CREATED, "Error when creating session %r" % response.json())
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
   300
        json = response.json()
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
   301
        self.assertIn('ext_id', json)
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
   302
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
   303
        session = Session.objects.get(ext_id=json['ext_id'])
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
   304
        self.assertIsNotNone(session)
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
   305
        self.assertEqual(self.group1, session.group)
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
   306
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
   307
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
   308
    def test_create_session_bad_group(self):
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
   309
        url = reverse('notes:session-list')
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
   310
        self.client.login(username='test_user3', password='top_secret')
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
   311
        response = self.client.post(url, {
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
   312
            'title': "a new session",
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
   313
            'description': "description of the session",
142
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   314
            'protocol': { 'owner': 'group1' },
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
   315
            'group': "group1"
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
   316
        }, format='json')
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
   317
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
   318
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
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
   319
        json = response.json()
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
   320
        self.assertIn('non_field_errors', json)
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
   321
        self.assertIn('Owner must be in group', json['non_field_errors'])
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
   322
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
   323
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 31
diff changeset
   324
    def test_create_session_with_ext_id(self):
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 31
diff changeset
   325
        url = reverse('notes:session-list')
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 31
diff changeset
   326
        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: 31
diff changeset
   327
        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: 31
diff changeset
   328
        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: 31
diff changeset
   329
            '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: 31
diff changeset
   330
            'title': "a new session",
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 31
diff changeset
   331
            'description': "description of the session",
142
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   332
            'group': 'group1'
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 31
diff changeset
   333
        }, 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: 31
diff changeset
   334
142
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   335
        self.assertEqual(response.status_code, status.HTTP_201_CREATED, "response content: %r" % response.content)
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 31
diff changeset
   336
        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: 31
diff changeset
   337
        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: 31
diff changeset
   338
        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: 31
diff changeset
   339
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 31
diff changeset
   340
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
    def test_detail_session(self):
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 31
diff changeset
   342
        url = reverse('notes:session-detail', kwargs={'ext_id':str(self.session1.ext_id)})
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
        self.client.login(username='test_user1', password='top_secret')
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
        response = self.client.get(url, format='json')
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
        self.assertEqual(response.status_code, status.HTTP_200_OK)
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
    def test_list_notes(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: 74
diff changeset
   348
        url = reverse('notes:notes-session-list', kwargs={'session_ext_id':str(self.session1.ext_id)})
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
        self.client.login(username='test_user1', password='top_secret')
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
        response = self.client.get(url, format='json')
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
        self.assertEqual(response.status_code, status.HTTP_200_OK)
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
    def test_detail_session_bad(self):
74
043477fd5c5c add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents: 31
diff changeset
   354
        url = reverse('notes:session-detail', kwargs={'ext_id':str(self.session2.ext_id)})
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
        self.client.login(username='test_user1', password='top_secret')
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
        response = self.client.get(url, format='json')
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
    def test_list_notes_bad(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: 74
diff changeset
   360
        url = reverse('notes:notes-session-list', kwargs={'session_ext_id':str(self.session2.ext_id)})
31
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
        self.client.login(username='test_user1', password='top_secret')
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
        response = self.client.get(url, format='json')
63be3ce389f7 improve api
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
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: 74
diff changeset
   364
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: 74
diff changeset
   365
    def test_filter_modified_since(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: 74
diff changeset
   366
        url = reverse('notes:session-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: 74
diff changeset
   367
        self.client.login(username='test_user3', 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: 74
diff changeset
   368
        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: 74
diff changeset
   369
            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: 74
diff changeset
   370
            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: 74
diff changeset
   371
        Session.objects.filter(pk=self.session4.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: 74
diff changeset
   372
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: 74
diff changeset
   373
        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: 74
diff changeset
   374
            url,
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: 74
diff changeset
   375
            {'modified_since': (nexthour - datetime.timedelta(minutes=30)).timestamp()},
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: 74
diff changeset
   376
            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: 74
diff changeset
   377
        )
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: 74
diff changeset
   378
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: 74
diff changeset
   379
        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: 74
diff changeset
   380
        json = 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: 74
diff changeset
   381
        self.assertIn('results', json, "must have 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: 74
diff changeset
   382
        self.assertIn('count', json, "must have 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: 74
diff changeset
   383
        self.assertEqual(json['count'], 1, "must have one 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: 74
diff changeset
   384
        self.assertEqual(len(json['results']), 1, "must have one 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: 74
diff changeset
   385
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: 74
diff changeset
   386
        self.assertEqual(json['results'][0].get('title'), "a new session 4")
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: 74
diff changeset
   387
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: 74
diff changeset
   388
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: 74
diff changeset
   389
    def test_filter_modified_since_zero(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: 74
diff changeset
   390
        url = reverse('notes:session-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: 74
diff changeset
   391
        self.client.login(username='test_user3', 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: 74
diff changeset
   392
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: 74
diff changeset
   393
        response = self.client.get(url, {'modified_since': 0}, 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: 74
diff changeset
   394
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: 74
diff changeset
   395
        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: 74
diff changeset
   396
        json = 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: 74
diff changeset
   397
        self.assertIn('results', json, "must have 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: 74
diff changeset
   398
        self.assertIn('count', json, "must have 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: 74
diff changeset
   399
        self.assertEqual(json['count'], 2, "must have two sessions")
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: 74
diff changeset
   400
        self.assertEqual(len(json['results']), 2, "must have two sessions")
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: 74
diff changeset
   401
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: 74
diff changeset
   402
        for session_json in json['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: 74
diff changeset
   403
            self.assertIn(session_json.get('title'), ['a new session 3', 'a new session 4'])
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: 74
diff changeset
   404
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: 74
diff changeset
   405
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: 74
diff changeset
   406
    def test_filter_modified_seconds(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: 74
diff changeset
   407
        url = reverse('notes:session-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: 74
diff changeset
   408
        self.client.login(username='test_user3', 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: 74
diff changeset
   409
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: 74
diff changeset
   410
        prevmoment = \
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: 74
diff changeset
   411
            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: 74
diff changeset
   412
            datetime.timedelta(seconds=5)
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: 74
diff changeset
   413
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: 74
diff changeset
   414
        response = self.client.get(url, {'modified_since': prevmoment.timestamp()}, 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: 74
diff changeset
   415
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: 74
diff changeset
   416
        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: 74
diff changeset
   417
        json = 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: 74
diff changeset
   418
        self.assertIn('results', json, "must have 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: 74
diff changeset
   419
        self.assertIn('count', json, "must have 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: 74
diff changeset
   420
        self.assertEqual(json['count'], 2, "must have two sessions")
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: 74
diff changeset
   421
        self.assertEqual(len(json['results']), 2, "must have two sessions")
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: 74
diff changeset
   422
        for session_json in json['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: 74
diff changeset
   423
            self.assertIn(session_json.get('title'), ['a new session 3', 'a new session 4'])
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: 74
diff changeset
   424
142
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   425
    def test_update_session(self):
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   426
        url = reverse('notes:session-detail', kwargs={'ext_id': self.session1.ext_id})
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   427
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   428
        self.client.login(username='test_user1', password='top_secret')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   429
        response = self.client.put(url, {
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   430
            'title': "a new session",
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   431
            'description': "description of the session",
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   432
            'group': 'group1'
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   433
        }, format='json')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   434
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   435
        self.assertEqual(response.status_code, status.HTTP_200_OK, "response content: %r" % response.content)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   436
        json = response.json()
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   437
        self.assertIn('ext_id', json)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   438
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   439
        session = Session.objects.get(ext_id=json['ext_id'])
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   440
        self.assertIsNotNone(session)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   441
        self.assertEqual(self.group1, session.group)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   442
        self.assertEqual(self.group1.profile.protocol, session.protocol)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   443
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   444
    @skip("Protocol update not yet implemented")
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   445
    def test_update_session_protocol(self):
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   446
        url = reverse('notes:session-detail', kwargs={'ext_id': self.session1.ext_id})
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   447
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   448
        self.client.login(username='test_user1', password='top_secret')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   449
        response = self.client.put(url, {
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   450
            'title': "an updated session",
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   451
            'description': "description of the session",
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   452
            'group': 'group1',
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   453
            'protocol': "urn:protocol:845ac623-b85a-4ddd-91ee-a2deb1a9b54f.3"
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   454
        }, format='json')
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   455
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   456
        json = response.json()
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   457
        # self.assertIn('ext_id', json)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   458
        session = Session.objects.get(ext_id=self.session1.ext_id)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   459
        self.assertEqual(response.status_code, status.HTTP_200_OK, "response content: %r" % response.content)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   460
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   461
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   462
        # session = Session.objects.get(ext_id=json['ext_id'])
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   463
        # self.assertIsNotNone(session)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   464
        # self.assertEqual(self.group1, session.group)
56850f5c73f6 - upgrade libraries
ymh <ymh.work@gmail.com>
parents: 131
diff changeset
   465
        # self.assertEqual(self.group1.profile.protocol, session.protocol)