server/python/django2/renkanmanager/tests/v1_0/tests_revision.py
author durandn
Thu, 21 Apr 2016 15:18:19 +0200
changeset 605 13d355fd09bf
parent 593 2ff785d7026c
child 610 b9edc1c1538a
permissions -rw-r--r--
updated uri to allow optional trailing slash on single resource URIs (django automatic redirects don't carry over the Authorization header that can sometimes be needed, for instance with OAuth)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
     1
import json
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
     2
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
     3
from django.contrib.auth import get_user_model
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
     4
from django.core.urlresolvers import reverse
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
     5
from renkanmanager.models import Renkan, Revision
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
     6
from rest_framework import status
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
     7
from rest_framework.test import APITestCase
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
     8
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
     9
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    10
User = get_user_model()
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    11
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    12
class RevisionTests(APITestCase):
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    13
    
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    14
    def setUp(self):
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    15
        User.objects.create_superuser("blop", "blop@blop.com", "blop")
593
2ff785d7026c corrected tests and serializer so they can support custom user model, added a readme (to be expanded) with configuration information for the field renkan api will use to render user information
durandn
parents: 590
diff changeset
    16
        self.user = User.objects.get_by_natural_key(username="blop")
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    17
        _ = self.client.login(username="blop", password="blop")
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    18
        User.objects.create_user("blip", "blip@blip.com", "blip")
593
2ff785d7026c corrected tests and serializer so they can support custom user model, added a readme (to be expanded) with configuration information for the field renkan api will use to render user information
durandn
parents: 590
diff changeset
    19
        self.unauthorized_user = User.objects.get_by_natural_key(username="blip")
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    20
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    21
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    22
        # POSTing new Renkan
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    23
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    24
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
    25
        post_url = reverse("v1.0:renkan_list")
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    26
        self.test_title = "test_title_1"
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    27
        self.test_content = json.dumps({
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    28
            "id": "",
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    29
            "title": "test_title_1",
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    30
            "description": "test_description_1",
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    31
            "created": "",
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    32
            "updated": "",
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    33
            "edges": [],
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    34
            "nodes": [],
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    35
            "users": [],
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    36
            "space_id": "",
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    37
            "views": []
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    38
        })
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    39
        self.test_data = {"title": self.test_title, "content": self.test_content}
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    40
        post_response = self.client.post(post_url, self.test_data, format="json")
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    41
        post_response_dict = json.loads(post_response.content.decode())
589
0ae11aa255a3 Moved python2/django into a django2 folder for consistency + clarified serializers fields name
durandn
parents: 588
diff changeset
    42
        self.test_renkan_guid = post_response_dict.get("id", "")
0ae11aa255a3 Moved python2/django into a django2 folder for consistency + clarified serializers fields name
durandn
parents: 588
diff changeset
    43
        self.test_initial_revision_guid = post_response_dict.get("current_revision_id", "")
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    44
    
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    45
    def test_get_revision(self):
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    46
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    47
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    48
        # GETting revision
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    49
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    50
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
    51
        get_url = reverse("v1.0:revision_detail", kwargs={"renkan_guid" : self.test_renkan_guid, "revision_guid": self.test_initial_revision_guid})
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    52
        get_response = self.client.get(get_url, {}, format="json")
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    53
        self.assertEqual(get_response.status_code, status.HTTP_200_OK)
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    54
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    55
        # Checking data
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    56
        get_response_dict = json.loads(get_response.content.decode()) 
589
0ae11aa255a3 Moved python2/django into a django2 folder for consistency + clarified serializers fields name
durandn
parents: 588
diff changeset
    57
        self.assertEqual(get_response_dict.get("id", ""), self.test_initial_revision_guid)
0ae11aa255a3 Moved python2/django into a django2 folder for consistency + clarified serializers fields name
durandn
parents: 588
diff changeset
    58
        self.assertEqual(get_response_dict.get("parent_renkan_id", ""), self.test_renkan_guid)
593
2ff785d7026c corrected tests and serializer so they can support custom user model, added a readme (to be expanded) with configuration information for the field renkan api will use to render user information
durandn
parents: 590
diff changeset
    59
        self.assertEqual(get_response_dict.get("revision_created_by", ""), getattr(self.user, User.USERNAME_FIELD))
2ff785d7026c corrected tests and serializer so they can support custom user model, added a readme (to be expanded) with configuration information for the field renkan api will use to render user information
durandn
parents: 590
diff changeset
    60
        self.assertEqual(get_response_dict.get("revision_last_updated_by", ""), getattr(self.user, User.USERNAME_FIELD))
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    61
        self.assertEqual(get_response_dict.get("title", ""), self.test_data.get("title", ""))
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    62
        self.assertEqual(get_response_dict.get("content", ""), self.test_data.get("content", ""))
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    63
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    64
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    65
        # GETting with wrong renkan guid
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    66
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    67
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
    68
        get_url = reverse("v1.0:revision_detail", kwargs={"renkan_guid" : "bad-renkan-guid", "revision_guid": self.test_initial_revision_guid})
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    69
        get_response = self.client.get(get_url, {}, format="json")
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    70
        self.assertEqual(get_response.status_code, status.HTTP_404_NOT_FOUND)
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    71
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    72
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    73
        # GETting with wrong revision guid
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    74
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    75
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
    76
        get_url = reverse("v1.0:revision_detail", kwargs={"renkan_guid" : self.test_renkan_guid, "revision_guid": "bad-revision-guid"})
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    77
        get_response = self.client.get(get_url, {}, format="json")
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    78
        self.assertEqual(get_response.status_code, status.HTTP_404_NOT_FOUND)
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    79
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    80
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    81
        # try GETting with unauthorized user 
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    82
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    83
        
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    84
        _ = self.client.login(username="blip", password="blip")
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
    85
        get_url = reverse("v1.0:revision_detail", kwargs={"renkan_guid" : self.test_renkan_guid, "revision_guid": self.test_initial_revision_guid})
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    86
        get_response = self.client.get(get_url, {}, format="json")
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    87
        self.assertEqual(get_response.status_code, status.HTTP_403_FORBIDDEN)
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    88
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    89
    def test_get_revision_list(self):
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    90
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    91
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    92
        # PUTting another revision in test renkan
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    93
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    94
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
    95
        put_url = reverse("v1.0:renkan_detail", kwargs={"renkan_guid" : self.test_renkan_guid})
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    96
        put_title = "edited_title"
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    97
        put_data = {
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    98
            "title" : put_title,
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    99
            "create_new_revision": True
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   100
        }
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   101
        put_response = self.client.put(put_url, put_data, format="json")
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   102
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   103
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   104
        # GETting revision lists
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   105
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   106
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   107
        get_url = reverse("v1.0:revision_list", kwargs={"renkan_guid" : self.test_renkan_guid})
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   108
        get_response = self.client.get(get_url, {}, format="json")
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   109
        self.assertEqual(get_response.status_code, status.HTTP_200_OK)
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   110
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   111
        # Checking data
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   112
        get_response_content = json.loads(get_response.content.decode()) # Should be a list
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   113
        self.assertTrue(isinstance(get_response_content, list))
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   114
        self.assertEqual(len(get_response_content), 2)
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   115
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   116
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   117
        # GETting with wrong renkan guid
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   118
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   119
        
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   120
        _ = self.client.login(username="blip", password="blip")
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   121
        get_url = reverse("v1.0:revision_detail", kwargs={"renkan_guid" : self.test_renkan_guid, "revision_guid": self.test_initial_revision_guid})
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   122
        get_response = self.client.get(get_url, {}, format="json")
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   123
        self.assertEqual(get_response.status_code, status.HTTP_403_FORBIDDEN)
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   124
    
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   125
    def test_delete_revision(self):
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   126
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   127
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   128
        # Try to DELETE the initial revision (last revision, should 400)
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   129
        ###################################################
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   130
        delete_url = reverse("v1.0:revision_detail", kwargs={"renkan_guid" : self.test_renkan_guid, "revision_guid": self.test_initial_revision_guid})
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   131
        delete_response = self.client.delete(delete_url, {}, format="json")
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   132
        self.assertEqual(delete_response.status_code, status.HTTP_400_BAD_REQUEST)
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   133
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   134
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   135
        # PUTting another revision in test renkan
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   136
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   137
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   138
        put_url = reverse("v1.0:renkan_detail", kwargs={"renkan_guid" : self.test_renkan_guid})
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   139
        put_title = "edited_title"
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   140
        put_data = {
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   141
            "title" : put_title,
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   142
            "create_new_revision": True
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   143
        }
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   144
        put_response = self.client.put(put_url, put_data, format="json")
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   145
        put_response_dict = json.loads(put_response.content.decode())
589
0ae11aa255a3 Moved python2/django into a django2 folder for consistency + clarified serializers fields name
durandn
parents: 588
diff changeset
   146
        added_revision_guid = put_response_dict.get("current_revision_id", "")
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   147
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   148
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   149
        # Try to DELETE the added revision (current revision, should 400)
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   150
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   151
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   152
        delete_url = reverse("v1.0:revision_detail", kwargs={"renkan_guid" : self.test_renkan_guid, "revision_guid": added_revision_guid})
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   153
        delete_response = self.client.delete(delete_url, {}, format="json")
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   154
        self.assertEqual(delete_response.status_code, status.HTTP_400_BAD_REQUEST)
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   155
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   156
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   157
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   158
        # try to DELETE with unauthorized user 
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   159
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   160
        
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   161
        _ = self.client.login(username="blip", password="blip")
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   162
        delete_url = reverse("v1.0:revision_detail", kwargs={"renkan_guid" : self.test_renkan_guid, "revision_guid": self.test_initial_revision_guid})
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   163
        delete_response = self.client.delete(delete_url, {}, format="json")
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   164
        self.assertEqual(delete_response.status_code, status.HTTP_403_FORBIDDEN)
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   165
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   166
        # Restoring rightful user
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   167
        _ = self.client.login(username="blop", password="blop")
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   168
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   169
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   170
        # Try to DELETE the initial revision (should 204 now that we added a revision)
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   171
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   172
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   173
        delete_url = reverse("v1.0:revision_detail", kwargs={"renkan_guid" : self.test_renkan_guid, "revision_guid": self.test_initial_revision_guid})
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   174
        delete_response = self.client.delete(delete_url, {}, format="json")
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   175
        self.assertEqual(delete_response.status_code, status.HTTP_204_NO_CONTENT)
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   176
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   177
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   178
        # Try to DELETE with wrong renkan guid
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   179
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   180
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   181
        delete_url = reverse("v1.0:revision_detail", kwargs={"renkan_guid" : "bad-renkan-guid", "revision_guid": self.test_initial_revision_guid})
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   182
        delete_response = self.client.delete(delete_url, {}, format="json")
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   183
        self.assertEqual(delete_response.status_code, status.HTTP_404_NOT_FOUND)
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   184
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   185
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   186
        # Try to DELETE with wrong revision guid
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   187
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   188
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   189
        delete_url = reverse("v1.0:revision_detail", kwargs={"renkan_guid" : self.test_renkan_guid, "revision_guid": "bad-revision-guid"})
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   190
        delete_response = self.client.delete(delete_url, {}, format="json")
587
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   191
        self.assertEqual(delete_response.status_code, status.HTTP_404_NOT_FOUND)