server/python/django2/renkanmanager/tests/v1_0/tests_renkan.py
changeset 593 2ff785d7026c
parent 590 3be2a86981c2
child 610 b9edc1c1538a
equal deleted inserted replaced
592:66243fb5e3fc 593:2ff785d7026c
    11 
    11 
    12 class RenkanTests(APITestCase):
    12 class RenkanTests(APITestCase):
    13     
    13     
    14     def setUp(self):
    14     def setUp(self):
    15         User.objects.create_superuser("blop", "blop@blop.com", "blop")
    15         User.objects.create_superuser("blop", "blop@blop.com", "blop")
    16         self.user = User.objects.get(username="blop")
    16         self.user = User.objects.get_by_natural_key(username="blop")
    17         _ = self.client.login(username="blop", password="blop")
    17         _ = self.client.login(username="blop", password="blop")
    18         User.objects.create_user("blip", "blip@blip.com", "blip")
    18         User.objects.create_user("blip", "blip@blip.com", "blip")
    19         self.unauthorized_user = User.objects.get(username="blip")
    19         self.unauthorized_user = User.objects.get_by_natural_key(username="blip")
    20         
    20         
    21         # POSTing test workspace
    21         # POSTing test workspace
    22         post_url = reverse("v1.0:workspace_list")
    22         post_url = reverse("v1.0:workspace_list")
    23         test_title = "bleh_title"
    23         test_title = "bleh_title"
    24         data = {"title": test_title}
    24         data = {"title": test_title}
    81         # Checking POSTed Renkan data
    81         # Checking POSTed Renkan data
    82         post_response_dict = json.loads(post_response.content.decode())
    82         post_response_dict = json.loads(post_response.content.decode())
    83         new_renkan_guid = post_response_dict.get("id", "")
    83         new_renkan_guid = post_response_dict.get("id", "")
    84         new_renkan = Renkan.objects.get(renkan_guid=new_renkan_guid)
    84         new_renkan = Renkan.objects.get(renkan_guid=new_renkan_guid)
    85         # GUIDs and username
    85         # GUIDs and username
    86         self.assertEqual(self.user.username, post_response_dict.get("created_by", ""))
    86         self.assertEqual(getattr(self.user, User.USERNAME_FIELD), post_response_dict.get("created_by", ""))
    87         self.assertEqual(self.user.username, post_response_dict.get("last_updated_by", ""))
    87         self.assertEqual(getattr(self.user, User.USERNAME_FIELD), post_response_dict.get("last_updated_by", ""))
    88         self.assertEqual(self.user.username, new_renkan.creator.username)
    88         self.assertEqual(getattr(self.user, User.USERNAME_FIELD), getattr(new_renkan.creator, User.USERNAME_FIELD))
    89         # Content and title extracted from revision
    89         # Content and title extracted from revision
    90         self.assertEqual(new_renkan.title, self.first_test_title)
    90         self.assertEqual(new_renkan.title, self.first_test_title)
    91         self.assertEqual(new_renkan.content, self.first_test_content)
    91         self.assertEqual(new_renkan.content, self.first_test_content)
    92         # Revision count
    92         # Revision count
    93         self.assertEqual(new_renkan.revision_count, 1)
    93         self.assertEqual(new_renkan.revision_count, 1)
    95         
    95         
    96         # Checking POSTed Renkan revision data
    96         # Checking POSTed Renkan revision data
    97         new_renkan_revision_guid = post_response_dict.get("current_revision_id", "")
    97         new_renkan_revision_guid = post_response_dict.get("current_revision_id", "")
    98         new_renkan_revision = Revision.objects.get(revision_guid = new_renkan_revision_guid)
    98         new_renkan_revision = Revision.objects.get(revision_guid = new_renkan_revision_guid)
    99         # GUIDs and username
    99         # GUIDs and username
   100         self.assertEqual(self.user.username, new_renkan_revision.creator.username)
   100         self.assertEqual(getattr(self.user, User.USERNAME_FIELD), getattr(new_renkan_revision.creator, User.USERNAME_FIELD))
   101         self.assertEqual(self.user.username, new_renkan_revision.last_updated_by.username)
   101         self.assertEqual(getattr(self.user, User.USERNAME_FIELD), getattr(new_renkan_revision.last_updated_by, User.USERNAME_FIELD))
   102         # Title and content
   102         # Title and content
   103         #    in the response
   103         #    in the response
   104         self.assertEqual(post_response_dict.get("title", ""), self.first_test_title)
   104         self.assertEqual(post_response_dict.get("title", ""), self.first_test_title)
   105         self.assertEqual(post_response_dict.get("content", ""), self.first_test_content)
   105         self.assertEqual(post_response_dict.get("content", ""), self.first_test_content)
   106         #    in the database
   106         #    in the database
   127         new_renkan_guid = post_response_dict.get("id", "")
   127         new_renkan_guid = post_response_dict.get("id", "")
   128         new_renkan = Renkan.objects.get(renkan_guid=new_renkan_guid)
   128         new_renkan = Renkan.objects.get(renkan_guid=new_renkan_guid)
   129         # GUIDs and username
   129         # GUIDs and username
   130         self.assertEqual(self.test_workspace_guid, post_response_dict.get("workspace_id", ""))
   130         self.assertEqual(self.test_workspace_guid, post_response_dict.get("workspace_id", ""))
   131         self.assertEqual(self.test_workspace_guid, new_renkan.workspace_guid)
   131         self.assertEqual(self.test_workspace_guid, new_renkan.workspace_guid)
   132         self.assertEqual(self.user.username, post_response_dict.get("created_by", ""))
   132         self.assertEqual(getattr(self.user, User.USERNAME_FIELD), post_response_dict.get("created_by", ""))
   133         self.assertEqual(self.user.username, post_response_dict.get("last_updated_by", ""))
   133         self.assertEqual(getattr(self.user, User.USERNAME_FIELD), post_response_dict.get("last_updated_by", ""))
   134         self.assertEqual(self.user.username, new_renkan.creator.username)
   134         self.assertEqual(getattr(self.user, User.USERNAME_FIELD), getattr(new_renkan.creator, User.USERNAME_FIELD))
   135         # Content and title extracted from revision
   135         # Content and title extracted from revision
   136         self.assertEqual(new_renkan.title, self.second_test_title)
   136         self.assertEqual(new_renkan.title, self.second_test_title)
   137         self.assertEqual(new_renkan.content, self.second_test_content)
   137         self.assertEqual(new_renkan.content, self.second_test_content)
   138         # Revision count
   138         # Revision count
   139         self.assertEqual(new_renkan.revision_count, 1)
   139         self.assertEqual(new_renkan.revision_count, 1)
   193         
   193         
   194         # Checking GET data
   194         # Checking GET data
   195         get_response_dict = json.loads(get_response.content.decode())
   195         get_response_dict = json.loads(get_response.content.decode())
   196         self.assertEqual(new_renkan_guid, get_response_dict.get("id", ""))
   196         self.assertEqual(new_renkan_guid, get_response_dict.get("id", ""))
   197         self.assertEqual(new_revision_guid, get_response_dict.get("current_revision_id", ""))
   197         self.assertEqual(new_revision_guid, get_response_dict.get("current_revision_id", ""))
   198         self.assertEqual(self.user.username, get_response_dict.get("created_by", ""))
   198         self.assertEqual(getattr(self.user, User.USERNAME_FIELD), get_response_dict.get("created_by", ""))
   199         self.assertEqual(self.user.username, get_response_dict.get("last_updated_by", ""))
   199         self.assertEqual(getattr(self.user, User.USERNAME_FIELD), get_response_dict.get("last_updated_by", ""))
   200         
   200         
   201         ###################################################
   201         ###################################################
   202         # GETting with wrong guid
   202         # GETting with wrong guid
   203         ###################################################
   203         ###################################################
   204         
   204         
   404         #     in the response
   404         #     in the response
   405         self.assertNotEqual(first_copy_response_dict.get("id"), source_renkan_guid)
   405         self.assertNotEqual(first_copy_response_dict.get("id"), source_renkan_guid)
   406         self.assertEqual(first_copy_response_dict.get("source_revision_id"), source_revision_guid)
   406         self.assertEqual(first_copy_response_dict.get("source_revision_id"), source_revision_guid)
   407         self.assertEqual(first_copy_response_dict.get("title", ""), "new_title_copy_1")
   407         self.assertEqual(first_copy_response_dict.get("title", ""), "new_title_copy_1")
   408         self.assertEqual(first_copy_response_dict.get("content", ""), self.first_test_content)
   408         self.assertEqual(first_copy_response_dict.get("content", ""), self.first_test_content)
   409         self.assertEqual(first_copy_response_dict.get("created_by", ""), self.user.username)
   409         self.assertEqual(first_copy_response_dict.get("created_by", ""), getattr(self.user, User.USERNAME_FIELD))
   410         self.assertEqual(first_copy_response_dict.get("last_updated_by", ""), self.user.username)
   410         self.assertEqual(first_copy_response_dict.get("last_updated_by", ""), getattr(self.user, User.USERNAME_FIELD))
   411         #     in the database
   411         #     in the database
   412         first_copy = Renkan.objects.get(renkan_guid=first_copy_response_dict.get("id", ""))
   412         first_copy = Renkan.objects.get(renkan_guid=first_copy_response_dict.get("id", ""))
   413         first_copy_revision = Revision.objects.get(revision_guid=first_copy_response_dict.get("current_revision_id", ""))
   413         first_copy_revision = Revision.objects.get(revision_guid=first_copy_response_dict.get("current_revision_id", ""))
   414         self.assertEqual(first_copy.title, "new_title_copy_1")
   414         self.assertEqual(first_copy.title, "new_title_copy_1")
   415         self.assertEqual(first_copy.content, self.first_test_content)
   415         self.assertEqual(first_copy.content, self.first_test_content)
   416         self.assertEqual(first_copy_revision.title, "new_title_copy_1")
   416         self.assertEqual(first_copy_revision.title, "new_title_copy_1")
   417         self.assertEqual(first_copy_revision.content, self.first_test_content)
   417         self.assertEqual(first_copy_revision.content, self.first_test_content)
   418         self.assertEqual(first_copy.creator.username, self.user.username)
   418         self.assertEqual(getattr(first_copy.creator, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD))
   419         self.assertEqual(first_copy_revision.creator.username, self.user.username)
   419         self.assertEqual(getattr(first_copy_revision.creator, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD))
   420         self.assertEqual(first_copy_revision.last_updated_by.username, self.user.username)
   420         self.assertEqual(getattr(first_copy_revision.last_updated_by, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD))
   421         
   421         
   422         ###################################################
   422         ###################################################
   423         # POSTing copy with source_renkan_guid in data
   423         # POSTing copy with source_renkan_guid in data
   424         ###################################################
   424         ###################################################
   425         
   425         
   433         #     in the response
   433         #     in the response
   434         self.assertNotEqual(second_copy_response_dict.get("id"), source_renkan_guid)
   434         self.assertNotEqual(second_copy_response_dict.get("id"), source_renkan_guid)
   435         self.assertEqual(second_copy_response_dict.get("source_revision_id"), source_revision_guid)
   435         self.assertEqual(second_copy_response_dict.get("source_revision_id"), source_revision_guid)
   436         self.assertEqual(second_copy_response_dict.get("title", ""), "new_title_copy_2")
   436         self.assertEqual(second_copy_response_dict.get("title", ""), "new_title_copy_2")
   437         self.assertEqual(second_copy_response_dict.get("content", ""), self.first_test_content)
   437         self.assertEqual(second_copy_response_dict.get("content", ""), self.first_test_content)
   438         self.assertEqual(second_copy_response_dict.get("created_by", ""), self.user.username)
   438         self.assertEqual(second_copy_response_dict.get("created_by", ""), getattr(self.user, User.USERNAME_FIELD))
   439         self.assertEqual(second_copy_response_dict.get("last_updated_by", ""), self.user.username)
   439         self.assertEqual(second_copy_response_dict.get("last_updated_by", ""), getattr(self.user, User.USERNAME_FIELD))
   440         #     in the database
   440         #     in the database
   441         second_copy = Renkan.objects.get(renkan_guid=second_copy_response_dict.get("id", ""))
   441         second_copy = Renkan.objects.get(renkan_guid=second_copy_response_dict.get("id", ""))
   442         second_copy_revision = Revision.objects.get(revision_guid=second_copy_response_dict.get("current_revision_id", ""))
   442         second_copy_revision = Revision.objects.get(revision_guid=second_copy_response_dict.get("current_revision_id", ""))
   443         self.assertEqual(second_copy.title, "new_title_copy_2")
   443         self.assertEqual(second_copy.title, "new_title_copy_2")
   444         self.assertEqual(second_copy.content, self.first_test_content)
   444         self.assertEqual(second_copy.content, self.first_test_content)
   445         self.assertEqual(second_copy_revision.title, "new_title_copy_2")
   445         self.assertEqual(second_copy_revision.title, "new_title_copy_2")
   446         self.assertEqual(second_copy_revision.content, self.first_test_content)
   446         self.assertEqual(second_copy_revision.content, self.first_test_content)
   447         self.assertEqual(second_copy.creator.username, self.user.username)
   447         self.assertEqual(getattr(second_copy.creator, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD))
   448         self.assertEqual(second_copy_revision.creator.username, self.user.username)
   448         self.assertEqual(getattr(second_copy_revision.creator, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD))
   449         self.assertEqual(second_copy_revision.last_updated_by.username, self.user.username)
   449         self.assertEqual(getattr(second_copy_revision.last_updated_by, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD))
   450         
   450         
   451         ###################################################
   451         ###################################################
   452         # POSTing copy with query arg for REVISION guid
   452         # POSTing copy with query arg for REVISION guid
   453         ###################################################
   453         ###################################################
   454         
   454         
   462         #     in the response
   462         #     in the response
   463         self.assertNotEqual(third_copy_response_dict.get("id"), source_renkan_guid)
   463         self.assertNotEqual(third_copy_response_dict.get("id"), source_renkan_guid)
   464         self.assertEqual(third_copy_response_dict.get("source_revision_id"), source_revision_guid)
   464         self.assertEqual(third_copy_response_dict.get("source_revision_id"), source_revision_guid)
   465         self.assertEqual(third_copy_response_dict.get("title", ""), "new_title_copy_3")
   465         self.assertEqual(third_copy_response_dict.get("title", ""), "new_title_copy_3")
   466         self.assertEqual(third_copy_response_dict.get("content", ""), self.first_test_content)
   466         self.assertEqual(third_copy_response_dict.get("content", ""), self.first_test_content)
   467         self.assertEqual(third_copy_response_dict.get("created_by", ""), self.user.username)
   467         self.assertEqual(third_copy_response_dict.get("created_by", ""), getattr(self.user, User.USERNAME_FIELD))
   468         self.assertEqual(third_copy_response_dict.get("last_updated_by", ""), self.user.username)
   468         self.assertEqual(third_copy_response_dict.get("last_updated_by", ""), getattr(self.user, User.USERNAME_FIELD))
   469         #     in the database
   469         #     in the database
   470         third_copy = Renkan.objects.get(renkan_guid=third_copy_response_dict.get("id", ""))
   470         third_copy = Renkan.objects.get(renkan_guid=third_copy_response_dict.get("id", ""))
   471         third_copy_revision = Revision.objects.get(revision_guid=third_copy_response_dict.get("current_revision_id", ""))
   471         third_copy_revision = Revision.objects.get(revision_guid=third_copy_response_dict.get("current_revision_id", ""))
   472         self.assertEqual(third_copy.title, "new_title_copy_3")
   472         self.assertEqual(third_copy.title, "new_title_copy_3")
   473         self.assertEqual(third_copy.content, self.first_test_content)
   473         self.assertEqual(third_copy.content, self.first_test_content)
   474         self.assertEqual(third_copy_revision.title, "new_title_copy_3")
   474         self.assertEqual(third_copy_revision.title, "new_title_copy_3")
   475         self.assertEqual(third_copy_revision.content, self.first_test_content)
   475         self.assertEqual(third_copy_revision.content, self.first_test_content)
   476         self.assertEqual(third_copy.creator.username, self.user.username)
   476         self.assertEqual(getattr(third_copy.creator, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD))
   477         self.assertEqual(third_copy_revision.creator.username, self.user.username)
   477         self.assertEqual(getattr(third_copy_revision.creator, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD))
   478         self.assertEqual(third_copy_revision.last_updated_by.username, self.user.username)
   478         self.assertEqual(getattr(third_copy_revision.last_updated_by, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD))
   479         
   479         
   480         ###################################################
   480         ###################################################
   481         # POSTing copy with source_revision_guid in data
   481         # POSTing copy with source_revision_guid in data
   482         ###################################################
   482         ###################################################
   483         
   483         
   491         #     in the response
   491         #     in the response
   492         self.assertNotEqual(fourth_copy_response_dict.get("id"), source_renkan_guid)
   492         self.assertNotEqual(fourth_copy_response_dict.get("id"), source_renkan_guid)
   493         self.assertEqual(fourth_copy_response_dict.get("source_revision_id"), source_revision_guid)
   493         self.assertEqual(fourth_copy_response_dict.get("source_revision_id"), source_revision_guid)
   494         self.assertEqual(fourth_copy_response_dict.get("title", ""), self.first_test_title)
   494         self.assertEqual(fourth_copy_response_dict.get("title", ""), self.first_test_title)
   495         self.assertEqual(fourth_copy_response_dict.get("content", ""), self.first_test_content)
   495         self.assertEqual(fourth_copy_response_dict.get("content", ""), self.first_test_content)
   496         self.assertEqual(fourth_copy_response_dict.get("created_by", ""), self.user.username)
   496         self.assertEqual(fourth_copy_response_dict.get("created_by", ""), getattr(self.user, User.USERNAME_FIELD))
   497         self.assertEqual(fourth_copy_response_dict.get("last_updated_by", ""), self.user.username)
   497         self.assertEqual(fourth_copy_response_dict.get("last_updated_by", ""), getattr(self.user, User.USERNAME_FIELD))
   498         #     in the database
   498         #     in the database
   499         fourth_copy = Renkan.objects.get(renkan_guid=fourth_copy_response_dict.get("id", ""))
   499         fourth_copy = Renkan.objects.get(renkan_guid=fourth_copy_response_dict.get("id", ""))
   500         fourth_copy_revision = Revision.objects.get(revision_guid=fourth_copy_response_dict.get("current_revision_id", ""))
   500         fourth_copy_revision = Revision.objects.get(revision_guid=fourth_copy_response_dict.get("current_revision_id", ""))
   501         self.assertEqual(fourth_copy.title, self.first_test_title)
   501         self.assertEqual(fourth_copy.title, self.first_test_title)
   502         self.assertEqual(fourth_copy.content, self.first_test_content)
   502         self.assertEqual(fourth_copy.content, self.first_test_content)
   503         self.assertEqual(fourth_copy_revision.title, self.first_test_title)
   503         self.assertEqual(fourth_copy_revision.title, self.first_test_title)
   504         self.assertEqual(fourth_copy_revision.content, self.first_test_content)
   504         self.assertEqual(fourth_copy_revision.content, self.first_test_content)
   505         self.assertEqual(fourth_copy.creator.username, self.user.username)
   505         self.assertEqual(getattr(fourth_copy.creator, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD))
   506         self.assertEqual(fourth_copy_revision.creator.username, self.user.username)
   506         self.assertEqual(getattr(fourth_copy_revision.creator, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD))
   507         self.assertEqual(fourth_copy_revision.last_updated_by.username, self.user.username)
   507         self.assertEqual(getattr(fourth_copy_revision.last_updated_by, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD))
   508         
   508         
   509         
   509         
   510         ###################################################
   510         ###################################################
   511         # try POSTing copy with bad query arg guid and with bad data guid
   511         # try POSTing copy with bad query arg guid and with bad data guid
   512         ###################################################
   512         ###################################################