src/notes/tests/api/sync.py
changeset 129 d48946d164c6
parent 128 34a75bd8d0b9
equal deleted inserted replaced
128:34a75bd8d0b9 129:d48946d164c6
     1 """
     1 """
     2 Tests the sync api
     2 Tests the sync api
     3 """
     3 """
     4 import datetime
     4 import datetime
     5 import logging
     5 import logging
       
     6 import uuid
     6 
     7 
     7 from django.contrib.auth import get_user_model
     8 from django.contrib.auth import get_user_model
     8 from django.contrib.contenttypes.models import ContentType
     9 from django.contrib.contenttypes.models import ContentType
     9 from django.urls import reverse
    10 from django.urls import reverse
    10 from django.utils import timezone
    11 from django.utils import timezone
    38             username='test_user3',
    39             username='test_user3',
    39             email='test_user@emial.com',
    40             email='test_user@emial.com',
    40             password='top_secret'
    41             password='top_secret'
    41         )
    42         )
    42 
    43 
       
    44         self.clientId = str(uuid.uuid4())
       
    45 
    43         url = reverse('notes:session-list')
    46         url = reverse('notes:session-list')
    44         self.client.login(username='test_user1', password='top_secret')
    47         self.client.login(username='test_user1', password='top_secret')
    45         response = self.client.post(url, {
    48         response = self.client.post(url, {
    46             'title': "a new session 1",
    49             'title': "a new session 1",
    47             'description': "Description 1",
    50             'description': "Description 1",
    48             'protocol': "[]"
    51             'protocol': "[]"
    49         }, format='json')
    52         }, format='json', HTTP_AUDITLOG_CLIENT=self.clientId)
    50 
    53 
    51         logger.debug('REPOSNSE %r', response.json())
       
    52 
    54 
    53         self.session1 = Session.objects.get(ext_id=response.json()['ext_id'])
    55         self.session1 = Session.objects.get(ext_id=response.json()['ext_id'])
    54         self.client.logout()
    56         self.client.logout()
    55 
    57 
    56         self.client.login(username='test_user2', password='top_secret')
    58         self.client.login(username='test_user2', password='top_secret')
   152         self.assertIn('notes', json_resp)
   154         self.assertIn('notes', json_resp)
   153         self.assertEqual(2, len(json_resp['notes']))
   155         self.assertEqual(2, len(json_resp['notes']))
   154         for sync_def in json_resp['notes']:
   156         for sync_def in json_resp['notes']:
   155             self.assertEqual('note', sync_def['type'])
   157             self.assertEqual('note', sync_def['type'])
   156             self.assertEqual(0, sync_def['action'])
   158             self.assertEqual(0, sync_def['action'])
   157             self.assertIn(sync_def['ext_id'],[str(self.note1.ext_id), str(self.note2.ext_id)])
   159             self.assertIn(sync_def['ext_id'], [str(self.note1.ext_id), str(self.note2.ext_id)])
       
   160 
       
   161     def test_simple_output_client_id(self):
       
   162         url = reverse('notes:sync-list')
       
   163         self.client.login(username='test_user1', password='top_secret')
       
   164         response = self.client.get(url, HTTP_AUDITLOG_CLIENT=self.clientId)
       
   165         self.assertEqual(response.status_code, status.HTTP_200_OK)
       
   166         json_resp = response.json()
       
   167         self.assertIn('sessions', json_resp)
       
   168         self.assertEqual(0, len(json_resp['sessions']))
   158 
   169 
   159     def test_modified_since_empty(self):
   170     def test_modified_since_empty(self):
   160         url = reverse('notes:sync-list')
   171         url = reverse('notes:sync-list')
   161         self.client.login(username='test_user1', password='top_secret')
   172         self.client.login(username='test_user1', password='top_secret')
   162 
   173