server/python/django2/renkanmanager/tests/v1_0/tests_revision.py
author durandn
Tue, 03 May 2016 14:32:28 +0200
changeset 610 b9edc1c1538a
parent 593 2ff785d7026c
child 613 e00a24b711a0
permissions -rw-r--r--
reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
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"
610
b9edc1c1538a reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents: 593
diff changeset
    27
        test_content_dict_init = {
588
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",
610
b9edc1c1538a reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents: 593
diff changeset
    30
            "description": "",
b9edc1c1538a reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents: 593
diff changeset
    31
            "created": "2016-03-11 15:10:10.645193+00:00",
b9edc1c1538a reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents: 593
diff changeset
    32
            "updated": "2016-03-11 15:10:10.645193+00:00",
588
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": []
610
b9edc1c1538a reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents: 593
diff changeset
    38
        }
b9edc1c1538a reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents: 593
diff changeset
    39
        self.test_content = json.dumps(test_content_dict_init)
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    40
        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
    41
        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
    42
        post_response_dict = json.loads(post_response.content.decode())
610
b9edc1c1538a reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents: 593
diff changeset
    43
        self.test_content_dict = json.loads(post_response_dict.get("content", "{}"))
b9edc1c1538a reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents: 593
diff changeset
    44
        self.post_response_content_dict = json.loads(post_response_dict.get("content", "{}"))
589
0ae11aa255a3 Moved python2/django into a django2 folder for consistency + clarified serializers fields name
durandn
parents: 588
diff changeset
    45
        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
    46
        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
    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
    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
    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
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    51
        # 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
    52
        ###################################################
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
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
    54
        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
    55
        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
    56
        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
    57
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    58
        # Checking data
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    59
        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
    60
        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
    61
        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
    62
        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
    63
        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
    64
        self.assertEqual(get_response_dict.get("title", ""), self.test_data.get("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
    65
        
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
        # 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
    68
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    69
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
    70
        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
    71
        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
    72
        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
    73
        
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
        # 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
    76
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    77
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
    78
        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
    79
        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
    80
        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
    81
        
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
        # 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
    84
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    85
        
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
    86
        _ = self.client.login(username="blip", password="blip")
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
    87
        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
    88
        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
    89
        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
    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
    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
    92
        
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
        # 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
    95
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
    96
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
    97
        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
    98
        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
    99
        put_data = {
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   100
            "title" : put_title,
610
b9edc1c1538a reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents: 593
diff changeset
   101
            "validation_timestamp": self.post_response_content_dict.get("updated", ""),
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   102
            "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
   103
        }
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   104
        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
   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
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   107
        # 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
   108
        ###################################################
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
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   110
        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
   111
        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
   112
        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
   113
        
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
        # Checking data
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   115
        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
   116
        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
   117
        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
   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
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   120
        # 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
   121
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   122
        
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   123
        _ = self.client.login(username="blip", password="blip")
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   124
        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
   125
        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
   126
        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
   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
    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
   129
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   130
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   131
        # 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
   132
        ###################################################
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   133
        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
   134
        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
   135
        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
   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
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   138
        # 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
   139
        ###################################################
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
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   141
        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
   142
        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
   143
        put_data = {
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   144
            "title" : put_title,
610
b9edc1c1538a reworked views and serializers to pass and take into account the "validation timestamp" to the model + refactored models to have a content validation method + adapted tests
durandn
parents: 593
diff changeset
   145
            "validation_timestamp": self.post_response_content_dict.get("updated", ""),
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   146
            "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
   147
        }
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   148
        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
   149
        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
   150
        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
   151
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   152
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   153
        # 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
   154
        ###################################################
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
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   156
        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
   157
        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
   158
        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
   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
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   161
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   162
        # 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
   163
        ###################################################
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
        
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   165
        _ = self.client.login(username="blip", password="blip")
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   166
        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
   167
        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
   168
        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
   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
        # Restoring rightful user
588
95536fa18d0d Minor adjustements to properly interact with Renkan client
durandn
parents: 587
diff changeset
   171
        _ = 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
   172
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   173
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   174
        # 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
   175
        ###################################################
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
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   177
        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
   178
        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
   179
        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
   180
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   181
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   182
        # 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
   183
        ###################################################
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
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   185
        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
   186
        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
   187
        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
   188
        
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   189
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   190
        # 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
   191
        ###################################################
fb0041aa74d3 transfer work on renkanmanager into a renkan/server/python2 folder: reworked models, implemented simple API basic permissions, wrote tests
durandn
parents:
diff changeset
   192
        
590
3be2a86981c2 API versioning via namespace
durandn
parents: 589
diff changeset
   193
        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
   194
        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
   195
        self.assertEqual(delete_response.status_code, status.HTTP_404_NOT_FOUND)