diff -r 854a027c80ff -r b9edc1c1538a server/python/django2/renkanmanager/tests/v1_0/tests_renkan.py --- a/server/python/django2/renkanmanager/tests/v1_0/tests_renkan.py Wed Apr 27 16:36:30 2016 +0200 +++ b/server/python/django2/renkanmanager/tests/v1_0/tests_renkan.py Tue May 03 14:32:28 2016 +0200 @@ -25,44 +25,47 @@ post_response = self.client.post(post_url, data, format="json") self.test_workspace_guid = json.loads(post_response.content.decode()).get("id") self.first_test_title = "test_title_1" - self.first_test_content = json.dumps({ + self.first_test_content_dict = { "id": "", "title": "test_title_1", "description": "test_description_1", - "created": "", - "updated": "", + "created": "2016-03-11 15:10:10.645193+00:00", + "updated": "2016-03-11 15:10:10.645193+00:00", "edges": [], "nodes": [], "users": [], "space_id": "", "views": [] - }) - self.second_test_title = "test_title_1" - self.second_test_content = json.dumps({ + } + self.first_test_content = json.dumps(self.first_test_content_dict) + self.second_test_title = "test_title_2" + self.second_test_content_dict = { "id": "", "title": "test_title_2", "description": "test_description_2", - "created": "", - "updated": "", + "created": "2016-03-11 15:10:10.645193+00:00", + "updated": "2016-03-12 15:10:10.645193+00:00", "edges": [], "nodes": [], "users": [], "space_id": "", "views": [] - }) - self.third_test_title = "test_title_1" - self.third_test_content = json.dumps({ + } + self.second_test_content = json.dumps(self.second_test_content_dict) + self.third_test_title = "test_title_3" + self.third_test_content_dict = { "id": "", "title": "test_title_3", "description": "test_description_3", - "created": "", - "updated": "", + "created": "2016-03-11 15:10:10.645193+00:00", + "updated": "2016-03-13 15:10:10.645193+00:00", "edges": [], "nodes": [], "users": [], "space_id": "", "views": [] - }) + } + self.third_test_content = json.dumps(self.third_test_content_dict) def test_create_renkan(self): @@ -80,6 +83,7 @@ # Checking POSTed Renkan data post_response_dict = json.loads(post_response.content.decode()) + post_response_content_dict = json.loads(post_response_dict.get("content", "{}")) new_renkan_guid = post_response_dict.get("id", "") new_renkan = Renkan.objects.get(renkan_guid=new_renkan_guid) # GUIDs and username @@ -88,7 +92,11 @@ self.assertEqual(getattr(self.user, User.USERNAME_FIELD), getattr(new_renkan.creator, User.USERNAME_FIELD)) # Content and title extracted from revision self.assertEqual(new_renkan.title, self.first_test_title) - self.assertEqual(new_renkan.content, self.first_test_content) + new_renkan_content_dict = json.loads(new_renkan.content) + for key in list(self.first_test_content_dict.keys()) + list(set(new_renkan_content_dict.keys()) - set(self.first_test_content_dict.keys())): + if key != "updated" and key != "created" and key != "id": + self.assertEqual(new_renkan_content_dict.get(key, ""), self.first_test_content_dict.get(key, "")) + # Revision count self.assertEqual(new_renkan.revision_count, 1) self.assertEqual(post_response_dict.get("revision_count", ""), 1) @@ -102,10 +110,16 @@ # Title and content # in the response self.assertEqual(post_response_dict.get("title", ""), self.first_test_title) - self.assertEqual(post_response_dict.get("content", ""), self.first_test_content) + for key in list(self.first_test_content_dict.keys()) + list(set(post_response_content_dict.keys()) - set(self.first_test_content_dict.keys())): + if key != "updated" and key != "created" and key != "id": + self.assertEqual(post_response_content_dict.get(key, ""), self.first_test_content_dict.get(key, "")) + # in the database self.assertEqual(new_renkan_revision.title, self.first_test_title) - self.assertEqual(new_renkan_revision.content, self.first_test_content) + new_revision_content_dict = json.loads(new_renkan_revision.content) + for key in list(self.first_test_content_dict.keys()) + list(set(new_revision_content_dict.keys()) - set(self.first_test_content_dict.keys())): + if key != "updated" and key != "created" and key != "id": + self.assertEqual(new_revision_content_dict.get(key, ""), self.first_test_content_dict.get(key, "")) # Checking permission self.assertTrue(self.user.has_perm("view_renkan", new_renkan)) @@ -128,13 +142,17 @@ new_renkan = Renkan.objects.get(renkan_guid=new_renkan_guid) # GUIDs and username self.assertEqual(self.test_workspace_guid, post_response_dict.get("workspace_id", "")) - self.assertEqual(self.test_workspace_guid, new_renkan.workspace_guid) + self.assertEqual(self.test_workspace_guid, new_renkan.workspace.workspace_guid) self.assertEqual(getattr(self.user, User.USERNAME_FIELD), post_response_dict.get("created_by", "")) self.assertEqual(getattr(self.user, User.USERNAME_FIELD), post_response_dict.get("last_updated_by", "")) self.assertEqual(getattr(self.user, User.USERNAME_FIELD), getattr(new_renkan.creator, User.USERNAME_FIELD)) # Content and title extracted from revision self.assertEqual(new_renkan.title, self.second_test_title) - self.assertEqual(new_renkan.content, self.second_test_content) + new_renkan_content_dict = json.loads(new_renkan.content) + for key in list(self.second_test_content_dict.keys()) + list(set(new_renkan_content_dict.keys()) - set(self.second_test_content_dict.keys())): + if key != "updated" and key != "created" and key != "id" and key != "space_id": + self.assertEqual(new_renkan_content_dict.get(key, ""), self.second_test_content_dict.get(key, "")) + # Revision count self.assertEqual(new_renkan.revision_count, 1) self.assertEqual(post_response_dict.get("revision_count", ""), 1) @@ -161,6 +179,16 @@ self.assertEqual(post_response.status_code, status.HTTP_404_NOT_FOUND) ################################################### + # POSTing with non-JSON serializable content + ################################################### + + post_url = reverse("v1.0:renkan_list") + data = {"title": self.third_test_title, "content": "notJson(Serializable}"} + + post_response = self.client.post(post_url, data, format="json") + self.assertEqual(post_response.status_code, status.HTTP_400_BAD_REQUEST) + + ################################################### # try POSTing with unauthorized user ################################################### @@ -259,6 +287,9 @@ self.assertTrue(isinstance(get_response_content, list)) self.assertEqual(len(get_response_content), 1) + + + def test_update_renkan(self): @@ -270,50 +301,66 @@ data = {} post_response = self.client.post(post_url, data, format="json") post_response_dict = json.loads(post_response.content.decode()) + post_response_ts = json.loads(post_response_dict.get("content"), "{}").get("updated", "") renkan_guid = post_response_dict.get("id", "") revision_guid = post_response_dict.get("current_revision_id", "") - + ################################################### # PUTting by updating current revision ################################################### put_url = reverse("v1.0:renkan_detail", kwargs={"renkan_guid": renkan_guid}) + put_content_dict = json.loads(self.first_test_content) + put_content_dict["updated"] = post_response_ts put_data = { "title" : self.first_test_title, - "content" : self.first_test_content, + "content" : json.dumps(put_content_dict), "create_new_revision": False } put_response = self.client.put(put_url, put_data, format="json") self.assertEqual(put_response.status_code, status.HTTP_200_OK) put_response_dict = json.loads(put_response.content.decode()) + put_response_content_dict = json.loads(put_response_dict.get("content", "{}")) + put_response_ts = put_response_content_dict.get("updated", "") + # checking we"re still on the same revision as the initial one updated_project = Renkan.objects.get(renkan_guid=renkan_guid) self.assertEqual(revision_guid, put_response_dict.get("current_revision_id", "")) self.assertEqual(put_response_dict.get("revision_count", ""), 1) self.assertEqual(updated_project.revision_count, 1) - self.assertEqual(revision_guid, updated_project.current_revision_guid) + self.assertEqual(revision_guid, updated_project.current_revision.revision_guid) # checking data was updated # in the reponse self.assertEqual(put_response_dict.get("title", ""), self.first_test_title) - self.assertEqual(put_response_dict.get("content", ""), self.first_test_content) + for key in list(self.first_test_content_dict.keys()) + list(set(put_response_content_dict.keys()) - set(self.first_test_content_dict.keys())): + if key != "updated" and key!= "id" and key != "space_id": + self.assertEqual(put_response_content_dict.get(key, ""), self.first_test_content_dict.get(key, "")) + # in the database updated_revision = Revision.objects.get(revision_guid=revision_guid) + updated_revision_content_dict = json.loads(updated_revision.content) self.assertEqual(updated_revision.title, self.first_test_title) - self.assertEqual(updated_revision.content, self.first_test_content) + for key in list(self.first_test_content_dict.keys()) + list(set(updated_revision_content_dict.keys()) - set(self.first_test_content_dict.keys())): + if key != "updated" and key!= "id" and key != "space_id": + self.assertEqual(updated_revision_content_dict.get(key, ""), self.first_test_content_dict.get(key, "")) ################################################### # PUTting by creating a new revision ################################################### + put_content_dict = json.loads(self.second_test_content) + put_content_dict["updated"] = put_response_ts put_data = { "title" : self.second_test_title, - "content" : self.second_test_content, + "content" : json.dumps(put_content_dict), "create_new_revision": True } put_response = self.client.put(put_url, put_data, format="json") - self.assertEqual(put_response.status_code, status.HTTP_200_OK) + self.assertEqual(put_response.status_code, status.HTTP_200_OK) put_response_dict = json.loads(put_response.content.decode()) + put_response_content_dict = json.loads(put_response_dict.get("content", "{}")) + put_response_ts = put_response_content_dict.get("updated", "") # checking we created a new revision updated_project = Renkan.objects.get(renkan_guid=renkan_guid) @@ -325,15 +372,20 @@ self.assertEqual(updated_project.revision_count, 2) # checking project now points towards new revision - self.assertEqual(updated_project.current_revision_guid, created_revision_guid) + self.assertEqual(updated_project.current_revision.revision_guid, created_revision_guid) # checking data was updated # in the reponse self.assertEqual(put_response_dict.get("title", ""), self.second_test_title) - self.assertEqual(put_response_dict.get("content", ""), self.second_test_content) + for key in list(self.second_test_content_dict.keys()) + list(set(put_response_content_dict.keys()) - set(self.second_test_content_dict.keys())): + if key != "updated" and key!= "id" and key != "space_id": + self.assertEqual(put_response_content_dict.get(key, ""), self.second_test_content_dict.get(key, "")) # in the database updated_revision = Revision.objects.get(revision_guid=created_revision_guid) + updated_revision_content_dict = json.loads(updated_revision.content) self.assertEqual(updated_revision.title, self.second_test_title) - self.assertEqual(updated_revision.content, self.second_test_content) + for key in list(self.second_test_content_dict.keys()) + list(set(updated_revision_content_dict.keys()) - set(self.second_test_content_dict.keys())): + if key != "updated" and key!= "id" and key != "space_id": + self.assertEqual(updated_revision_content_dict.get(key, ""), self.second_test_content_dict.get(key, "")) ################################################### # try to update source_revision_guid or workspace_guid @@ -347,14 +399,6 @@ put_response = self.client.put(put_url, put_data, format="json") self.assertEqual(put_response.status_code, status.HTTP_400_BAD_REQUEST) - put_data = { - "title" : self.third_test_title, - "content" : self.third_test_content, - "source_revision_id" : "bleh-revision-guid" # should fail without even checking the id - } - put_response = self.client.put(put_url, put_data, format="json") - self.assertEqual(put_response.status_code, status.HTTP_400_BAD_REQUEST) - ################################################### # PUTting with wrong guid ################################################### @@ -398,6 +442,7 @@ first_copy_url = post_url+"?source_renkan_id="+source_renkan_guid first_copy_response = self.client.post(first_copy_url, first_copy_data, format="json") first_copy_response_dict = json.loads(first_copy_response.content.decode()) + first_copy_response_content_dict = json.loads(first_copy_response_dict.get("content", "{}")) self.assertEqual(first_copy_response.status_code, status.HTTP_201_CREATED) self.assertEqual(Renkan.objects.count(), 2) # Checking data @@ -405,16 +450,20 @@ self.assertNotEqual(first_copy_response_dict.get("id"), source_renkan_guid) self.assertEqual(first_copy_response_dict.get("source_revision_id"), source_revision_guid) self.assertEqual(first_copy_response_dict.get("title", ""), "new_title_copy_1") - self.assertEqual(first_copy_response_dict.get("content", ""), self.first_test_content) + for key in list(self.first_test_content_dict.keys()) + list(set(first_copy_response_content_dict.keys()) - set(self.first_test_content_dict.keys())): + if key != "updated" and key != "created" and key !="title" and key!= "id" and key != "space_id": + self.assertEqual(first_copy_response_content_dict.get(key, ""), self.first_test_content_dict.get(key, "")) self.assertEqual(first_copy_response_dict.get("created_by", ""), getattr(self.user, User.USERNAME_FIELD)) self.assertEqual(first_copy_response_dict.get("last_updated_by", ""), getattr(self.user, User.USERNAME_FIELD)) # in the database first_copy = Renkan.objects.get(renkan_guid=first_copy_response_dict.get("id", "")) first_copy_revision = Revision.objects.get(revision_guid=first_copy_response_dict.get("current_revision_id", "")) self.assertEqual(first_copy.title, "new_title_copy_1") - self.assertEqual(first_copy.content, self.first_test_content) self.assertEqual(first_copy_revision.title, "new_title_copy_1") - self.assertEqual(first_copy_revision.content, self.first_test_content) + first_copy_revision_content_dict = json.loads(first_copy_revision.content) + for key in list(self.first_test_content_dict.keys()) + list(set(first_copy_revision_content_dict.keys()) - set(self.first_test_content_dict.keys())): + if key != "updated" and key != "created" and key!= "id" and key != "space_id": + self.assertEqual(first_copy_revision_content_dict.get(key, ""), self.first_test_content_dict.get(key, "")) self.assertEqual(getattr(first_copy.creator, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD)) self.assertEqual(getattr(first_copy_revision.creator, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD)) self.assertEqual(getattr(first_copy_revision.last_updated_by, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD)) @@ -427,6 +476,7 @@ second_copy_url = post_url second_copy_response = self.client.post(second_copy_url, second_copy_data, format="json") second_copy_response_dict = json.loads(second_copy_response.content.decode()) + second_copy__response_content_dict = json.loads(second_copy_response_dict.get("content", "{}")) self.assertEqual(second_copy_response.status_code, status.HTTP_201_CREATED) self.assertEqual(Renkan.objects.count(), 3) # Checking data @@ -434,16 +484,20 @@ self.assertNotEqual(second_copy_response_dict.get("id"), source_renkan_guid) self.assertEqual(second_copy_response_dict.get("source_revision_id"), source_revision_guid) self.assertEqual(second_copy_response_dict.get("title", ""), "new_title_copy_2") - self.assertEqual(second_copy_response_dict.get("content", ""), self.first_test_content) + for key in list(self.first_test_content_dict.keys()) + list(set(second_copy__response_content_dict.keys()) - set(self.first_test_content_dict.keys())): + if key != "updated" and key != "created" and key!= "id" and key != "space_id": + self.assertEqual(second_copy__response_content_dict.get(key, ""), self.first_test_content_dict.get(key, "")) self.assertEqual(second_copy_response_dict.get("created_by", ""), getattr(self.user, User.USERNAME_FIELD)) self.assertEqual(second_copy_response_dict.get("last_updated_by", ""), getattr(self.user, User.USERNAME_FIELD)) # in the database second_copy = Renkan.objects.get(renkan_guid=second_copy_response_dict.get("id", "")) second_copy_revision = Revision.objects.get(revision_guid=second_copy_response_dict.get("current_revision_id", "")) self.assertEqual(second_copy.title, "new_title_copy_2") - self.assertEqual(second_copy.content, self.first_test_content) self.assertEqual(second_copy_revision.title, "new_title_copy_2") - self.assertEqual(second_copy_revision.content, self.first_test_content) + second_copy_revision_content_dict = json.loads(second_copy_revision.content) + for key in list(self.first_test_content_dict.keys()) + list(set(second_copy_revision_content_dict.keys()) - set(self.first_test_content_dict.keys())): + if key != "updated" and key != "created" and key!= "id" and key != "space_id": + self.assertEqual(second_copy_revision_content_dict.get(key, ""), self.first_test_content_dict.get(key, "")) self.assertEqual(getattr(second_copy.creator, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD)) self.assertEqual(getattr(second_copy_revision.creator, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD)) self.assertEqual(getattr(second_copy_revision.last_updated_by, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD)) @@ -456,6 +510,7 @@ third_copy_url = post_url+"?source_revision_id="+source_revision_guid third_copy_response = self.client.post(third_copy_url, third_copy_data, format="json") third_copy_response_dict = json.loads(third_copy_response.content.decode()) + third_copy_response_content_dict = json.loads(third_copy_response_dict.get("content", "{}")) self.assertEqual(third_copy_response.status_code, status.HTTP_201_CREATED) self.assertEqual(Renkan.objects.count(), 4) # Checking data @@ -463,16 +518,20 @@ self.assertNotEqual(third_copy_response_dict.get("id"), source_renkan_guid) self.assertEqual(third_copy_response_dict.get("source_revision_id"), source_revision_guid) self.assertEqual(third_copy_response_dict.get("title", ""), "new_title_copy_3") - self.assertEqual(third_copy_response_dict.get("content", ""), self.first_test_content) + for key in list(self.first_test_content_dict.keys()) + list(set(third_copy_response_content_dict.keys()) - set(self.first_test_content_dict.keys())): + if key != "updated" and key != "created" and key!= "id" and key != "space_id": + self.assertEqual(third_copy_response_content_dict.get(key, ""), self.first_test_content_dict.get(key, "")) self.assertEqual(third_copy_response_dict.get("created_by", ""), getattr(self.user, User.USERNAME_FIELD)) self.assertEqual(third_copy_response_dict.get("last_updated_by", ""), getattr(self.user, User.USERNAME_FIELD)) # in the database third_copy = Renkan.objects.get(renkan_guid=third_copy_response_dict.get("id", "")) third_copy_revision = Revision.objects.get(revision_guid=third_copy_response_dict.get("current_revision_id", "")) + third_copy_revision_content_dict = json.loads(third_copy_revision.content) self.assertEqual(third_copy.title, "new_title_copy_3") - self.assertEqual(third_copy.content, self.first_test_content) self.assertEqual(third_copy_revision.title, "new_title_copy_3") - self.assertEqual(third_copy_revision.content, self.first_test_content) + for key in list(self.first_test_content_dict.keys()) + list(set(third_copy_revision_content_dict.keys()) - set(self.first_test_content_dict.keys())): + if key != "updated" and key != "created" and key!= "id" and key != "space_id": + self.assertEqual(third_copy_revision_content_dict.get(key, ""), self.first_test_content_dict.get(key, "")) self.assertEqual(getattr(third_copy.creator, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD)) self.assertEqual(getattr(third_copy_revision.creator, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD)) self.assertEqual(getattr(third_copy_revision.last_updated_by, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD)) @@ -485,6 +544,7 @@ fourth_copy_url = post_url fourth_copy_response = self.client.post(fourth_copy_url, fourth_copy_data, format="json") fourth_copy_response_dict = json.loads(fourth_copy_response.content.decode()) + fourth_copy_response_content_dict = json.loads(fourth_copy_response_dict.get("content", "{}")) self.assertEqual(fourth_copy_response.status_code, status.HTTP_201_CREATED) self.assertEqual(Renkan.objects.count(), 5) # Checking data @@ -492,16 +552,20 @@ self.assertNotEqual(fourth_copy_response_dict.get("id"), source_renkan_guid) self.assertEqual(fourth_copy_response_dict.get("source_revision_id"), source_revision_guid) self.assertEqual(fourth_copy_response_dict.get("title", ""), self.first_test_title) - self.assertEqual(fourth_copy_response_dict.get("content", ""), self.first_test_content) + for key in list(self.first_test_content_dict.keys()) + list(set(fourth_copy_response_content_dict.keys()) - set(self.first_test_content_dict.keys())): + if key != "updated" and key != "created" and key!= "id" and key != "space_id": + self.assertEqual(fourth_copy_response_content_dict.get(key, ""), self.first_test_content_dict.get(key, "")) self.assertEqual(fourth_copy_response_dict.get("created_by", ""), getattr(self.user, User.USERNAME_FIELD)) self.assertEqual(fourth_copy_response_dict.get("last_updated_by", ""), getattr(self.user, User.USERNAME_FIELD)) # in the database fourth_copy = Renkan.objects.get(renkan_guid=fourth_copy_response_dict.get("id", "")) fourth_copy_revision = Revision.objects.get(revision_guid=fourth_copy_response_dict.get("current_revision_id", "")) self.assertEqual(fourth_copy.title, self.first_test_title) - self.assertEqual(fourth_copy.content, self.first_test_content) self.assertEqual(fourth_copy_revision.title, self.first_test_title) - self.assertEqual(fourth_copy_revision.content, self.first_test_content) + fourth_copy_revision_content_dict = json.loads(fourth_copy_revision.content) + for key in list(self.first_test_content_dict.keys()) + list(set(fourth_copy_revision_content_dict.keys()) - set(self.first_test_content_dict.keys())): + if key != "updated" and key != "created" and key!= "id" and key != "space_id": + self.assertEqual(fourth_copy_revision_content_dict.get(key, ""), self.first_test_content_dict.get(key, "")) self.assertEqual(getattr(fourth_copy.creator, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD)) self.assertEqual(getattr(fourth_copy_revision.creator, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD)) self.assertEqual(getattr(fourth_copy_revision.last_updated_by, User.USERNAME_FIELD), getattr(self.user, User.USERNAME_FIELD)) @@ -542,6 +606,7 @@ post_response_dict = json.loads(post_response.content.decode()) to_delete_renkan_guid = post_response_dict.get("id", "") to_delete_revision_guid = post_response_dict.get("current_revision_id", "") + to_delete_renkan_ts = json.loads(post_response_dict.get("content", "")).get("updated", "") ################################################### # POSTing copy @@ -552,7 +617,7 @@ copy_renkan_guid = post_response_dict.get("id", "") # Adding another revision - put_data = {"title": self.first_test_title+"_edited!", "create_new_revision": True} + put_data = {"title": self.first_test_title+"_edited!", "validation_timestamp": to_delete_renkan_ts, "create_new_revision": True} put_url = reverse("v1.0:renkan_detail", kwargs={"renkan_guid":to_delete_renkan_guid}) put_response = self.client.put(put_url, put_data, format="json") self.assertEqual(Renkan.objects.count(), 2) @@ -592,7 +657,7 @@ # Check that remaining renkan doesn"t have reference to deleted renkan ################################################### copy_renkan = Renkan.objects.get(renkan_guid=copy_renkan_guid) - self.assertEqual(copy_renkan.source_revision_guid, "") + self.assertIsNone(copy_renkan.source_revision) ################################################### # Try to DELETE renkan with wrong guid