diff --git a/SAS/TMSS/CMakeLists.txt b/SAS/TMSS/CMakeLists.txt index b41d67a1d9df1b8a505a793a8485e69c78e30df9..381203a5a5187bb7dacbbf811da8f1bd71df4580 100644 --- a/SAS/TMSS/CMakeLists.txt +++ b/SAS/TMSS/CMakeLists.txt @@ -5,6 +5,6 @@ lofar_package(TMSS 0.1 DEPENDS PyCommon pyparameterset) add_subdirectory(src) add_subdirectory(bin) add_subdirectory(test) -add_subdirectory(frontend) +# GOEI effe niet add_subdirectory(frontend) lofar_add_docker_files(docker-compose-tmss.yml) diff --git a/SAS/TMSS/test/t_subtask_validation.py b/SAS/TMSS/test/t_subtask_validation.py index 80b562af61ce3956a03ddc231ef59fbe93aa1c9e..c20c88b61703f4847ea45ca8528d152f4a81d870 100755 --- a/SAS/TMSS/test/t_subtask_validation.py +++ b/SAS/TMSS/test/t_subtask_validation.py @@ -151,7 +151,7 @@ class SubtaskValidationTest(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask/', subtask_test_data, 201, subtask_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, subtask_test_data) + GET_and_assert_equal_expected_response(self, url, 200, subtask_test_data) def test_validate_simple_string_schema_with_invalid_specification_via_rest(self): template = rest_data_creator.SubtaskTemplate(schema='{"type": "string"}') @@ -183,7 +183,7 @@ class SubtaskValidationTest(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask/', subtask_test_data, 201, subtask_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, subtask_test_data) + GET_and_assert_equal_expected_response(self, url, 200, subtask_test_data) def test_validate_correlator_schema_with_invalid_specification_via_rest(self): # fetch correlator_schema for Dupplo UC1 which should be in the initially populated database diff --git a/SAS/TMSS/test/t_tmssapp_scheduling_django.py b/SAS/TMSS/test/t_tmssapp_scheduling_django.py index 28bdfefadbe5b2c11567f73c26fc8aa8bd167306..9fa9a987f1e380d231159f80a43897d0c6435be9 100755 --- a/SAS/TMSS/test/t_tmssapp_scheduling_django.py +++ b/SAS/TMSS/test/t_tmssapp_scheduling_django.py @@ -41,10 +41,6 @@ from lofar.sas.tmss.test.tmss_test_data_django_models import * from django.db.utils import IntegrityError -# TODO: rest API testing should be moved out of this test module. -# import rest_framework.test -# client = rest_framework.test.APIClient() -# from lofar.sas.tmss.test.test_utils import assertDataWithUrls, assertUrlList class SubtaskTemplateTest(unittest.TestCase): def test_SubtaskTemplate_gets_created_with_correct_creation_timestamp(self): @@ -71,32 +67,6 @@ class SubtaskTemplateTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_SubtaskTemplate_list_view_shows_entry(self): - # - # # setup - # entry = models.SubtaskTemplate.objects.create(**self.get_test_data()) - # - # # assert - # response = client.get('/subtask_template/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data['results'][0], self.get_test_data()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_SubtaskTemplate_view_returns_correct_entry(self): - # - # # setup - # id1 = models.SubtaskTemplate.objects.create(**self.get_test_data()).id - # id2 = models.SubtaskTemplate.objects.create(**self.get_test_data()).id - # - # # assert - # response1 = client.get('/subtask_template/%s/' % id1, format='json', follow=True) - # response2 = client.get('/subtask_template/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, self.get_test_data()) - # assertDataWithUrls(self, response2.data, self.get_test_data()) - class DataproductSpecificationsTemplateTest(unittest.TestCase): @@ -124,35 +94,6 @@ class DataproductSpecificationsTemplateTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_DataproductSpecificationsTemplate_list_view_shows_entry(self): - # - # # setup - # entry = models.DataproductSpecificationsTemplate.objects.create(**self.get_test_data()) - # - # # assert - # response = client.get('/dataproduct_specifications_template/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # for item in self.get_test_data().items(): - # self.assertIn(item, response.data['results'][0].items()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_DataproductSpecificationsTemplate_view_returns_correct_entry(self): - # - # # setup - # id1 = models.DataproductSpecificationsTemplate.objects.create(**self.get_test_data()).id - # id2 = models.DataproductSpecificationsTemplate.objects.create(**self.get_test_data()).id - # - # # assert - # response1 = client.get('/dataproduct_specifications_template/%s/' % id1, format='json', follow=True) - # response2 = client.get('/dataproduct_specifications_template/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # for item in self.get_test_data().items(): - # self.assertIn(item, response1.data.items()) - # for item in self.get_test_data().items(): - # self.assertIn(item, response2.data.items()) - class SubtaskInputSelectionTemplateTest(unittest.TestCase): # This currently adds nothing on top of the template base class, so nothing new to test here. @@ -188,31 +129,6 @@ class SubtaskOutputTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_SubtaskOutput_list_view_shows_entry(self): - # # setup - # models.SubtaskOutput.objects.create(**SubtaskOutput_test_data()) - # - # # assert - # response = client.get('/subtask_output/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data['results'][0], SubtaskOutput_test_data()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_SubtaskOutput_view_returns_correct_entry(self): - # # setup - # id1 = models.SubtaskOutput.objects.create(**SubtaskOutput_test_data()).id - # id2 = models.SubtaskOutput.objects.create(**SubtaskOutput_test_data()).id - # - # # assert - # response1 = client.get('/subtask_output/%s/' % id1, format='json', follow=True) - # response2 = client.get('/subtask_output/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, SubtaskOutput_test_data()) - # assertDataWithUrls(self, response2.data, SubtaskOutput_test_data()) - - def test_SubtaskOutput_prevents_missing_subtask(self): # setup @@ -249,31 +165,6 @@ class SubtaskInputTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_SubtaskInput_list_view_shows_entry(self): - # # setup - # models.SubtaskInput.objects.create(**SubtaskInput_test_data()) - # - # # assert - # response = client.get('/subtask_input/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data['results'][0], SubtaskInput_test_data()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_SubtaskInput_view_returns_correct_entry(self): - # # setup - # id1 = models.SubtaskInput.objects.create(**SubtaskInput_test_data()).id - # id2 = models.SubtaskInput.objects.create(**SubtaskInput_test_data()).id - # - # # assert - # response1 = client.get('/subtask_input/%s/' % id1, format='json', follow=True) - # response2 = client.get('/subtask_input/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, SubtaskInput_test_data()) - # assertDataWithUrls(self, response2.data, SubtaskInput_test_data()) - - def test_SubtaskInput_prevents_missing_subtask(self): # setup @@ -285,20 +176,6 @@ class SubtaskInputTest(unittest.TestCase): models.SubtaskInput.objects.create(**test_data) - # TODO: rest API testing should be moved out of this test module. - # def test_SubtaskInput_allows_setting_dataproducts(self): - # # Other then through the API view, we cannot assign ManyToMany on creation, but have to set it later - # si = models.SubtaskInput.objects.create(**SubtaskInput_test_data()) - # si.dataproducts.set([models.Dataproduct.objects.create(**Dataproduct_test_data()), - # models.Dataproduct.objects.create(**Dataproduct_test_data())]) - # si.save() - # - # # assert - # response = client.get('/subtask_input/%s' % si.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data, SubtaskInput_test_data()) - - class SubtaskTest(unittest.TestCase): def test_Subtask_gets_created_with_correct_creation_timestamp(self): @@ -324,32 +201,6 @@ class SubtaskTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_Subtask_list_view_shows_entry(self): - # - # # setup - # entry = models.Subtask.objects.create(**Subtask_test_data()) - # - # # assert - # response = client.get('/subtask/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data['results'][0], Subtask_test_data()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_Subtask_view_returns_correct_entry(self): - # - # # setup - # id1 = models.Subtask.objects.create(**Subtask_test_data()).id - # id2 = models.Subtask.objects.create(**Subtask_test_data()).id - # - # # assert - # response1 = client.get('/subtask/%s/' % id1, format='json', follow=True) - # response2 = client.get('/subtask/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, Subtask_test_data()) - # assertDataWithUrls(self, response2.data, Subtask_test_data()) - def test_Subtask_prevents_missing_template(self): # setup @@ -360,37 +211,6 @@ class SubtaskTest(unittest.TestCase): with self.assertRaises(IntegrityError): models.Subtask.objects.create(**test_data) - # TODO: rest API testing should be moved out of this test module. - # def test_nested_Subtask_are_filtered_according_to_TaskBlueprint(self): - # tbt = TaskBlueprintTest() - # tbt.setUp(populate=False) - # - # # setup - # task_blueprint_1 = models.TaskBlueprint.objects.create(**tbt.get_test_data()) - # task_blueprint_2 = models.TaskBlueprint.objects.create(**tbt.get_test_data()) - # test_data_1 = dict(Subtask_test_data()) - # test_data_1['task_blueprint'] = task_blueprint_1 - # subtask_1 = models.Subtask.objects.create(**test_data_1) - # test_data_2 = dict(Subtask_test_data()) - # test_data_2['task_blueprint'] = task_blueprint_2 - # subtask_2 = models.Subtask.objects.create(**test_data_2) - # - # # assert the returned list contains related items - # response = client.get('/task_blueprint/%s/subtask/' % task_blueprint_2.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # self.assertEqual(len(response.data['results']), 1) - # assertDataWithUrls(self, response.data['results'][0], test_data_2) - # - # # assert an existing related item is returned - # response = client.get( - # '/task_blueprint/%s/subtask/%s/' % (task_blueprint_2.id, subtask_2.id), format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data, test_data_2) - # - # # assert an existing unrelated item is not returned - # response = client.get( '/task_blueprint/%s/subtask/%s/' % (task_blueprint_2.id, subtask_1.id), format='json', follow=True) - # self.assertEqual(response.status_code, 404) - class DataproductTest(unittest.TestCase): def test_Dataproduct_gets_created_with_correct_creation_timestamp(self): @@ -417,31 +237,6 @@ class DataproductTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_Dataproduct_list_view_shows_entry(self): - # - # # setup - # entry = models.Dataproduct.objects.create(**Dataproduct_test_data()) - # - # # assert - # response = client.get('/dataproduct/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data['results'][0], Dataproduct_test_data()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_Dataproduct_view_returns_correct_entry(self): - # - # # setup - # id1 = models.Dataproduct.objects.create(**Dataproduct_test_data()).id - # id2 = models.Dataproduct.objects.create(**Dataproduct_test_data()).id - # - # # assert - # response1 = client.get('/dataproduct/%s/' % id1, format='json', follow=True) - # response2 = client.get('/dataproduct/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, Dataproduct_test_data()) - # assertDataWithUrls(self, response2.data, Dataproduct_test_data()) def test_Dataproduct_prevents_missing_specifications_template(self): @@ -479,45 +274,6 @@ class SubtaskConnectorTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_SubtaskConnector_list_view_shows_entry(self): - # # setup - # models.SubtaskConnector.objects.create(**SubtaskConnector_test_data()) - # - # # assert - # response = client.get('/subtask_connector/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data['results'][0], SubtaskConnector_test_data()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_SubtaskConnector_view_returns_correct_entry(self): - # # setup - # id1 = models.SubtaskConnector.objects.create(**SubtaskConnector_test_data()).id - # id2 = models.SubtaskConnector.objects.create(**SubtaskConnector_test_data()).id - # - # # assert - # response1 = client.get('/subtask_connector/%s/' % id1, format='json', follow=True) - # response2 = client.get('/subtask_connector/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, SubtaskConnector_test_data()) - # assertDataWithUrls(self, response2.data, SubtaskConnector_test_data()) - - # TODO: rest API testing should be moved out of this test module. - # def test_SubtaskConnector_allows_setting_dataformats(self): - # # Other then through the API view, we cannot assign ManyToMany on creation, but have to set it later - # - # test_data_1 = dict(SubtaskConnector_test_data()) - # test_data_1['inputs'] = None - # tior = models.SubtaskConnector.objects.create(**SubtaskConnector_test_data()) - # tior.dataformats.set([models.Dataformat.objects.get(value='Beamformed'), - # models.Dataformat.objects.get(value='MeasurementSet')]) - # tior.save() - # - # # assert - # response = client.get('/subtask_connector/%s' % tior.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data, SubtaskConnector_test_data()) class AntennaSetTest(unittest.TestCase): def test_AntennaSet_gets_created_with_correct_creation_timestamp(self): @@ -544,30 +300,6 @@ class AntennaSetTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_AntennaSet_list_view_shows_entry(self): - # # setup - # models.AntennaSet.objects.create(**AntennaSet_test_data()) - # - # # assert - # response = client.get('/antenna_set/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data['results'][0], AntennaSet_test_data()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_AntennaSet_view_returns_correct_entry(self): - # # setup - # id1 = models.AntennaSet.objects.create(**AntennaSet_test_data()).id - # id2 = models.AntennaSet.objects.create(**AntennaSet_test_data()).id - # - # # assert - # response1 = client.get('/antenna_set/%s/' % id1, format='json', follow=True) - # response2 = client.get('/antenna_set/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, AntennaSet_test_data()) - # assertDataWithUrls(self, response2.data, AntennaSet_test_data()) - class DataproductTransformTest(unittest.TestCase): def test_DataproductTransform_gets_created_with_correct_creation_timestamp(self): @@ -594,30 +326,6 @@ class DataproductTransformTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_DataproductTransform_list_view_shows_entry(self): - # # setup - # models.DataproductTransform.objects.create(**DataproductTransform_test_data()) - # - # # assert - # response = client.get('/dataproduct_transform/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data['results'][0], DataproductTransform_test_data()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_DataproductTransform_view_returns_correct_entry(self): - # # setup - # id1 = models.DataproductTransform.objects.create(**DataproductTransform_test_data()).id - # id2 = models.DataproductTransform.objects.create(**DataproductTransform_test_data()).id - # - # # assert - # response1 = client.get('/dataproduct_transform/%s/' % id1, format='json', follow=True) - # response2 = client.get('/dataproduct_transform/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, DataproductTransform_test_data()) - # assertDataWithUrls(self, response2.data, DataproductTransform_test_data()) - class FilesystemTest(unittest.TestCase): def test_Filesystem_gets_created_with_correct_creation_timestamp(self): @@ -644,30 +352,6 @@ class FilesystemTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_Filesystem_list_view_shows_entry(self): - # # setup - # models.Filesystem.objects.create(**Filesystem_test_data()) - # - # # assert - # response = client.get('/filesystem/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data['results'][0], Filesystem_test_data()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_Filesystem_view_returns_correct_entry(self): - # # setup - # id1 = models.Filesystem.objects.create(**Filesystem_test_data()).id - # id2 = models.Filesystem.objects.create(**Filesystem_test_data()).id - # - # # assert - # response1 = client.get('/filesystem/%s/' % id1, format='json', follow=True) - # response2 = client.get('/filesystem/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, Filesystem_test_data()) - # assertDataWithUrls(self, response2.data, Filesystem_test_data()) - class ClusterTest(unittest.TestCase): def test_Cluster_gets_created_with_correct_creation_timestamp(self): @@ -693,30 +377,6 @@ class ClusterTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_Cluster_list_view_shows_entry(self): - # # setup - # models.Cluster.objects.create(**Cluster_test_data()) - # - # # assert - # response = client.get('/cluster/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data['results'][0], Cluster_test_data()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_Cluster_view_returns_correct_entry(self): - # # setup - # id1 = models.Cluster.objects.create(**Cluster_test_data()).id - # id2 = models.Cluster.objects.create(**Cluster_test_data()).id - # - # # assert - # response1 = client.get('/cluster/%s/' % id1, format='json', follow=True) - # response2 = client.get('/cluster/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, Cluster_test_data()) - # assertDataWithUrls(self, response2.data, Cluster_test_data()) - class DataproductArchiveInfoTest(unittest.TestCase): def test_DataproductArchiveInfo_gets_created_with_correct_creation_timestamp(self): @@ -743,30 +403,6 @@ class DataproductArchiveInfoTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_DataproductArchiveInfo_list_view_shows_entry(self): - # # setup - # models.DataproductArchiveInfo.objects.create(**DataproductArchiveInfo_test_data()) - # - # # assert - # response = client.get('/dataproduct_archive_info/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data['results'][0], DataproductArchiveInfo_test_data()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_DataproductArchiveInfo_view_returns_correct_entry(self): - # # setup - # id1 = models.DataproductArchiveInfo.objects.create(**DataproductArchiveInfo_test_data()).id - # id2 = models.DataproductArchiveInfo.objects.create(**DataproductArchiveInfo_test_data()).id - # - # # assert - # response1 = client.get('/dataproduct_archive_info/%s/' % id1, format='json', follow=True) - # response2 = client.get('/dataproduct_archive_info/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, DataproductArchiveInfo_test_data()) - # assertDataWithUrls(self, response2.data, DataproductArchiveInfo_test_data()) - class DataproductHashTest(unittest.TestCase): def test_DataproductHash_gets_created_with_correct_creation_timestamp(self): @@ -793,30 +429,6 @@ class DataproductHashTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_DataproductHash_list_view_shows_entry(self): - # # setup - # models.DataproductHash.objects.create(**DataproductHash_test_data()) - # - # # assert - # response = client.get('/dataproduct_hash/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data['results'][0], DataproductHash_test_data()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_DataproductHash_view_returns_correct_entry(self): - # # setup - # id1 = models.DataproductHash.objects.create(**DataproductHash_test_data()).id - # id2 = models.DataproductHash.objects.create(**DataproductHash_test_data()).id - # - # # assert - # response1 = client.get('/dataproduct_hash/%s/' % id1, format='json', follow=True) - # response2 = client.get('/dataproduct_hash/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, DataproductHash_test_data()) - # assertDataWithUrls(self, response2.data, DataproductHash_test_data()) - if __name__ == "__main__": os.environ['TZ'] = 'UTC' diff --git a/SAS/TMSS/test/t_tmssapp_scheduling_functional.py b/SAS/TMSS/test/t_tmssapp_scheduling_functional.py index 5fdef254a72ea722334f86c85ff296ca29325d45..0b4345a35d6069ecceb663fcdcd8d8bcc8cccf39 100755 --- a/SAS/TMSS/test/t_tmssapp_scheduling_functional.py +++ b/SAS/TMSS/test/t_tmssapp_scheduling_functional.py @@ -53,7 +53,7 @@ class SubtaskTemplateTestCase(unittest.TestCase): self.assertTrue("Subtask Template List" in r.content.decode('utf8')) def test_subtask_template_template_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/subtask_template/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/subtask_template/1234321/', 404, {}) def test_subtask_template_POST_and_GET(self): st_test_data = test_data_creator.SubtaskTemplate() @@ -61,7 +61,7 @@ class SubtaskTemplateTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_template/', st_test_data, 201, st_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, st_test_data) + GET_and_assert_equal_expected_response(self, url, 200, st_test_data) def test_subtask_template_PUT_invalid_raises_error(self): st_test_data = test_data_creator.SubtaskTemplate() @@ -74,11 +74,11 @@ class SubtaskTemplateTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_template/', st_test_data, 201, st_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, st_test_data) + GET_and_assert_equal_expected_response(self, url, 200, st_test_data) # PUT new values, verify PUT_and_assert_expected_response(self, url, st_test_data2, 200, st_test_data2) - GET_and_assert_expected_response(self, url, 200, st_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, st_test_data2) def test_subtask_template_PATCH(self): st_test_data = test_data_creator.SubtaskTemplate() @@ -86,7 +86,7 @@ class SubtaskTemplateTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_template/', st_test_data, 201, st_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, st_test_data) + GET_and_assert_equal_expected_response(self, url, 200, st_test_data) test_patch = {"type": BASE_URL + '/subtask_type/inspection/', "version": 'v6.28318530718', @@ -97,7 +97,7 @@ class SubtaskTemplateTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(st_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_subtask_template_DELETE(self): st_test_data = test_data_creator.SubtaskTemplate() @@ -105,7 +105,7 @@ class SubtaskTemplateTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_template/', st_test_data, 201, st_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, st_test_data) + GET_and_assert_equal_expected_response(self, url, 200, st_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -122,14 +122,32 @@ class SubtaskTemplateTestCase(unittest.TestCase): test_data = dict(st_test_data) test_data['type'] = type_url url = POST_and_assert_expected_response(self, BASE_URL + '/subtask_template/', test_data, 201, test_data)['url'] - GET_and_assert_expected_response(self, url, 200, test_data) + GET_and_assert_equal_expected_response(self, url, 200, test_data) # Try to DELETE dependency, verify that was not successful # Unfortunately we don't get a nice error in json, but a Django debug page on error 500... response = requests.delete(type_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, type_url, 200, type_data) + GET_and_assert_equal_expected_response(self, type_url, 200, type_data) + + def test_GET_SubtaskTemplate_list_view_shows_entry(self): + + test_data_1 = SubtaskTemplate_test_data() + models.SubtaskTemplate.objects.create(**test_data_1) + nbr_results = models.SubtaskTemplate.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/subtask_template/', test_data_1, nbr_results) + + def test_GET_SubtaskTemplate_view_returns_correct_entry(self): + + # setup + test_data_1 = SubtaskTemplate_test_data() + test_data_2 = SubtaskTemplate_test_data() + id1 = models.SubtaskTemplate.objects.create(**test_data_1).id + id2 = models.SubtaskTemplate.objects.create(**test_data_2).id + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/subtask_template/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/subtask_template/%s/' % id2, test_data_2) class DataproductSpecificationsTemplateTestCase(unittest.TestCase): @@ -139,7 +157,7 @@ class DataproductSpecificationsTemplateTestCase(unittest.TestCase): self.assertTrue("Dataproduct Specifications Template List" in r.content.decode('utf8')) def test_dataproduct_specifications_template_template_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/dataproduct_specifications_template/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/dataproduct_specifications_template/1234321/', 404, {}) def test_dataproduct_specifications_template_POST_and_GET(self): dst_test_data = test_data_creator.DataproductSpecificationsTemplate() @@ -147,7 +165,7 @@ class DataproductSpecificationsTemplateTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_specifications_template/', dst_test_data, 201, dst_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dst_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dst_test_data) def test_dataproduct_specifications_template_PUT_invalid_raises_error(self): dst_test_data = test_data_creator.DataproductSpecificationsTemplate() @@ -161,11 +179,11 @@ class DataproductSpecificationsTemplateTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_specifications_template/', dst_test_data, 201, dst_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dst_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dst_test_data) # PUT new values, verify PUT_and_assert_expected_response(self, url, dst_test_data2, 200, dst_test_data2) - GET_and_assert_expected_response(self, url, 200, dst_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, dst_test_data2) def test_dataproduct_specifications_template_PATCH(self): dst_test_data = test_data_creator.DataproductSpecificationsTemplate() @@ -173,7 +191,7 @@ class DataproductSpecificationsTemplateTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_specifications_template/', dst_test_data, 201, dst_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dst_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dst_test_data) test_patch = {"version": 'v6.28318530718', "schema": {"mykey": "my better value"}, @@ -183,7 +201,7 @@ class DataproductSpecificationsTemplateTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(dst_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_dataproduct_specifications_template_DELETE(self): dst_test_data = test_data_creator.DataproductSpecificationsTemplate() @@ -191,11 +209,29 @@ class DataproductSpecificationsTemplateTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_specifications_template/', dst_test_data, 201, dst_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dst_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dst_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) + def test_GET_DataproductSpecificationsTemplate_list_view_shows_entry(self): + + test_data_1 = DataproductSpecificationsTemplate_test_data() + models.DataproductSpecificationsTemplate.objects.create(**test_data_1) + nbr_results = models.DataproductSpecificationsTemplate.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/dataproduct_specifications_template/', test_data_1, nbr_results) + + def test_GET_DataproductSpecificationsTemplate_view_returns_correct_entry(self): + + # setup + test_data_1 = DataproductSpecificationsTemplate_test_data() + test_data_2 = DataproductSpecificationsTemplate_test_data() + id1 = models.DataproductSpecificationsTemplate.objects.create(**test_data_1).id + id2 = models.DataproductSpecificationsTemplate.objects.create(**test_data_2).id + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/dataproduct_specifications_template/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/dataproduct_specifications_template/%s/' % id2, test_data_2) + class DataproductFeedbackTemplateTestCase(unittest.TestCase): # This currently adds nothing on top of the template base class, so nothing new to test here. @@ -231,7 +267,7 @@ class DefaultSubtaskTemplatesTestCase(unittest.TestCase): response = requests.delete(template_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, template_url, 200, st_test_data) + GET_and_assert_equal_expected_response(self, template_url, 200, st_test_data) def test_default_dataproduct_specifications_template_PROTECT_behavior_on_template_deleted(self): dpst_test_data = test_data_creator.DataproductSpecificationsTemplate() @@ -246,7 +282,7 @@ class DefaultSubtaskTemplatesTestCase(unittest.TestCase): response = requests.delete(template_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, template_url, 200, dpst_test_data) + GET_and_assert_equal_expected_response(self, template_url, 200, dpst_test_data) class SubtaskTestCase(unittest.TestCase): @@ -263,7 +299,7 @@ class SubtaskTestCase(unittest.TestCase): self.assertTrue("Subtask List" in r.content.decode('utf8')) def test_subtask_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/subtask/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/subtask/1234321/', 404, {}) def test_subtask_POST_and_GET(self): st_test_data = test_data_creator.Subtask(cluster_url=self.cluster_url, task_blueprint_url=self.task_blueprint_url, specifications_template_url=self.specifications_template_url) @@ -271,7 +307,7 @@ class SubtaskTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask/', st_test_data, 201, st_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, st_test_data) + GET_and_assert_equal_expected_response(self, url, 200, st_test_data) minimium_subtaskid = 2000000 subtask_id = url.split("subtask/")[1].replace("/","") self.assertGreaterEqual(int(subtask_id), minimium_subtaskid) @@ -288,11 +324,11 @@ class SubtaskTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask/', st_test_data, 201, st_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, st_test_data) + GET_and_assert_equal_expected_response(self, url, 200, st_test_data) # PUT new values, verify PUT_and_assert_expected_response(self, url, st_test_data2, 200, st_test_data2) - GET_and_assert_expected_response(self, url, 200, st_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, st_test_data2) def test_subtask_PATCH(self): st_test_data = test_data_creator.Subtask(cluster_url=self.cluster_url, task_blueprint_url=self.task_blueprint_url, specifications_template_url=self.specifications_template_url) @@ -300,7 +336,7 @@ class SubtaskTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask/', st_test_data, 201, st_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, st_test_data) + GET_and_assert_equal_expected_response(self, url, 200, st_test_data) test_patch = {"specifications_doc": {"somespec": "somevalue"}} @@ -308,7 +344,7 @@ class SubtaskTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(st_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_subtask_DELETE(self): st_test_data = test_data_creator.Subtask(cluster_url=self.cluster_url, task_blueprint_url=self.task_blueprint_url, specifications_template_url=self.specifications_template_url) @@ -316,7 +352,7 @@ class SubtaskTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask/', st_test_data, 201, st_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, st_test_data) + GET_and_assert_equal_expected_response(self, url, 200, st_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -333,14 +369,14 @@ class SubtaskTestCase(unittest.TestCase): test_data = dict(st_test_data) test_data['state'] = state_url url = POST_and_assert_expected_response(self, BASE_URL + '/subtask/', test_data, 201, test_data)['url'] - GET_and_assert_expected_response(self, url, 200, test_data) + GET_and_assert_equal_expected_response(self, url, 200, test_data) # Try to DELETE dependency, verify that was not successful # Unfortunately we don't get a nice error in json, but a Django debug page on error 500... response = requests.delete(state_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, state_url, 200, state_data) + GET_and_assert_equal_expected_response(self, state_url, 200, state_data) def test_subtask_SET_NULL_behavior_on_task_blueprint_deleted(self): # make new task_blueprint_url instance, but reuse related data for speed @@ -352,7 +388,7 @@ class SubtaskTestCase(unittest.TestCase): # POST new item and verify url = POST_and_assert_expected_response(self, BASE_URL + '/subtask/', st_test_data, 201, st_test_data)['url'] - GET_and_assert_expected_response(self, url, 200, st_test_data) + GET_and_assert_equal_expected_response(self, url, 200, st_test_data) # DELETE dependency and check it's gone DELETE_and_assert_gone(self, task_blueprint_url) @@ -360,7 +396,7 @@ class SubtaskTestCase(unittest.TestCase): # assert item reference is set null expected_data = dict(st_test_data) expected_data['task_blueprint'] = None - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_subtask_PROTECT_behavior_on_template_deleted(self): stt_test_data = test_data_creator.SubtaskTemplate() @@ -369,14 +405,57 @@ class SubtaskTestCase(unittest.TestCase): # POST new item and verify url = POST_and_assert_expected_response(self, BASE_URL + '/subtask/', st_test_data, 201, st_test_data)['url'] - GET_and_assert_expected_response(self, url, 200, st_test_data) + GET_and_assert_equal_expected_response(self, url, 200, st_test_data) # Try to DELETE dependency, verify that was not successful # Unfortunately we don't get a nice error in json, but a Django debug page on error 500... response = requests.delete(specifications_template_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, specifications_template_url, 200, stt_test_data) + GET_and_assert_equal_expected_response(self, specifications_template_url, 200, stt_test_data) + + def test_GET_Subtask_list_view_shows_entry(self): + + test_data_1 = Subtask_test_data() + models.Subtask.objects.create(**test_data_1) + nbr_results = models.Subtask.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/subtask/', test_data_1, nbr_results) + + def test_GET_Subtask_view_returns_correct_entry(self): + + # setup + test_data_1 = Subtask_test_data() + test_data_2 = Subtask_test_data() + id1 = models.Subtask.objects.create(**test_data_1).id + id2 = models.Subtask.objects.create(**test_data_2).id + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/subtask/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/subtask/%s/' % id2, test_data_2) + + def test_nested_Subtask_are_filtered_according_to_TaskBlueprint(self): + + # setup + test_data_1 = Subtask_test_data() + test_data_2 = Subtask_test_data() + tbt_test_data_1 = TaskBlueprint_test_data("task blue print one") + tbt_test_data_2 = TaskBlueprint_test_data("task blue print two") + task_blueprint_1 = models.TaskBlueprint.objects.create(**tbt_test_data_1) + task_blueprint_2 = models.TaskBlueprint.objects.create(**tbt_test_data_2) + test_data_1 = dict(test_data_1) + test_data_1['task_blueprint'] = task_blueprint_1 + subtask_1 = models.Subtask.objects.create(**test_data_1) + test_data_2 = dict(test_data_2) + test_data_2['task_blueprint'] = task_blueprint_2 + subtask_2 = models.Subtask.objects.create(**test_data_2) + + # assert the returned list contains related items, a list of length 1 is retrieved + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/task_blueprint/%s/subtask/' % task_blueprint_2.id, test_data_2, 1) + # assert an existing related item is returned + GET_and_assert_in_expected_response(self, BASE_URL + '/task_blueprint/%s/subtask/%s/' % + (task_blueprint_2.id, subtask_2.id), test_data_2) + # assert an existing unrelated item is not returned + GET_and_assert_equal_expected_code(self, + BASE_URL + '/task_blueprint/%s/subtask/%s/' % (task_blueprint_2.id, subtask_1.id), 404) def test_subtask_state_log_records(self): st_test_data = test_data_creator.Subtask() @@ -417,7 +496,7 @@ class DataproductTestCase(unittest.TestCase): self.assertTrue("Dataproduct List" in r.content.decode('utf8')) def test_dataproduct_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/dataproduct/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/dataproduct/1234321/', 404, {}) def test_dataproduct_POST_and_GET(self): dp_test_data = test_data_creator.Dataproduct(specifications_template_url=self.specifications_template_url, subtask_output_url=self.subtask_output_url, dataproduct_feedback_template_url=self.dataproduct_feedback_template_url) @@ -425,7 +504,7 @@ class DataproductTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct/', dp_test_data, 201, dp_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dp_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dp_test_data) def test_dataproduct_PUT_invalid_raises_error(self): dp_test_data = test_data_creator.Dataproduct(specifications_template_url=self.specifications_template_url, subtask_output_url=self.subtask_output_url, dataproduct_feedback_template_url=self.dataproduct_feedback_template_url) @@ -439,11 +518,11 @@ class DataproductTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct/', dp_test_data, 201, dp_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dp_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dp_test_data) # PUT new values, verify PUT_and_assert_expected_response(self, url, dp_test_data2, 200, dp_test_data2) - GET_and_assert_expected_response(self, url, 200, dp_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, dp_test_data2) def test_dataproduct_PATCH(self): dp_test_data = test_data_creator.Dataproduct(specifications_template_url=self.specifications_template_url, subtask_output_url=self.subtask_output_url, dataproduct_feedback_template_url=self.dataproduct_feedback_template_url) @@ -451,7 +530,7 @@ class DataproductTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct/', dp_test_data, 201, dp_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dp_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dp_test_data) test_patch = {"filename": 'my_better.filename', "deleted_since": datetime.utcnow().isoformat()} @@ -460,7 +539,7 @@ class DataproductTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(dp_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_dataproduct_DELETE(self): dp_test_data = test_data_creator.Dataproduct(specifications_template_url=self.specifications_template_url, subtask_output_url=self.subtask_output_url, dataproduct_feedback_template_url=self.dataproduct_feedback_template_url) @@ -468,7 +547,7 @@ class DataproductTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct/', dp_test_data, 201, dp_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dp_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dp_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -485,14 +564,14 @@ class DataproductTestCase(unittest.TestCase): test_data = dict(dp_test_data) test_data['dataformat'] = dataformat_url url = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct/', test_data, 201, test_data)['url'] - GET_and_assert_expected_response(self, url, 200, test_data) + GET_and_assert_equal_expected_response(self, url, 200, test_data) # Try to DELETE dependency, verify that was not successful # Unfortunately we don't get a nice error in json, but a Django debug page on error 500... response = requests.delete(dataformat_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, dataformat_url, 200, dataformat_data) + GET_and_assert_equal_expected_response(self, dataformat_url, 200, dataformat_data) def test_dataproduct_CASCADE_behavior_on_specifications_template_deleted(self): specifications_template_url = test_data_creator.post_data_and_get_url(test_data_creator.SubtaskTemplate(), '/dataproduct_specifications_template/') @@ -500,13 +579,31 @@ class DataproductTestCase(unittest.TestCase): # POST new item, verify url = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct/', dp_test_data, 201, dp_test_data)['url'] - GET_and_assert_expected_response(self, url, 200, dp_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dp_test_data) # DELETE dependency and check it's gone DELETE_and_assert_gone(self, specifications_template_url) # assert item gone - GET_and_assert_expected_response(self, url, 404, {}) + GET_and_assert_equal_expected_response(self, url, 404, {}) + + def test_GET_Dataproduct_list_view_shows_entry(self): + + test_data_1 = Dataproduct_test_data() + models.Dataproduct.objects.create(**test_data_1) + nbr_results = models.Dataproduct.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/dataproduct/', test_data_1, nbr_results) + + def test_GET_Dataproduct_view_returns_correct_entry(self): + + # setup + test_data_1 = Dataproduct_test_data() + test_data_2 = Dataproduct_test_data() + id1 = models.Dataproduct.objects.create(**test_data_1).id + id2 = models.Dataproduct.objects.create(**test_data_2).id + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/dataproduct/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/dataproduct/%s/' % id2, test_data_2) class SubtaskConnectorTestCase(unittest.TestCase): @@ -516,7 +613,7 @@ class SubtaskConnectorTestCase(unittest.TestCase): self.assertTrue("Subtask Connector List" in r.content.decode('utf8')) def test_subtask_connector_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/subtask_connector/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/subtask_connector/1234321/', 404, {}) def test_subtask_connector_POST_and_GET(self): stc_test_data = test_data_creator.SubtaskConnector() @@ -524,7 +621,7 @@ class SubtaskConnectorTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_connector/', stc_test_data, 201, stc_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, stc_test_data) + GET_and_assert_equal_expected_response(self, url, 200, stc_test_data) def test_subtask_connector_PUT_invalid_raises_error(self): stc_test_data = test_data_creator.SubtaskConnector() @@ -538,11 +635,11 @@ class SubtaskConnectorTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_connector/', stc_test_data, 201, stc_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, stc_test_data) + GET_and_assert_equal_expected_response(self, url, 200, stc_test_data) # PUT new values, verify PUT_and_assert_expected_response(self, url, stc_test_data2, 200, stc_test_data2) - GET_and_assert_expected_response(self, url, 200, stc_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, stc_test_data2) def test_subtask_connector_PATCH(self): stc_test_data = test_data_creator.SubtaskConnector() @@ -550,7 +647,7 @@ class SubtaskConnectorTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_connector/', stc_test_data, 201, stc_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, stc_test_data) + GET_and_assert_equal_expected_response(self, url, 200, stc_test_data) test_patch = {"role": BASE_URL + '/role/calibrator/', "datatype": BASE_URL + '/datatype/quality/', } @@ -559,7 +656,7 @@ class SubtaskConnectorTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(stc_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_subtask_connector_DELETE(self): stc_test_data = test_data_creator.SubtaskConnector() @@ -567,7 +664,7 @@ class SubtaskConnectorTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_connector/', stc_test_data, 201, stc_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, stc_test_data) + GET_and_assert_equal_expected_response(self, url, 200, stc_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -585,15 +682,14 @@ class SubtaskConnectorTestCase(unittest.TestCase): test_data = dict(stc_test_data) test_data['role'] = role_url url = POST_and_assert_expected_response(self, BASE_URL + '/subtask_connector/', test_data, 201, test_data)['url'] - GET_and_assert_expected_response(self, url, 200, test_data) + GET_and_assert_equal_expected_response(self, url, 200, test_data) # Try to DELETE dependency, verify that was not successful # Unfortunately we don't get a nice error in json, but a Django debug page on error 500... response = requests.delete(role_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, role_url, 200, role_data) - + GET_and_assert_equal_expected_response(self, role_url, 200, role_data) def test_subtask_connector_PROTECT_behavior_on_datatype_deleted(self): stc_test_data = test_data_creator.SubtaskConnector() @@ -607,14 +703,46 @@ class SubtaskConnectorTestCase(unittest.TestCase): test_data = dict(stc_test_data) test_data['datatype'] = datatype_url url = POST_and_assert_expected_response(self, BASE_URL + '/subtask_connector/', test_data, 201, test_data)['url'] - GET_and_assert_expected_response(self, url, 200, test_data) + GET_and_assert_equal_expected_response(self, url, 200, test_data) # Try to DELETE dependency, verify that was not successful # Unfortunately we don't get a nice error in json, but a Django debug page on error 500... response = requests.delete(datatype_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, datatype_url, 200, datatype_data) + GET_and_assert_equal_expected_response(self, datatype_url, 200, datatype_data) + + def test_GET_SubtaskConnector_list_view_shows_entry(self): + + test_data_1 = SubtaskConnector_test_data() + models.SubtaskConnector.objects.create(**test_data_1) + nbr_results = models.SubtaskConnector.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/subtask_connector/', test_data_1, nbr_results) + + def test_GET_SubtaskConnector_view_returns_correct_entry(self): + + # setup + test_data_1 = SubtaskConnector_test_data() + test_data_2 = SubtaskConnector_test_data() + id1 = models.SubtaskConnector.objects.create(**test_data_1).id + id2 = models.SubtaskConnector.objects.create(**test_data_2).id + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/subtask_connector/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/subtask_connector/%s/' % id2, test_data_2) + + def test_SubtaskConnector_allows_setting_dataformats(self): + """ + Other then through the API view, we cannot assign ManyToMany on creation, but have to set it later + """ + test_data_1 = dict(SubtaskConnector_test_data()) + test_data_1['inputs'] = None + test_data_2 = SubtaskConnector_test_data() + tior = models.SubtaskConnector.objects.create(**test_data_2) + tior.dataformats.set([models.Dataformat.objects.get(value='Beamformed'), + models.Dataformat.objects.get(value='MeasurementSet')]) + tior.save() + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/subtask_connector/%s' % tior.id, test_data_2) class SubtaskInputTestCase(unittest.TestCase): @@ -636,7 +764,7 @@ class SubtaskInputTestCase(unittest.TestCase): self.assertTrue("Subtask Input List" in r.content.decode('utf8')) def test_subtask_input_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/subtask_input/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/subtask_input/1234321/', 404, {}) def test_subtask_input_POST_and_GET(self): sti_test_data = test_data_creator.SubtaskInput(subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_connector_url=self.subtask_connector_url, subtask_output_url=self.subtask_output_url, subtask_input_selection_template_url=self.subtask_input_selection_template_url) @@ -644,7 +772,7 @@ class SubtaskInputTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_input/', sti_test_data, 201, sti_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, sti_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sti_test_data) def test_subtask_input_PUT_invalid_raises_error(self): sti_test_data = test_data_creator.SubtaskInput(subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_connector_url=self.subtask_connector_url, subtask_output_url=self.subtask_output_url, subtask_input_selection_template_url=self.subtask_input_selection_template_url) @@ -657,12 +785,12 @@ class SubtaskInputTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_input/', sti_test_data, 201, sti_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, sti_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sti_test_data) # PUT new values, verify sti_test_data2 = test_data_creator.SubtaskInput(subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_connector_url=self.subtask_connector_url, subtask_output_url=self.subtask_output_url, subtask_input_selection_template_url=self.subtask_input_selection_template_url) PUT_and_assert_expected_response(self, url, sti_test_data2, 200, sti_test_data2) - GET_and_assert_expected_response(self, url, 200, sti_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, sti_test_data2) def test_subtask_input_PATCH(self): sti_test_data = test_data_creator.SubtaskInput(subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_connector_url=self.subtask_connector_url, subtask_output_url=self.subtask_output_url, subtask_input_selection_template_url=self.subtask_input_selection_template_url) @@ -670,7 +798,7 @@ class SubtaskInputTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_input/', sti_test_data, 201, sti_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, sti_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sti_test_data) # make new subtask_url instance, but reuse related data for speed subtask_url = test_data_creator.post_data_and_get_url(test_data_creator.Subtask(cluster_url=self.subtask_data['cluster'], @@ -685,7 +813,7 @@ class SubtaskInputTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(sti_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_subtask_input_DELETE(self): sti_test_data = test_data_creator.SubtaskInput(subtask_url=self.subtask_url, task_relation_blueprint_url=self.task_relation_blueprint_url, dataproduct_urls=self.dataproduct_urls, subtask_connector_url=self.subtask_connector_url, subtask_output_url=self.subtask_output_url, subtask_input_selection_template_url=self.subtask_input_selection_template_url) @@ -693,7 +821,7 @@ class SubtaskInputTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_input/', sti_test_data, 201, sti_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, sti_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sti_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -708,13 +836,13 @@ class SubtaskInputTestCase(unittest.TestCase): # POST new item, verify url = POST_and_assert_expected_response(self, BASE_URL + '/subtask_input/', sti_test_data, 201, sti_test_data)['url'] - GET_and_assert_expected_response(self, url, 200, sti_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sti_test_data) # DELETE dependency and check it's gone DELETE_and_assert_gone(self, subtask_url) # assert item gone - GET_and_assert_expected_response(self, url, 404, {}) + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_subtask_input_SET_NULL_behavior_on_connector_deleted(self): subtask_connector_url = test_data_creator.post_data_and_get_url(test_data_creator.SubtaskConnector(), '/subtask_connector/') @@ -722,7 +850,7 @@ class SubtaskInputTestCase(unittest.TestCase): # POST new item, verify url = POST_and_assert_expected_response(self, BASE_URL + '/subtask_input/', sti_test_data, 201, sti_test_data)['url'] - GET_and_assert_expected_response(self, url, 200, sti_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sti_test_data) # DELETE dependency and check it's gone DELETE_and_assert_gone(self, subtask_connector_url) @@ -730,7 +858,7 @@ class SubtaskInputTestCase(unittest.TestCase): # assert item reference is set null expected_data = dict(sti_test_data) expected_data['connector'] = None - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_subtask_input_SET_NULL_behavior_on_task_relation_blueprint_deleted(self): # make new task_relation_blueprint instance, but reuse related data for speed @@ -741,7 +869,7 @@ class SubtaskInputTestCase(unittest.TestCase): # POST new item, verify url = POST_and_assert_expected_response(self, BASE_URL + '/subtask_input/', sti_test_data, 201, sti_test_data)['url'] - GET_and_assert_expected_response(self, url, 200, sti_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sti_test_data) # DELETE dependency and check it's gone DELETE_and_assert_gone(self, task_relation_blueprint_url) @@ -749,7 +877,7 @@ class SubtaskInputTestCase(unittest.TestCase): # assert item reference is set null expected_data = dict(sti_test_data) expected_data['task_relation_blueprint'] = None - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_subtask_input_PROTECT_behavior_on_producer_deleted(self): # make new subtask_output_url instance, but reuse related data for speed @@ -758,14 +886,14 @@ class SubtaskInputTestCase(unittest.TestCase): # POST with dependency url = POST_and_assert_expected_response(self, BASE_URL + '/subtask_input/', sti_test_data, 201, sti_test_data)['url'] - GET_and_assert_expected_response(self, url, 200, sti_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sti_test_data) # Try to DELETE dependency, verify that was not successful # Unfortunately we don't get a nice error in json, but a Django debug page on error 500... response = requests.delete(subtask_output_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, subtask_output_url, 200, {}) + GET_and_assert_equal_expected_response(self, subtask_output_url, 200, {}) def test_subtask_input_PROTECT_behavior_on_selection_template_deleted(self): subtask_input_selection_template_url = test_data_creator.post_data_and_get_url(test_data_creator.SubtaskInputSelectionTemplate(), '/subtask_input_selection_template/') @@ -778,14 +906,45 @@ class SubtaskInputTestCase(unittest.TestCase): # POST with dependency url = POST_and_assert_expected_response(self, BASE_URL + '/subtask_input/', sti_test_data, 201, sti_test_data)['url'] - GET_and_assert_expected_response(self, url, 200, sti_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sti_test_data) # Try to DELETE dependency, verify that was not successful # Unfortunately we don't get a nice error in json, but a Django debug page on error 500... response = requests.delete(subtask_input_selection_template_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, subtask_input_selection_template_url, 200, {}) + GET_and_assert_equal_expected_response(self, subtask_input_selection_template_url, 200, {}) + + def test_GET_SubtaskInput_list_view_shows_entry(self): + + test_data_1 = SubtaskInput_test_data() + models.SubtaskInput.objects.create(**test_data_1) + nbr_results = models.SubtaskInput.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/subtask_input/', test_data_1, nbr_results) + + def test_GET_SubtaskInput_view_returns_correct_entry(self): + + # setup + test_data_1 = SubtaskInput_test_data() + test_data_2 = SubtaskInput_test_data() + id1 = models.SubtaskInput.objects.create(**test_data_1).id + id2 = models.SubtaskInput.objects.create(**test_data_2).id + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/subtask_input/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/subtask_input/%s/' % id2, test_data_2) + + def test_SubtaskInput_allows_setting_dataproducts(self): + + test_data_1 = SubtaskInput_test_data() + dpt_test_data_1 = Dataproduct_test_data() + dpt_test_data_2 = Dataproduct_test_data() + # Other then through the API view, we cannot assign ManyToMany on creation, but have to set it later + si = models.SubtaskInput.objects.create(**test_data_1) + si.dataproducts.set([models.Dataproduct.objects.create(**dpt_test_data_1), + models.Dataproduct.objects.create(**dpt_test_data_2)]) + si.save() + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/subtask_input/%s/' % si.id, test_data_1) class SubtaskOutputTestCase(unittest.TestCase): @@ -802,7 +961,7 @@ class SubtaskOutputTestCase(unittest.TestCase): self.assertTrue("Subtask Output List" in r.content.decode('utf8')) def test_subtask_output_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/subtask_output/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/subtask_output/1234321/', 404, {}) def test_subtask_output_POST_and_GET(self): sto_test_data = test_data_creator.SubtaskOutput(subtask_url=self.subtask_url, subtask_connector_url=self.subtask_connector_url) @@ -811,7 +970,7 @@ class SubtaskOutputTestCase(unittest.TestCase): r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_output/', sto_test_data, 201, sto_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, sto_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sto_test_data) def test_subtask_output_PUT_invalid_raises_error(self): sto_test_data = test_data_creator.SubtaskOutput(subtask_url=self.subtask_url, subtask_connector_url=self.subtask_connector_url) @@ -824,11 +983,11 @@ class SubtaskOutputTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_output/', sto_test_data, 201,sto_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, sto_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sto_test_data) # PUT new values, verify PUT_and_assert_expected_response(self, url, sto_test_data2, 200, sto_test_data2) - GET_and_assert_expected_response(self, url, 200, sto_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, sto_test_data2) def test_subtask_output_PATCH(self): sto_test_data = test_data_creator.SubtaskOutput(subtask_url=self.subtask_url, subtask_connector_url=self.subtask_connector_url) @@ -838,7 +997,7 @@ class SubtaskOutputTestCase(unittest.TestCase): r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_output/', sto_test_data, 201, sto_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, sto_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sto_test_data) test_patch = {"subtask": sto_test_data2["subtask"], "tags": ['FANCYTAG'], } @@ -847,7 +1006,7 @@ class SubtaskOutputTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(sto_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_subtask_output_DELETE(self): sto_test_data = test_data_creator.SubtaskOutput(subtask_url=self.subtask_url, subtask_connector_url=self.subtask_connector_url) @@ -856,7 +1015,7 @@ class SubtaskOutputTestCase(unittest.TestCase): r_dict = POST_and_assert_expected_response(self, BASE_URL + '/subtask_output/', sto_test_data, 201, sto_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, sto_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sto_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -868,13 +1027,13 @@ class SubtaskOutputTestCase(unittest.TestCase): # POST new item, verify url = POST_and_assert_expected_response(self, BASE_URL + '/subtask_output/', sto_test_data, 201, sto_test_data)['url'] - GET_and_assert_expected_response(self, url, 200, sto_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sto_test_data) # DELETE dependency and check it's gone DELETE_and_assert_gone(self, subtask_url) # assert item gone - GET_and_assert_expected_response(self, url, 404, {}) + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_subtask_output_SET_NULL_behavior_on_connector_deleted(self): sto_test_data = test_data_creator.SubtaskOutput(subtask_url=self.subtask_url, subtask_connector_url=self.subtask_connector_url) @@ -883,7 +1042,7 @@ class SubtaskOutputTestCase(unittest.TestCase): url = \ POST_and_assert_expected_response(self, BASE_URL + '/subtask_output/', sto_test_data, 201, sto_test_data)[ 'url'] - GET_and_assert_expected_response(self, url, 200, sto_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sto_test_data) # DELETE dependency and check it's gone DELETE_and_assert_gone(self, sto_test_data['connector']) @@ -891,8 +1050,25 @@ class SubtaskOutputTestCase(unittest.TestCase): # assert item reference is set null expected_data = dict(sto_test_data) expected_data['connector'] = None - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) + def test_GET_SubtaskOutput_list_view_shows_entry(self): + + test_data_1 = SubtaskOutput_test_data() + models.SubtaskOutput.objects.create(**test_data_1) + nbr_results = models.SubtaskOutput.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/subtask_output/', test_data_1, nbr_results) + + def test_GET_SubtaskOutput_view_returns_correct_entry(self): + + # setup + test_data_1 = SubtaskOutput_test_data() + test_data_2 = SubtaskOutput_test_data() + id1 = models.SubtaskOutput.objects.create(**test_data_1).id + id2 = models.SubtaskOutput.objects.create(**test_data_2).id + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/subtask_output/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/subtask_output/%s/' % id2, test_data_2) class AntennaSetTestCase(unittest.TestCase): @@ -902,7 +1078,7 @@ class AntennaSetTestCase(unittest.TestCase): self.assertTrue("Antenna Set List" in r.content.decode('utf8')) def test_antenna_set_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/antenna_set/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/antenna_set/1234321/', 404, {}) def test_antenna_set_POST_and_GET(self): antennaset_test_data = test_data_creator.AntennaSet() @@ -910,7 +1086,7 @@ class AntennaSetTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/antenna_set/', antennaset_test_data, 201, antennaset_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, antennaset_test_data) + GET_and_assert_equal_expected_response(self, url, 200, antennaset_test_data) def test_antenna_set_PUT_invalid_raises_error(self): antennaset_test_data = test_data_creator.AntennaSet() @@ -924,11 +1100,11 @@ class AntennaSetTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/antenna_set/', antennaset_test_data, 201, antennaset_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, antennaset_test_data) + GET_and_assert_equal_expected_response(self, url, 200, antennaset_test_data) # PUT new values, verify PUT_and_assert_expected_response(self, url, antennaset_test_data2, 200, antennaset_test_data2) - GET_and_assert_expected_response(self, url, 200, antennaset_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, antennaset_test_data2) def test_antenna_set_PATCH(self): antennaset_test_data = test_data_creator.AntennaSet() @@ -936,7 +1112,7 @@ class AntennaSetTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/antenna_set/', antennaset_test_data, 201, antennaset_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, antennaset_test_data) + GET_and_assert_equal_expected_response(self, url, 200, antennaset_test_data) test_patch = {"rcus": [11, 12, 13, 14, 15], "station_type": BASE_URL + '/station_type/remote/'} @@ -945,7 +1121,7 @@ class AntennaSetTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(antennaset_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_antenna_set_DELETE(self): antennaset_test_data = test_data_creator.AntennaSet() @@ -953,7 +1129,7 @@ class AntennaSetTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/antenna_set/', antennaset_test_data, 201, antennaset_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, antennaset_test_data) + GET_and_assert_equal_expected_response(self, url, 200, antennaset_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -970,14 +1146,32 @@ class AntennaSetTestCase(unittest.TestCase): test_data = dict(antennaset_test_data) test_data['station_type'] = dataformat_url url = POST_and_assert_expected_response(self, BASE_URL + '/antenna_set/', test_data, 201, test_data)['url'] - GET_and_assert_expected_response(self, url, 200, test_data) + GET_and_assert_equal_expected_response(self, url, 200, test_data) # Try to DELETE dependency, verify that was not successful # Unfortunately we don't get a nice error in json, but a Django debug page on error 500... response = requests.delete(dataformat_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, dataformat_url, 200, dataformat_data) + GET_and_assert_equal_expected_response(self, dataformat_url, 200, dataformat_data) + + def test_GET_AntennaSet_list_view_shows_entry(self): + + test_data_1 = AntennaSet_test_data() + models.AntennaSet.objects.create(**test_data_1) + nbr_results = models.AntennaSet.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/antenna_set/', test_data_1, nbr_results) + + def test_GET_AntennaSet_view_returns_correct_entry(self): + + # setup + test_data_1 = AntennaSet_test_data() + test_data_2 = AntennaSet_test_data() + id1 = models.AntennaSet.objects.create(**test_data_1).id + id2 = models.AntennaSet.objects.create(**test_data_2).id + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/antenna_set/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/antenna_set/%s/' % id2, test_data_2) class DataproductTransformTestCase(unittest.TestCase): @@ -994,7 +1188,7 @@ class DataproductTransformTestCase(unittest.TestCase): self.assertTrue("Dataproduct Transform List" in r.content.decode('utf8')) def test_dataproduct_transform_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/dataproduct_transform/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/dataproduct_transform/1234321/', 404, {}) def test_dataproduct_transform_POST_and_GET(self): dpt_test_data = test_data_creator.DataproductTransform(input_dataproduct_url=self.input_dataproduct_url, output_dataproduct_url=self.output_dataproduct_url) @@ -1002,7 +1196,7 @@ class DataproductTransformTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_transform/', dpt_test_data, 201, dpt_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dpt_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dpt_test_data) def test_dataproduct_transform_PUT_invalid_raises_error(self): dpt_test_data = test_data_creator.DataproductTransform(input_dataproduct_url=self.input_dataproduct_url, output_dataproduct_url=self.output_dataproduct_url) @@ -1016,11 +1210,11 @@ class DataproductTransformTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_transform/', dpt_test_data, 201, dpt_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dpt_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dpt_test_data) # PUT new values, verify PUT_and_assert_expected_response(self, url, dpt_test_data2, 200, dpt_test_data2) - GET_and_assert_expected_response(self, url, 200, dpt_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, dpt_test_data2) def test_dataproduct_transform_PATCH(self): dpt_test_data = test_data_creator.DataproductTransform(input_dataproduct_url=self.input_dataproduct_url, output_dataproduct_url=self.output_dataproduct_url) @@ -1028,7 +1222,7 @@ class DataproductTransformTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_transform/', dpt_test_data, 201, dpt_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dpt_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dpt_test_data) # make new output_dataproduct_url instance, but reuse related data for speed output_dp_test_data = test_data_creator.Dataproduct(specifications_template_url=self.output_dataproduct_data['specifications_template'], @@ -1043,7 +1237,7 @@ class DataproductTransformTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(dpt_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_dataproduct_transform_DELETE(self): dpt_test_data = test_data_creator.DataproductTransform(input_dataproduct_url=self.input_dataproduct_url, output_dataproduct_url=self.output_dataproduct_url) @@ -1051,7 +1245,7 @@ class DataproductTransformTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_transform/', dpt_test_data, 201, dpt_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dpt_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dpt_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -1066,14 +1260,14 @@ class DataproductTransformTestCase(unittest.TestCase): # POST new item and verify url = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_transform/', dpt_test_data, 201, dpt_test_data)['url'] - GET_and_assert_expected_response(self, url, 200, dpt_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dpt_test_data) # Try to DELETE dependency, verify that was not successful # Unfortunately we don't get a nice error in json, but a Django debug page on error 500... response = requests.delete(input_dataproduct_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, input_dataproduct_url, 200, input_dp_test_data) + GET_and_assert_equal_expected_response(self, input_dataproduct_url, 200, input_dp_test_data) def test_dataproduct_transform_PROTECT_behavior_on_output_deleted(self): # make new output_dataproduct_url instance, but reuse related data for speed @@ -1085,14 +1279,32 @@ class DataproductTransformTestCase(unittest.TestCase): # POST new item and verify url = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_transform/', dpt_test_data, 201, dpt_test_data)['url'] - GET_and_assert_expected_response(self, url, 200, dpt_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dpt_test_data) # Try to DELETE dependency, verify that was not successful # Unfortunately we don't get a nice error in json, but a Django debug page on error 500... response = requests.delete(output_dataproduct_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, output_dataproduct_url, 200, output_dp_test_data) + GET_and_assert_equal_expected_response(self, output_dataproduct_url, 200, output_dp_test_data) + + def test_GET_DataproductTransform_list_view_shows_entry(self): + + test_data_1 = DataproductTransform_test_data() + models.DataproductTransform.objects.create(**test_data_1) + nbr_results = models.DataproductTransform.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/dataproduct_transform/', test_data_1, nbr_results) + + def test_GET_DataproductTransform_view_returns_correct_entry(self): + + # setup + test_data_1 = DataproductTransform_test_data() + test_data_2 = DataproductTransform_test_data() + id1 = models.DataproductTransform.objects.create(**test_data_1).id + id2 = models.DataproductTransform.objects.create(**test_data_2).id + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/dataproduct_transform/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/dataproduct_transform/%s/' % id2, test_data_2) class FilesystemTestCase(unittest.TestCase): @@ -1102,7 +1314,7 @@ class FilesystemTestCase(unittest.TestCase): self.assertTrue("Filesystem List" in r.content.decode('utf8')) def test_filesystem_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/filesystem/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/filesystem/1234321/', 404, {}) def test_filesystem_POST_and_GET(self): fs_test_data = test_data_creator.Filesystem() @@ -1110,7 +1322,7 @@ class FilesystemTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/filesystem/', fs_test_data, 201, fs_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, fs_test_data) + GET_and_assert_equal_expected_response(self, url, 200, fs_test_data) def test_filesystem_PUT_invalid_raises_error(self): fs_test_data = test_data_creator.Filesystem() @@ -1125,13 +1337,13 @@ class FilesystemTestCase(unittest.TestCase): r_dict = POST_and_assert_expected_response(self, BASE_URL + '/filesystem/', fs_test_data, 201, fs_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, fs_test_data) + GET_and_assert_equal_expected_response(self, url, 200, fs_test_data) fs_test_data2 = test_data_creator.Filesystem() # PUT new values, verify PUT_and_assert_expected_response(self, url, fs_test_data2, 200, fs_test_data2) - GET_and_assert_expected_response(self, url, 200, fs_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, fs_test_data2) def test_filesystem_PATCH(self): cluster_url = test_data_creator.post_data_and_get_url(test_data_creator.Cluster(), '/cluster/') @@ -1141,7 +1353,7 @@ class FilesystemTestCase(unittest.TestCase): r_dict = POST_and_assert_expected_response(self, BASE_URL + '/filesystem/', fs_test_data, 201, fs_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, fs_test_data) + GET_and_assert_equal_expected_response(self, url, 200, fs_test_data) cluster_url2 = test_data_creator.post_data_and_get_url(test_data_creator.Cluster(), '/cluster/') test_patch = {"cluster": cluster_url2, @@ -1151,7 +1363,7 @@ class FilesystemTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(fs_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_filesystem_DELETE(self): fs_test_data = test_data_creator.Filesystem() @@ -1160,7 +1372,7 @@ class FilesystemTestCase(unittest.TestCase): r_dict = POST_and_assert_expected_response(self, BASE_URL + '/filesystem/', fs_test_data, 201, fs_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, fs_test_data) + GET_and_assert_equal_expected_response(self, url, 200, fs_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -1171,14 +1383,32 @@ class FilesystemTestCase(unittest.TestCase): # POST new item and verify url = POST_and_assert_expected_response(self, BASE_URL + '/filesystem/', fs_test_data, 201, fs_test_data)['url'] - GET_and_assert_expected_response(self, url, 200, fs_test_data) + GET_and_assert_equal_expected_response(self, url, 200, fs_test_data) # Try to DELETE dependency, verify that was not successful # Unfortunately we don't get a nice error in json, but a Django debug page on error 500... response = requests.delete(fs_test_data['cluster'], auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, fs_test_data['cluster'], 200, {}) + GET_and_assert_equal_expected_response(self, fs_test_data['cluster'], 200, {}) + + def test_GET_Filesystem_list_view_shows_entry(self): + + test_data_1 = Filesystem_test_data() + models.Filesystem.objects.create(**test_data_1) + nbr_results = models.Filesystem.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/filesystem/', test_data_1, nbr_results) + + def test_GET_Filesystem_view_returns_correct_entry(self): + + # setup + test_data_1 = Filesystem_test_data() + test_data_2 = Filesystem_test_data() + id1 = models.Filesystem.objects.create(**test_data_1).id + id2 = models.Filesystem.objects.create(**test_data_2).id + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/filesystem/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/filesystem/%s/' % id2, test_data_2) class ClusterTestCase(unittest.TestCase): @@ -1188,7 +1418,7 @@ class ClusterTestCase(unittest.TestCase): self.assertTrue("Cluster List" in r.content.decode('utf8')) def test_cluster_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/cluster/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/cluster/1234321/', 404, {}) def test_cluster_POST_and_GET(self): c_test_data = test_data_creator.Cluster() @@ -1196,7 +1426,7 @@ class ClusterTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/cluster/', c_test_data, 201, c_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, c_test_data) + GET_and_assert_equal_expected_response(self, url, 200, c_test_data) def test_cluster_PUT_invalid_raises_error(self): c_test_data = test_data_creator.Cluster() @@ -1208,13 +1438,13 @@ class ClusterTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/cluster/', c_test_data, 201, c_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, c_test_data) + GET_and_assert_equal_expected_response(self, url, 200, c_test_data) c_test_data2 = test_data_creator.Cluster() # PUT new values, verify PUT_and_assert_expected_response(self, url, c_test_data2, 200, c_test_data2) - GET_and_assert_expected_response(self, url, 200, c_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, c_test_data2) def test_cluster_PATCH(self): c_test_data = test_data_creator.Cluster() @@ -1222,7 +1452,7 @@ class ClusterTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/cluster/', c_test_data, 201, c_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, c_test_data) + GET_and_assert_equal_expected_response(self, url, 200, c_test_data) test_patch = {"location": 'at the other end of the universe'} @@ -1230,7 +1460,7 @@ class ClusterTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(c_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_cluster_DELETE(self): c_test_data = test_data_creator.Cluster() @@ -1238,11 +1468,29 @@ class ClusterTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/cluster/', c_test_data, 201, c_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, c_test_data) + GET_and_assert_equal_expected_response(self, url, 200, c_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) + def test_GET_Cluster_list_view_shows_entry(self): + + test_data_1 = Cluster_test_data("Cluster one") + models.Cluster.objects.create(**test_data_1) + nbr_results = models.Cluster.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/cluster/', test_data_1, nbr_results) + + def test_GET_Cluster_view_returns_correct_entry(self): + + # setup + test_data_1 = Cluster_test_data("Cluster 1") + test_data_2 = Cluster_test_data("Cluster 2") + id1 = models.Cluster.objects.create(**test_data_1).id + id2 = models.Cluster.objects.create(**test_data_2).id + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/cluster/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/cluster/%s/' % id2, test_data_2) + class DataproductHashTestCase(unittest.TestCase): @classmethod @@ -1255,7 +1503,7 @@ class DataproductHashTestCase(unittest.TestCase): self.assertTrue("Dataproduct Hash List" in r.content.decode('utf8')) def test_dataproduct_hash_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/dataproduct_hash/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/dataproduct_hash/1234321/', 404, {}) def test_dataproduct_hash_POST_and_GET(self): dph_test_data = test_data_creator.DataproductHash(dataproduct_url=self.dataproduct_url) @@ -1264,7 +1512,7 @@ class DataproductHashTestCase(unittest.TestCase): r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_hash/', dph_test_data, 201, dph_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dph_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dph_test_data) def test_dataproduct_hash_PUT_invalid_raises_error(self): dph_test_data = test_data_creator.DataproductHash(dataproduct_url=self.dataproduct_url) @@ -1280,11 +1528,11 @@ class DataproductHashTestCase(unittest.TestCase): r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_hash/', dph_test_data, 201, dph_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dph_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dph_test_data) # PUT new values, verify PUT_and_assert_expected_response(self, url, dph_test_data2, 200, dph_test_data2) - GET_and_assert_expected_response(self, url, 200, dph_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, dph_test_data2) def test_dataproduct_hash_PATCH(self): dph_test_data = test_data_creator.DataproductHash(dataproduct_url=self.dataproduct_url) @@ -1293,7 +1541,7 @@ class DataproductHashTestCase(unittest.TestCase): r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_hash/', dph_test_data, 201, dph_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dph_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dph_test_data) test_patch = {"algorithm": BASE_URL + '/algorithm/aes256/', "hash": 'bender-was-here'} @@ -1302,7 +1550,7 @@ class DataproductHashTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(dph_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_dataproduct_hash_DELETE(self): dph_test_data = test_data_creator.DataproductHash(dataproduct_url=self.dataproduct_url) @@ -1311,7 +1559,7 @@ class DataproductHashTestCase(unittest.TestCase): r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_hash/', dph_test_data, 201, dph_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dph_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dph_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -1322,14 +1570,14 @@ class DataproductHashTestCase(unittest.TestCase): # POST new item and verify url = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_hash/', dph_test_data, 201, dph_test_data)['url'] - GET_and_assert_expected_response(self, url, 200, dph_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dph_test_data) # Try to DELETE dependency, verify that was not successful # Unfortunately we don't get a nice error in json, but a Django debug page on error 500... response = requests.delete(dph_test_data['dataproduct'], auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, dph_test_data['dataproduct'], 200, {}) + GET_and_assert_equal_expected_response(self, dph_test_data['dataproduct'], 200, {}) def test_dataproduct_hash_PROTECT_behavior_on_algorithm_deleted(self): dph_test_data = test_data_creator.DataproductHash(dataproduct_url=self.dataproduct_url) @@ -1337,14 +1585,32 @@ class DataproductHashTestCase(unittest.TestCase): # POST new item and verify url = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_hash/', dph_test_data, 201, dph_test_data)['url'] - GET_and_assert_expected_response(self, url, 200, dph_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dph_test_data) # Try to DELETE dependency, verify that was not successful # Unfortunately we don't get a nice error in json, but a Django debug page on error 500... response = requests.delete(dph_test_data['algorithm'], auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, dph_test_data['algorithm'], 200, {}) + GET_and_assert_equal_expected_response(self, dph_test_data['algorithm'], 200, {}) + + def test_GET_DataproductHash_list_view_shows_entry(self): + + test_data_1 = DataproductHash_test_data() + models.DataproductHash.objects.create(**test_data_1) + nbr_results = models.DataproductHash.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/dataproduct_hash/', test_data_1, nbr_results) + + def test_GET_DataproductHash_view_returns_correct_entry(self): + + # setup + test_data_1 = DataproductHash_test_data() + test_data_2 = DataproductHash_test_data() + id1 = models.DataproductHash.objects.create(**test_data_1).id + id2 = models.DataproductHash.objects.create(**test_data_2).id + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/dataproduct_hash/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/dataproduct_hash/%s/' % id2, test_data_2) class DataproductArchiveInfoTestCase(unittest.TestCase): @@ -1358,7 +1624,7 @@ class DataproductArchiveInfoTestCase(unittest.TestCase): self.assertTrue("Dataproduct Archive Info List" in r.content.decode('utf8')) def test_dataproduct_archive_info_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/dataproduct_archive_info/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/dataproduct_archive_info/1234321/', 404, {}) def test_dataproduct_archive_info_POST_and_GET(self): dpai_test_data = test_data_creator.DataproductArchiveInfo(dataproduct_url=self.dataproduct_url) @@ -1367,7 +1633,7 @@ class DataproductArchiveInfoTestCase(unittest.TestCase): r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_archive_info/', dpai_test_data, 201, dpai_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dpai_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dpai_test_data) def test_dataproduct_archive_info_PUT_invalid_raises_error(self): dpai_test_data = test_data_creator.DataproductArchiveInfo(dataproduct_url=self.dataproduct_url) @@ -1383,11 +1649,11 @@ class DataproductArchiveInfoTestCase(unittest.TestCase): r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_archive_info/', dpai_test_data, 201, dpai_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dpai_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dpai_test_data) # PUT new values, verify PUT_and_assert_expected_response(self, url, dpai_test_data2, 200, dpai_test_data2) - GET_and_assert_expected_response(self, url, 200, dpai_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, dpai_test_data2) def test_dataproduct_archive_info_PATCH(self): dpai_test_data = test_data_creator.DataproductArchiveInfo(dataproduct_url=self.dataproduct_url) @@ -1396,7 +1662,7 @@ class DataproductArchiveInfoTestCase(unittest.TestCase): r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_archive_info/', dpai_test_data, 201, dpai_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dpai_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dpai_test_data) test_patch = {"storage_ticket": "mygoldenticket"} @@ -1404,7 +1670,7 @@ class DataproductArchiveInfoTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(dpai_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_dataproduct_archive_info_DELETE(self): dpai_test_data = test_data_creator.DataproductArchiveInfo(dataproduct_url=self.dataproduct_url) @@ -1413,7 +1679,7 @@ class DataproductArchiveInfoTestCase(unittest.TestCase): r_dict = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_archive_info/', dpai_test_data, 201, dpai_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, dpai_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dpai_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -1424,14 +1690,32 @@ class DataproductArchiveInfoTestCase(unittest.TestCase): # POST new item and verify url = POST_and_assert_expected_response(self, BASE_URL + '/dataproduct_archive_info/', dpai_test_data, 201, dpai_test_data)['url'] - GET_and_assert_expected_response(self, url, 200, dpai_test_data) + GET_and_assert_equal_expected_response(self, url, 200, dpai_test_data) # Try to DELETE dependency, verify that was not successful # Unfortunately we don't get a nice error in json, but a Django debug page on error 500... response = requests.delete(dpai_test_data['dataproduct'], auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, dpai_test_data['dataproduct'], 200, {}) + GET_and_assert_equal_expected_response(self, dpai_test_data['dataproduct'], 200, {}) + + def test_GET_DataproductArchiveInfo_list_view_shows_entry(self): + + test_data_1 = DataproductArchiveInfo_test_data() + models.DataproductArchiveInfo.objects.create(**test_data_1) + nbr_results = models.DataproductArchiveInfo.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/dataproduct_archive_info/', test_data_1, nbr_results) + + def test_GET_DataproductArchiveInfo_view_returns_correct_entry(self): + + # setup + test_data_1 = DataproductArchiveInfo_test_data() + test_data_2 = DataproductArchiveInfo_test_data() + id1 = models.DataproductArchiveInfo.objects.create(**test_data_1).id + id2 = models.DataproductArchiveInfo.objects.create(**test_data_2).id + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/dataproduct_archive_info/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/dataproduct_archive_info/%s/' % id2, test_data_2) class SubtaskQuery(unittest.TestCase): diff --git a/SAS/TMSS/test/t_tmssapp_specification_django.py b/SAS/TMSS/test/t_tmssapp_specification_django.py index 2682fd8abb405f0540149e5a568de48f14becaab..2709487a1d945dfb2f6dc70721fa66c4dfd5f33d 100755 --- a/SAS/TMSS/test/t_tmssapp_specification_django.py +++ b/SAS/TMSS/test/t_tmssapp_specification_django.py @@ -40,10 +40,6 @@ from lofar.sas.tmss.test.tmss_test_data_django_models import * from django.db.utils import IntegrityError -# TODO: rest API testing should be moved out of this test module. -# import rest_framework.test -# client = rest_framework.test.APIClient() -# from lofar.sas.tmss.test.test_utils import assertDataWithUrls, assertUrlList class GeneratorTemplateTest(unittest.TestCase): def test_GeneratorTemplate_gets_created_with_correct_creation_timestamp(self): @@ -69,35 +65,6 @@ class GeneratorTemplateTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_GeneratorTemplate_list_view_shows_entry(self): - # - # # setup - # entry = models.GeneratorTemplate.objects.create(**self.test_data_1) - # - # # assert - # response = client.get('/generator_template/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # for item in self.test_data_1.items(): - # self.assertIn(item, response.data['results'][0].items()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_GeneratorTemplate_view_returns_correct_entry(self): - # - # # setup - # id1 = models.GeneratorTemplate.objects.create(**self.test_data_1).id - # id2 = models.GeneratorTemplate.objects.create(**self.test_data_2).id - # - # # assert - # response1 = client.get('/generator_template/%s/' % id1, format='json', follow=True) - # response2 = client.get('/generator_template/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # for item in self.test_data_1.items(): - # self.assertIn(item, response1.data.items()) - # for item in self.test_data_2.items(): - # self.assertIn(item, response2.data.items()) - class DefaultGeneratorTemplateTest(unittest.TestCase): def test_DefaultGeneratorTemplate_prevents_same_name(self): @@ -137,35 +104,6 @@ class SchedulingUnitTemplateTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_SchedulingUnitTemplate_list_view_shows_entry(self): - # - # # setup - # entry = models.SchedulingUnitTemplate.objects.create(**self.test_data_1) - # - # # assert - # response = client.get('/scheduling_unit_template/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # for item in self.test_data_1.items(): - # self.assertIn(item, response.data['results'][0].items()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_SchedulingUnitTemplate_view_returns_correct_entry(self): - # - # # setup - # id1 = models.SchedulingUnitTemplate.objects.create(**self.test_data_1).id - # id2 = models.SchedulingUnitTemplate.objects.create(**self.test_data_2).id - # - # # assert - # response1 = client.get('/scheduling_unit_template/%s/' % id1, format='json', follow=True) - # response2 = client.get('/scheduling_unit_template/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # for item in self.test_data_1.items(): - # self.assertIn(item, response1.data.items()) - # for item in self.test_data_2.items(): - # self.assertIn(item, response2.data.items()) - class TaskTemplateTest(unittest.TestCase): def test_TaskTemplate_gets_created_with_correct_creation_timestamp(self): @@ -192,35 +130,6 @@ class TaskTemplateTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_TaskTemplate_list_view_shows_entry(self): - # - # # setup - # entry = models.TaskTemplate.objects.create(**self.test_data_1) - # - # # assert - # response = client.get('/task_template/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # for item in self.test_data_1.items(): - # self.assertIn(item, response.data['results'][0].items()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_TaskTemplate_view_returns_correct_entry(self): - # - # # setup - # id1 = models.TaskTemplate.objects.create(**self.test_data_1).id - # id2 = models.TaskTemplate.objects.create(**self.test_data_2).id - # - # # assert - # response1 = client.get('/task_template/%s/' % id1, format='json', follow=True) - # response2 = client.get('/task_template/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # for item in self.test_data_1.items(): - # self.assertIn(item, response1.data.items()) - # for item in self.test_data_2.items(): - # self.assertIn(item, response2.data.items()) - class WorkRelationSelectionTemplateTest(unittest.TestCase): def test_WorkRelationSelectionTemplate_gets_created_with_correct_creation_timestamp(self): @@ -247,62 +156,8 @@ class WorkRelationSelectionTemplateTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_WorkRelationSelectionTemplate_list_view_shows_entry(self): - # - # # setup - # entry = models.WorkRelationSelectionTemplate.objects.create(**self.test_data_1) - # - # # assert - # response = client.get('/work_relation_selection_template/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # for item in self.test_data_1.items(): - # self.assertIn(item, response.data['results'][0].items()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_WorkRelationSelectionTemplate_view_returns_correct_entry(self): - # - # # setup - # id1 = models.WorkRelationSelectionTemplate.objects.create(**self.test_data_1).id - # id2 = models.WorkRelationSelectionTemplate.objects.create(**self.test_data_2).id - # - # # assert - # response1 = client.get('/work_relation_selection_template/%s/' % id1, format='json', follow=True) - # response2 = client.get('/work_relation_selection_template/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # for item in self.test_data_1.items(): - # self.assertIn(item, response1.data.items()) - # for item in self.test_data_2.items(): - # self.assertIn(item, response2.data.items()) - class TaskConnectorsTest(unittest.TestCase): - # TODO: rest API testing should be moved out of this test module. - # def test_GET_TaskConnectors_list_view_shows_entry(self): - # - # # setup - # models.TaskConnectors.objects.create(**self.get_test_data()) - # - # # assert - # response = client.get('/task_connectors/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data['results'][0], self.get_test_data()) - - # TODO: rest API testing should be moved out of this test module. - # def test_GET_TaskConnectors_view_returns_correct_entry(self): - # - # # setup - # id1 = models.TaskConnectors.objects.create(**self.test_data_1).id - # id2 = models.TaskConnectors.objects.create(**self.test_data_2).id - # - # # assert - # response1 = client.get('/task_connectors/%s/' % id1, format='json', follow=True) - # response2 = client.get('/task_connectors/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, self.test_data_1) - # assertDataWithUrls(self, response2.data, self.test_data_2) def test_POST_TaskConnectors_prevents_missing_input_of(self): @@ -324,35 +179,8 @@ class TaskConnectorsTest(unittest.TestCase): with self.assertRaises(IntegrityError): models.TaskConnectors.objects.create(**test_data_1) - # TODO: rest API testing should be moved out of this test module. - # def test_TaskConnectors_allows_setting_dataformats(self): - # # Other then through the API view, we cannot assign ManyToMany on creation, but have to set it later - # - # test_data_1 = dict(self.test_data_1) - # test_data_1['input_of'] = None - # wior = models.TaskConnectors.objects.create(**self.test_data_2) - # wior.dataformats.set([models.Dataformat.objects.get(value='Beamformed'), - # models.Dataformat.objects.get(value='MeasurementSet')]) - # wior.save() - # - # # assert - # response = client.get('/task_connectors/%s/' % wior.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data, self.test_data_2) - class CycleTest(unittest.TestCase): - # TODO: rest API testing should be moved out of this test module. - # def test_GET_Cycle_list_view_shows_entry(self): - # - # # setup - # models.Cycle.objects.create(**self.test_data_1) - # - # # assert - # response = client.get('/cycle/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # for item in self.test_data_1.items(): - # self.assertIn(item, response.data['results'][0].items()) def test_Cycle_gets_created_with_correct_creation_timestamp(self): @@ -378,55 +206,8 @@ class CycleTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_Cycle_view_returns_correct_entry(self): - # - # # setup - # id1 = models.Cycle.objects.create(**self.test_data_1).name # name is pk - # id2 = models.Cycle.objects.create(**self.test_data_2).name - # - # # assert - # response1 = client.get('/cycle/%s/' % id1, format='json', follow=True) - # response2 = client.get('/cycle/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # for item in self.test_data_1.items(): - # self.assertIn(item, response1.data.items()) - # for item in self.test_data_2.items(): - # self.assertIn(item, response2.data.items()) - - # TODO: rest API testing should be moved out of this test module. - # def test_Cycle_constains_list_of_related_projects(self): - # - # self.pt = ProjectTest() - # - # # setup - # cycle = models.Cycle.objects.create(**self.test_data_1) - # project1 = models.Project.objects.create(**self.pt.test_data_1) - # project1.cycle = cycle - # project1.save() - # project2 = models.Project.objects.create(**self.pt.test_data_2) - # project2.cycle = cycle - # project2.save() - # - # # assert - # response = client.get('/cycle/%s/' % cycle.name, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertUrlList(self, response.data['projects'], [project1, project2]) - class ProjectTest(unittest.TestCase): - # TODO: rest API testing should be moved out of this test module. - # def test_GET_Project_list_view_shows_entry(self): - # - # # setup - # models.Project.objects.create(**self.test_data_1) - # - # # assert - # response = client.get('/project/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # for item in self.test_data_1.items(): - # self.assertIn(item, response.data['results'][0].items()) def test_Project_gets_created_with_correct_creation_timestamp(self): @@ -452,66 +233,8 @@ class ProjectTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_Project_view_returns_correct_entry(self): - # - # # setup - # id1 = models.Project.objects.create(**self.test_data_1).name # name is pk - # id2 = models.Project.objects.create(**self.test_data_2).name - # - # # assert - # response1 = client.get('/project/%s/' % id1, format='json', follow=True) - # response2 = client.get('/project/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # for item in self.test_data_1.items(): - # self.assertIn(item, response1.data.items()) - # for item in self.test_data_2.items(): - # self.assertIn(item, response2.data.items()) - - # TODO: rest API testing should be moved out of this test module. - # def test_nested_projects_are_filtered_according_to_cycle(self): - # - # self.ct = CycleTest() - # self.ct.setUp() - # - # # setup - # cycle_1 = models.Cycle.objects.create(**self.ct.test_data_1) - # cycle_2 = models.Cycle.objects.create(**self.ct.test_data_2) - # test_data_1 = dict(self.test_data_1) - # test_data_1['cycle'] = cycle_1 - # project_1 = models.Project.objects.create(**test_data_1) - # test_data_2 = dict(self.test_data_2) - # test_data_2['cycle'] = cycle_2 - # project_2 = models.Project.objects.create(**test_data_2) - # - # # assert the returned list contains related items - # response = client.get('/cycle/%s/project/' % cycle_2.name, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # self.assertEqual(len(response.data['results']), 1) - # assertDataWithUrls(self, response.data['results'][0], test_data_2) - # - # # assert an existing related item is returned, name is pk - # response = client.get('/cycle/%s/project/%s/' % (cycle_2.name, project_2.name) , format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data, test_data_2) - # - # # assert an existing unrelated item is not returned, name is pk - # response = client.get('/cycle/%s/project/%s/' % (cycle_2.name, project_1.name) , format='json', follow=True) - # self.assertEqual(response.status_code, 404) - class SchedulingSetTest(unittest.TestCase): - # TODO: rest API testing should be moved out of this test module. - # def test_GET_SchedulingSet_list_view_shows_entry(self): - # - # # setup - # models.SchedulingSet.objects.create(**self.test_data_1) - # - # # assert - # response = client.get('/scheduling_set/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data['results'][0], self.test_data_1) def test_SchedulingSet_gets_created_with_correct_creation_timestamp(self): @@ -537,21 +260,6 @@ class SchedulingSetTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_SchedulingSet_view_returns_correct_entry(self): - # - # # setup - # id1 = models.SchedulingSet.objects.create(**self.test_data_1).id - # id2 = models.SchedulingSet.objects.create(**self.test_data_2).id - # - # # assert - # response1 = client.get('/scheduling_set/%s/' % id1, format='json', follow=True) - # response2 = client.get('/scheduling_set/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, self.test_data_1) - # assertDataWithUrls(self, response2.data, self.test_data_2) - def test_SchedulingSet_prevents_missing_project(self): # setup @@ -562,39 +270,8 @@ class SchedulingSetTest(unittest.TestCase): with self.assertRaises(IntegrityError): models.SchedulingSet.objects.create(**test_data) - # TODO: rest API testing should be moved out of this test module. - # def test_SchedulingSet_contains_list_of_related_SchedulingUnitDraft(self): - # - # sudt = SchedulingUnitDraftTest() - # sudt.setUp(populate=True) - # - # # setup - # scheduling_set = models.SchedulingSet.objects.create(**self.test_data_1) - # scheduling_unit_draft_1 = models.SchedulingUnitDraft.objects.create(**sudt.test_data_1) - # scheduling_unit_draft_1.scheduling_set = scheduling_set - # scheduling_unit_draft_1.save() - # scheduling_unit_draft_2 = models.SchedulingUnitDraft.objects.create(**sudt.test_data_2) - # scheduling_unit_draft_2.scheduling_set = scheduling_set - # scheduling_unit_draft_2.save() - # - # # assert - # response = client.get('/scheduling_set/%s/' % scheduling_set.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertUrlList(self, response.data['scheduling_unit_drafts'], [scheduling_unit_draft_1, scheduling_unit_draft_2]) - class SchedulingUnitDraftTest(unittest.TestCase): - # TODO: rest API testing should be moved out of this test module. - # def test_GET_SchedulingUnitDraft_list_view_shows_entry(self): - # - # # setup - # models.SchedulingUnitDraft.objects.create(**self.test_data_1) - # - # # assert - # response = client.get('/scheduling_unit_draft/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # - # assertDataWithUrls(self, response.data['results'][0], self.test_data_1) def test_SchedulingUnitDraft_gets_created_with_correct_creation_timestamp(self): @@ -620,21 +297,6 @@ class SchedulingUnitDraftTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_SchedulingUnitDraft_view_returns_correct_entry(self): - # - # # setup - # id1 = models.SchedulingUnitDraft.objects.create(**self.test_data_1).id - # id2 = models.SchedulingUnitDraft.objects.create(**self.test_data_2).id - # - # # assert - # response1 = client.get('/scheduling_unit_draft/%s/' % id1, format='json', follow=True) - # response2 = client.get('/scheduling_unit_draft/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, self.test_data_1) - # assertDataWithUrls(self, response2.data, self.test_data_2) - def test_SchedulingUnitDraft_prevents_missing_template(self): # setup @@ -655,88 +317,8 @@ class SchedulingUnitDraftTest(unittest.TestCase): with self.assertRaises(IntegrityError): models.SchedulingUnitDraft.objects.create(**test_data) - # TODO: rest API testing should be moved out of this test module. - # def test_nested_SchedulingUnitDraft_are_filtered_according_to_SchedulingSet(self): - # - # sst = SchedulingSetTest() - # sst.setUp() - # - # # setup - # scheduling_set_1 = models.SchedulingSet.objects.create(**sst.test_data_1) - # scheduling_set_2 = models.SchedulingSet.objects.create(**sst.test_data_2) - # test_data_1 = dict(self.test_data_1) - # test_data_1['scheduling_set'] = scheduling_set_1 - # scheduling_unit_draft_1 = models.SchedulingUnitDraft.objects.create(**test_data_1) - # test_data_2 = dict(self.test_data_2) - # test_data_2['scheduling_set'] = scheduling_set_2 - # scheduling_unit_draft_2 = models.SchedulingUnitDraft.objects.create(**test_data_2) - # - # # assert the returned list contains related items - # response = client.get('/scheduling_set/%s/scheduling_unit_draft/' % scheduling_set_2.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # self.assertEqual(len(response.data['results']), 1) - # assertDataWithUrls(self, response.data['results'][0], test_data_2) - # - # # assert an existing related item is returned - # response = client.get('/scheduling_set/%s/scheduling_unit_draft/%s/' % (scheduling_set_2.id, scheduling_unit_draft_2.id) , format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data, test_data_2) - # - # # assert an existing unrelated item is not returned - # response = client.get('/scheduling_set/%s/scheduling_unit_draft/%s/' % (scheduling_set_2.id, scheduling_unit_draft_1.id) , format='json', follow=True) - # self.assertEqual(response.status_code, 404) - - # TODO: rest API testing should be moved out of this test module. - # def test_SchedulingUnitDraft_contains_list_of_related_SchedulingUnitBlueprint(self): - # subt = SchedulingUnitBlueprintTest() - # subt.setUp(populate=False) - # - # # setup - # scheduling_unit_draft = models.SchedulingUnitDraft.objects.create(**self.test_data_1) - # scheduling_unit_blueprint_1 = models.SchedulingUnitBlueprint.objects.create(**subt.test_data_1) - # scheduling_unit_blueprint_1.draft = scheduling_unit_draft - # scheduling_unit_blueprint_1.save() - # scheduling_unit_blueprint_2 = models.SchedulingUnitBlueprint.objects.create(**subt.test_data_2) - # scheduling_unit_blueprint_2.draft = scheduling_unit_draft - # scheduling_unit_blueprint_2.save() - # - # # assert - # response = client.get('/scheduling_unit_draft/%s/' % scheduling_unit_draft.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertUrlList(self, response.data['related_scheduling_unit_blueprint'], [scheduling_unit_blueprint_1, scheduling_unit_blueprint_2]) - - # TODO: rest API testing should be moved out of this test module. - # def test_SchedulingUnitDraft_contains_list_of_related_TaskDraft(self): - # tdt = TaskDraftTest() - # tdt.setUp(populate=False) - # - # # setup - # scheduling_unit_draft = models.SchedulingUnitDraft.objects.create(**self.test_data_1) - # task_draft_1 = models.TaskDraft.objects.create(**tdt.test_data_1) - # task_draft_1.scheduling_unit_draft = scheduling_unit_draft - # task_draft_1.save() - # task_draft_2 = models.TaskDraft.objects.create(**tdt.test_data_2) - # task_draft_2.scheduling_unit_draft = scheduling_unit_draft - # task_draft_2.save() - # - # # assert - # response = client.get('/scheduling_unit_draft/%s/' % scheduling_unit_draft.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertUrlList(self, response.data['task_drafts'], [task_draft_1, task_draft_2]) - class TaskDraftTest(unittest.TestCase): - # TODO: rest API testing should be moved out of this test module. - # def test_GET_TaskDraft_list_view_shows_entry(self): - # - # # setup - # models.TaskDraft.objects.create(**self.test_data_1) - # - # # assert - # response = client.get('/task_draft/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # - # assertDataWithUrls(self, response.data['results'][0], self.test_data_1) def test_TaskDraft_gets_created_with_correct_creation_timestamp(self): @@ -762,21 +344,6 @@ class TaskDraftTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_TaskDraft_view_returns_correct_entry(self): - # - # # setup - # id1 = models.TaskDraft.objects.create(**self.test_data_1).id - # id2 = models.TaskDraft.objects.create(**self.test_data_2).id - # - # # assert - # response1 = client.get('/task_draft/%s/' % id1, format='json', follow=True) - # response2 = client.get('/task_draft/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, self.test_data_1) - # assertDataWithUrls(self, response2.data, self.test_data_2) - def test_TaskDraft_prevents_missing_template(self): # setup @@ -797,92 +364,8 @@ class TaskDraftTest(unittest.TestCase): with self.assertRaises(IntegrityError): models.TaskDraft.objects.create(**test_data) - # TODO: rest API testing should be moved out of this test module. - # def test_nested_TaskDraft_are_filtered_according_to_SchedulingUnitDraft(self): - # sudt = SchedulingUnitDraftTest() - # sudt.setUp(populate=False) - # - # # setup - # scheduling_unit_draft_1 = models.SchedulingUnitDraft.objects.create(**sudt.test_data_1) - # scheduling_unit_draft_2 = models.SchedulingUnitDraft.objects.create(**sudt.test_data_2) - # test_data_1 = dict(self.test_data_1) - # test_data_1['scheduling_unit_draft'] = scheduling_unit_draft_1 - # task_draft_1 = models.TaskDraft.objects.create(**test_data_1) - # test_data_2 = dict(self.test_data_2) - # test_data_2['scheduling_unit_draft'] = scheduling_unit_draft_2 - # task_draft_2 = models.TaskDraft.objects.create(**test_data_2) - # - # # assert the returned list contains related items - # response = client.get('/scheduling_unit_draft/%s/task_draft/' % scheduling_unit_draft_2.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # self.assertEqual(len(response.data['results']), 1) - # assertDataWithUrls(self, response.data['results'][0], test_data_2) - # - # # assert an existing related item is returned - # response = client.get('/scheduling_unit_draft/%s/task_draft/%s/' % (scheduling_unit_draft_2.id, task_draft_2.id), format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data, test_data_2) - # - # # assert an existing unrelated item is not returned - # response = client.get('/scheduling_unit_draft/%s/task_draft/%s/' % (scheduling_unit_draft_2.id, task_draft_1.id), format='json', follow=True) - # self.assertEqual(response.status_code, 404) - - - # TODO: rest API testing should be moved out of this test module. - # def test_TaskDraft_contains_list_of_related_TaskBlueprint(self): - # - # tbt = TaskBlueprintTest() - # tbt.setUp(populate=False) - # - # # setup - # task_draft = models.TaskDraft.objects.create(**self.test_data_1) - # task_blueprint_1 = models.TaskBlueprint.objects.create(**tbt.test_data_1) - # task_blueprint_1.draft = task_draft - # task_blueprint_1.save() - # task_blueprint_2 = models.TaskBlueprint.objects.create(**tbt.test_data_2) - # task_blueprint_2.draft = task_draft - # task_blueprint_2.save() - # - # # assert - # response = client.get('/task_draft/%s/' % task_draft.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertUrlList(self, response.data['related_task_blueprint'], [task_blueprint_1, task_blueprint_2]) - - - # TODO: rest API testing should be moved out of this test module. - # def test_TaskDraft_contains_lists_of_related_TaskRelationDraft(self): - # - # trdt = TaskRelationDraftTest() - # trdt.setUp(populate=False) - # - # # setup - # task_draft = models.TaskDraft.objects.create(**self.test_data_1) - # task_relation_draft_1 = models.TaskRelationDraft.objects.create(**trdt.test_data_1) - # task_relation_draft_1.producer = task_draft - # task_relation_draft_1.save() - # task_relation_draft_2 = models.TaskRelationDraft.objects.create(**trdt.test_data_2) - # task_relation_draft_2.consumer = task_draft - # task_relation_draft_2.save() - # - # # assert - # response = client.get('/task_draft/%s/' % task_draft.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertUrlList(self, response.data['produced_by'], [task_relation_draft_1]) - # assertUrlList(self, response.data['consumed_by'], [task_relation_draft_2]) - class TaskRelationDraftTest(unittest.TestCase): - # TODO: rest API testing should be moved out of this test module. - # def test_GET_TaskRelationDraft_list_view_shows_entry(self): - # - # # setup - # models.TaskRelationDraft.objects.create(**self.test_data_1) - # - # # assert - # response = client.get('/task_relation_draft/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # - # assertDataWithUrls(self, response.data['results'][0], self.test_data_1) def test_TaskRelationDraft_gets_created_with_correct_creation_timestamp(self): @@ -908,20 +391,6 @@ class TaskRelationDraftTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_TaskRelationDraft_view_returns_correct_entry(self): - # - # # setup - # id1 = models.TaskRelationDraft.objects.create(**self.test_data_1).id - # id2 = models.TaskRelationDraft.objects.create(**self.test_data_2).id - # - # # assert - # response1 = client.get('/task_relation_draft/%s/' % id1, format='json', follow=True) - # response2 = client.get('/task_relation_draft/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, self.test_data_1) - # assertDataWithUrls(self, response2.data, self.test_data_2) def test_TaskRelationDraft_prevents_missing_template(self): @@ -953,54 +422,8 @@ class TaskRelationDraftTest(unittest.TestCase): with self.assertRaises(IntegrityError): models.TaskRelationDraft.objects.create(**test_data) - # TODO: rest API testing should be moved out of this test module. - # def test_nested_TaskRelationDraft_are_filtered_according_to_TaskDraft(self): - # tdt = TaskDraftTest() - # tdt.setUp(populate=False) - # - # # setup - # task_draft_1 = models.TaskDraft.objects.create(**tdt.test_data_1) - # task_draft_2 = models.TaskDraft.objects.create(**tdt.test_data_2) - # test_data_1 = dict(self.test_data_1) - # test_data_1['producer'] = task_draft_1 - # task_relation_draft_1 = models.TaskRelationDraft.objects.create(**test_data_1) - # test_data_2 = dict(self.test_data_2) - # test_data_2['consumer'] = task_draft_2 - # task_relation_draft_2 = models.TaskRelationDraft.objects.create(**test_data_2) - # - # # assert the returned list contains related items - # response = client.get('/task_draft/%s/task_relation_draft/' % task_draft_2.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # self.assertEqual(len(response.data['results']), 1) - # assertDataWithUrls(self, response.data['results'][0], test_data_2) - # - # # assert an existing related producer is returned - # response = client.get('/task_draft/%s/task_relation_draft/%s/' % (task_draft_1.id, task_relation_draft_1.id), format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data, test_data_1) - # - # # assert an existing related consumer is returned - # response = client.get('/task_draft/%s/task_relation_draft/%s/' % (task_draft_2.id, task_relation_draft_2.id), format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data, test_data_2) - # - # # assert an existing unrelated item is not returned - # response = client.get('/task_draft/%s/task_relation_draft/%s/' % (task_draft_2.id, task_relation_draft_1.id), format='json', follow=True) - # self.assertEqual(response.status_code, 404) - class SchedulingUnitBlueprintTest(unittest.TestCase): - # TODO: rest API testing should be moved out of this test module. - # def test_GET_SchedulingUnitBlueprint_list_view_shows_entry(self): - # - # # setup - # models.SchedulingUnitBlueprint.objects.create(**SchedulingUnitBlueprint_test_data()) - # - # # assert - # response = client.get('/scheduling_unit_blueprint/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # - # assertDataWithUrls(self, response.data['results'][0], SchedulingUnitBlueprint_test_data()) def test_SchedulingUnitBlueprint_gets_created_with_correct_creation_timestamp(self): @@ -1026,20 +449,6 @@ class SchedulingUnitBlueprintTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_SchedulingUnitBlueprint_view_returns_correct_entry(self): - # - # # setup - # id1 = models.SchedulingUnitBlueprint.objects.create(**SchedulingUnitBlueprint_test_data()).id - # id2 = models.SchedulingUnitBlueprint.objects.create(**SchedulingUnitBlueprint_test_data()).id - # - # # assert - # response1 = client.get('/scheduling_unit_blueprint/%s/' % id1, format='json', follow=True) - # response2 = client.get('/scheduling_unit_blueprint/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, self.test_data_1) - # assertDataWithUrls(self, response2.data, self.test_data_2) def test_SchedulingUnitBlueprint_prevents_missing_template(self): @@ -1061,50 +470,8 @@ class SchedulingUnitBlueprintTest(unittest.TestCase): with self.assertRaises(IntegrityError): models.SchedulingUnitBlueprint.objects.create(**test_data) - # TODO: rest API testing should be moved out of this test module. - # def test_nested_SchedulingUnitBlueprint_are_filtered_according_to_SchedulingUnitDraft(self): - # - # sudt = SchedulingUnitDraftTest() - # sudt.setUp(populate=False) - # - # # setup - # scheduling_unit_draft_1 = models.SchedulingUnitDraft.objects.create(**sudt.test_data_1) - # scheduling_unit_draft_2 = models.SchedulingUnitDraft.objects.create(**sudt.test_data_2) - # test_data_1 = dict(self.test_data_1) - # test_data_1['draft'] = scheduling_unit_draft_1 - # scheduling_unit_blueprint_1 = models.SchedulingUnitBlueprint.objects.create(**test_data_1) - # test_data_2 = dict(self.test_data_2) - # test_data_2['draft'] = scheduling_unit_draft_2 - # scheduling_unit_blueprint_2 = models.SchedulingUnitBlueprint.objects.create(**test_data_2) - # - # # assert the returned list contains related items - # response = client.get('/scheduling_unit_draft/%s/scheduling_unit_blueprint/' % scheduling_unit_draft_2.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # self.assertEqual(len(response.data['results']), 1) - # assertDataWithUrls(self, response.data['results'][0], test_data_2) - # - # # assert an existing related item is returned - # response = client.get('/scheduling_unit_draft/%s/scheduling_unit_blueprint/%s/' % (scheduling_unit_draft_2.id, scheduling_unit_blueprint_2.id) , format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data, test_data_2) - # - # # assert an existing unrelated item is not returned - # response = client.get('/scheduling_unit_draft/%s/scheduling_unit_blueprint/%s/' % (scheduling_unit_draft_2.id, scheduling_unit_blueprint_1.id) , format='json', follow=True) - # self.assertEqual(response.status_code, 404) - class TaskBlueprintTest(unittest.TestCase): - # TODO: rest API testing should be moved out of this test module. - # def test_GET_TaskBlueprint_list_view_shows_entry(self): - # - # # setup - # models.TaskBlueprint.objects.create(**self.test_data_1) - # - # # assert - # response = client.get('/task_blueprint/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # - # assertDataWithUrls(self, response.data['results'][0], self.test_data_1) def test_TaskBlueprint_gets_created_with_correct_creation_timestamp(self): @@ -1130,21 +497,6 @@ class TaskBlueprintTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_TaskBlueprint_view_returns_correct_entry(self): - # - # # setup - # id1 = models.TaskBlueprint.objects.create(**self.test_data_1).id - # id2 = models.TaskBlueprint.objects.create(**self.test_data_2).id - # - # # assert - # response1 = client.get('/task_blueprint/%s/' % id1, format='json', follow=True) - # response2 = client.get('/task_blueprint/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, self.test_data_1) - # assertDataWithUrls(self, response2.data, self.test_data_2) - def test_TaskBlueprint_prevents_missing_template(self): # setup @@ -1176,90 +528,7 @@ class TaskBlueprintTest(unittest.TestCase): models.TaskBlueprint.objects.create(**test_data) - # TODO: rest API testing should be moved out of this test module. - # def test_nested_TaskBlueprint_are_filtered_according_to_TaskDraft(self): - # tdt = TaskDraftTest() - # tdt.setUp(populate=False) - # - # # setup - # task_draft_1 = models.TaskDraft.objects.create(**tdt.test_data_1) - # task_draft_2 = models.TaskDraft.objects.create(**tdt.test_data_2) - # test_data_1 = dict(self.test_data_1) - # test_data_1['draft'] = task_draft_1 - # task_blueprint_1 = models.TaskBlueprint.objects.create(**test_data_1) - # test_data_2 = dict(self.test_data_2) - # test_data_2['draft'] = task_draft_2 - # task_blueprint_2 = models.TaskBlueprint.objects.create(**test_data_2) - # - # # assert the returned list contains related items - # response = client.get('/task_draft/%s/task_blueprint/' % task_draft_2.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # self.assertEqual(len(response.data['results']), 1) - # assertDataWithUrls(self, response.data['results'][0], test_data_2) - # - # # assert an existing related item is returned - # response = client.get('/task_draft/%s/task_blueprint/%s/' % (task_draft_2.id, task_blueprint_2.id), format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data, test_data_2) - # - # # assert an existing unrelated item is not returned - # response = client.get('/task_draft/%s/task_blueprint/%s/' % (task_draft_2.id, task_blueprint_1.id), format='json', follow=True) - # self.assertEqual(response.status_code, 404) - - # TODO: rest API testing should be moved out of this test module. - # def test_TaskBlueprint_contains_list_of_related_Subtask(self): - # - # from t_tmssapp_scheduling_django import SubtaskTest # Note: cannot do this on module level due to circular import - # st = SubtaskTest() - # st.setUp(populate=False) - # - # # setup - # task_blueprint = models.TaskBlueprint.objects.create(**self.test_data_1) - # subtask_1 = models.Subtask.objects.create(**st.test_data_1) - # subtask_1.task_blueprint = task_blueprint - # subtask_1.save() - # subtask_2 = models.Subtask.objects.create(**st.test_data_2) - # subtask_2.task_blueprint = task_blueprint - # subtask_2.save() - # - # # assert - # response = client.get('/task_blueprint/%s/' % task_blueprint.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertUrlList(self, response.data['subtasks'], [subtask_1, subtask_2]) - - # TODO: rest API testing should be moved out of this test module. - # def test_TaskBlueprint_contains_lists_of_related_TaskRelationBlueprint(self): - # - # trbt = TaskRelationBlueprintTest() - # trbt.setUp(populate=False) - # - # # setup - # task_blueprint = models.TaskBlueprint.objects.create(**self.test_data_1) - # task_relation_blueprint_1 = models.TaskRelationBlueprint.objects.create(**trbt.test_data_1) - # task_relation_blueprint_1.producer = task_blueprint - # task_relation_blueprint_1.save() - # task_relation_blueprint_2 = models.TaskRelationBlueprint.objects.create(**trbt.test_data_2) - # task_relation_blueprint_2.consumer = task_blueprint - # task_relation_blueprint_2.save() - # - # # assert - # response = client.get('/task_blueprint/%s/' % task_blueprint.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertUrlList(self, response.data['produced_by'], [task_relation_blueprint_1]) - # assertUrlList(self, response.data['consumed_by'], [task_relation_blueprint_2]) - - class TaskRelationBlueprintTest(unittest.TestCase): - # TODO: rest API testing should be moved out of this test module. - # def test_GET_TaskRelationBlueprint_list_view_shows_entry(self): - # # setup - # models.TaskRelationBlueprint.objects.create(**self.test_data_1) - # - # # assert - # response = client.get('/task_relation_blueprint/', format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # - # assertDataWithUrls(self, response.data['results'][0], self.test_data_1) def test_TaskRelationBlueprint_gets_created_with_correct_creation_timestamp(self): # setup @@ -1283,20 +552,6 @@ class TaskRelationBlueprintTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - # TODO: rest API testing should be moved out of this test module. - # def test_GET_TaskRelationBlueprint_view_returns_correct_entry(self): - # # setup - # id1 = models.TaskRelationBlueprint.objects.create(**self.test_data_1).id - # id2 = models.TaskRelationBlueprint.objects.create(**self.test_data_2).id - # - # # assert - # response1 = client.get('/task_relation_blueprint/%s/' % id1, format='json', follow=True) - # response2 = client.get('/task_relation_blueprint/%s/' % id2, format='json', follow=True) - # self.assertEqual(response1.status_code, 200) - # self.assertEqual(response2.status_code, 200) - # assertDataWithUrls(self, response1.data, self.test_data_1) - # assertDataWithUrls(self, response2.data, self.test_data_2) - def test_TaskRelationBlueprint_prevents_missing_selection_template(self): # setup test_data = dict(TaskRelationBlueprint_test_data()) @@ -1351,72 +606,6 @@ class TaskRelationBlueprintTest(unittest.TestCase): with self.assertRaises(IntegrityError): models.TaskRelationBlueprint.objects.create(**test_data) - # TODO: rest API testing should be moved out of this test module. - # def test_nested_TaskRelationBlueprint_are_filtered_according_to_TaskRelationDraft(self): - # trdt = TaskRelationDraftTest() - # trdt.setUp(populate=False) - # - # # setup - # task_relation_draft_1 = models.TaskRelationDraft.objects.create(**trdt.test_data_1) - # task_relation_draft_2 = models.TaskRelationDraft.objects.create(**trdt.test_data_2) - # test_data_1 = dict(self.test_data_1) - # test_data_1['draft'] = task_relation_draft_1 - # task_relation_blueprint_1 = models.TaskRelationBlueprint.objects.create(**test_data_1) - # test_data_2 = dict(self.test_data_2) - # test_data_2['draft'] = task_relation_draft_2 - # task_relation_blueprint_2 = models.TaskRelationBlueprint.objects.create(**test_data_2) - # - # # assert the returned list contains related items - # response = client.get('/task_relation_draft/%s/task_relation_blueprint/' % task_relation_draft_2.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # self.assertEqual(len(response.data['results']), 1) - # assertDataWithUrls(self, response.data['results'][0], test_data_2) - # - # # assert an existing related item is returned - # response = client.get('/task_relation_draft/%s/task_relation_blueprint/%s/' % (task_relation_draft_2.id, task_relation_blueprint_2.id), format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data, test_data_2) - # - # # assert an existing unrelated item is not returned - # response = client.get('/task_relation_draft/%s/task_relation_blueprint/%s/' % (task_relation_draft_2.id, task_relation_blueprint_1.id), format='json', follow=True) - # self.assertEqual(response.status_code, 404) - - # TODO: rest API testing should be moved out of this test module. - # def test_nested_TaskRelationBlueprint_are_filtered_according_to_TaskBlueprint(self): - # tbt = TaskBlueprintTest() - # tbt.setUp(populate=False) - # - # # setup - # task_blueprint_1 = models.TaskBlueprint.objects.create(**tbt.test_data_1) - # task_blueprint_2 = models.TaskBlueprint.objects.create(**tbt.test_data_2) - # test_data_1 = dict(self.test_data_1) - # test_data_1['producer'] = task_blueprint_1 - # task_relation_blueprint_1 = models.TaskRelationBlueprint.objects.create(**test_data_1) - # test_data_2 = dict(self.test_data_2) - # test_data_2['consumer'] = task_blueprint_2 - # task_relation_blueprint_2 = models.TaskRelationBlueprint.objects.create(**test_data_2) - # - # # assert the returned list contains related producer - # response = client.get('/task_blueprint/%s/task_relation_blueprint/' % task_blueprint_1.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # self.assertEqual(len(response.data['results']), 1) - # assertDataWithUrls(self, response.data['results'][0], test_data_1) - # - # # assert the returned list contains related consumer - # response = client.get('/task_blueprint/%s/task_relation_blueprint/' % task_blueprint_2.id, format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # self.assertEqual(len(response.data['results']), 1) - # assertDataWithUrls(self, response.data['results'][0], test_data_2) - # - # # assert an existing related item is returned - # response = client.get('/task_blueprint/%s/task_relation_blueprint/%s/' % (task_blueprint_2.id, task_relation_blueprint_2.id), format='json', follow=True) - # self.assertEqual(response.status_code, 200) - # assertDataWithUrls(self, response.data, test_data_2) - # - # # assert an existing unrelated item is not returned - # response = client.get('/task_blueprint/%s/task_relation_blueprint/%s/' % (task_blueprint_2.id, task_relation_blueprint_1.id), format='json', follow=True) - # self.assertEqual(response.status_code, 404) - # if __name__ == "__main__": os.environ['TZ'] = 'UTC' diff --git a/SAS/TMSS/test/t_tmssapp_specification_functional.py b/SAS/TMSS/test/t_tmssapp_specification_functional.py index fb3deef98e6e7f768d10ec60207e6453c257c5e4..ac22c0ef9ab63c27cff2ece54861e8975a103775 100755 --- a/SAS/TMSS/test/t_tmssapp_specification_functional.py +++ b/SAS/TMSS/test/t_tmssapp_specification_functional.py @@ -37,31 +37,61 @@ logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=loggin # use setup/teardown magic for tmss test database, ldap server and django server # (ignore pycharm unused import statement, python unittests does use at RunTime the tmss_test_environment_unittest_setup module) from lofar.sas.tmss.test.tmss_test_environment_unittest_setup import * +from lofar.sas.tmss.test.tmss_test_data_django_models import * +from lofar.sas.tmss.tmss.tmssapp import models +from lofar.sas.tmss.test.test_utils import assertUrlList + # import and setup test data creator from lofar.sas.tmss.test.tmss_test_data_rest import TMSSRESTTestDataCreator test_data_creator = TMSSRESTTestDataCreator(BASE_URL, AUTH) + +def get_total_number_of_objects(object_name): + """ + Retrieve the total number (count) of the given object + :param: object_name (string) or sub-url like 'subtask', etc + :return: url for new item + """ + response = requests.get(BASE_URL + '/' + object_name + '/', auth=AUTH) + json_response = response.json() + return json_response.get('count') + +def get_sub_urls(object_name): + """ + Retrieve the total number (count) of the given object + :param: object_name (string) or sub-url like 'subtask', etc + :return: url for new item + """ + response = requests.get(BASE_URL + '/' + object_name + '/', auth=AUTH) + json_response = response.json() + lst_urls = [] + for item in json_response.get('results'): + lst_urls.append(item['url']) + return lst_urls + + class BasicFunctionTestCase(unittest.TestCase): # todo: test_welcome_page (once we have one :)) pass class GeneratorTemplateTestCase(unittest.TestCase): + def test_generator_template_list_apiformat(self): r = requests.get(BASE_URL + '/generator_template/?format=api', auth=AUTH) self.assertEqual(r.status_code, 200) self.assertTrue("Generator Template List" in r.content.decode('utf8')) def test_generator_template_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/generator_template/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/generator_template/1234321/', 404, {}) def test_generator_template_POST_and_GET(self): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/generator_template/', test_data_creator.GeneratorTemplate(), 201, test_data_creator.GeneratorTemplate()) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, test_data_creator.GeneratorTemplate()) + GET_and_assert_equal_expected_response(self, url, 200, test_data_creator.GeneratorTemplate()) def test_generator_template_PUT_invalid_raises_error(self): PUT_and_assert_expected_response(self, BASE_URL + '/generator_template/9876789876/', test_data_creator.GeneratorTemplate(), 404, {}) @@ -71,18 +101,18 @@ class GeneratorTemplateTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/generator_template/', test_data_creator.GeneratorTemplate(), 201, test_data_creator.GeneratorTemplate()) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, test_data_creator.GeneratorTemplate()) + GET_and_assert_equal_expected_response(self, url, 200, test_data_creator.GeneratorTemplate()) # PUT new values, verify PUT_and_assert_expected_response(self, url, test_data_creator.GeneratorTemplate("generatortemplate2"), 200, test_data_creator.GeneratorTemplate("generatortemplate2")) - GET_and_assert_expected_response(self, url, 200, test_data_creator.GeneratorTemplate("generatortemplate2")) + GET_and_assert_equal_expected_response(self, url, 200, test_data_creator.GeneratorTemplate("generatortemplate2")) def test_generator_template_PATCH(self): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/generator_template/', test_data_creator.GeneratorTemplate(), 201, test_data_creator.GeneratorTemplate()) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, test_data_creator.GeneratorTemplate()) + GET_and_assert_equal_expected_response(self, url, 200, test_data_creator.GeneratorTemplate()) test_patch = {"version": 'v6.28318530718', "schema": {"mykey": "my better value"}} @@ -91,18 +121,27 @@ class GeneratorTemplateTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(test_data_creator.GeneratorTemplate()) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_generator_template_DELETE(self): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/generator_template/', test_data_creator.GeneratorTemplate(), 201, test_data_creator.GeneratorTemplate()) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, test_data_creator.GeneratorTemplate()) + GET_and_assert_equal_expected_response(self, url, 200, test_data_creator.GeneratorTemplate()) # DELETE and check it's gone DELETE_and_assert_gone(self, url) + def test_GET_generator_template_view_returns_correct_entry(self): + + test_data_1 = GeneratorTemplate_test_data("test_generator_template_1") + test_data_2 = GeneratorTemplate_test_data("test_generator_template_2") + id1 = models.GeneratorTemplate.objects.create(**test_data_1).id + id2 = models.GeneratorTemplate.objects.create(**test_data_2).id + GET_and_assert_in_expected_response(self, BASE_URL + '/generator_template/' + str(id1), test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/generator_template/' + str(id2), test_data_2) + class SchedulingUnitTemplateTestCase(unittest.TestCase): def test_scheduling_unit_template_list_apiformat(self): @@ -111,14 +150,14 @@ class SchedulingUnitTemplateTestCase(unittest.TestCase): self.assertTrue("Scheduling Unit Template List" in r.content.decode('utf8')) def test_scheduling_unit_template_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_template/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/scheduling_unit_template/1234321/', 404, {}) def test_scheduling_unit_template_POST_and_GET(self): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_template/', test_data_creator.SchedulingUnitTemplate(), 201, test_data_creator.SchedulingUnitTemplate()) url = r_dict['url'] - GET_and_assert_expected_response(self, url+'?format=json', 200, test_data_creator.SchedulingUnitTemplate()) + GET_and_assert_equal_expected_response(self, url+'?format=json', 200, test_data_creator.SchedulingUnitTemplate()) def test_scheduling_unit_template_PUT_invalid_raises_error(self): PUT_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_template/9876789876/', test_data_creator.SchedulingUnitTemplate(), 404, {}) @@ -128,18 +167,18 @@ class SchedulingUnitTemplateTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_template/', test_data_creator.SchedulingUnitTemplate(), 201, test_data_creator.SchedulingUnitTemplate()) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, test_data_creator.SchedulingUnitTemplate()) + GET_and_assert_equal_expected_response(self, url, 200, test_data_creator.SchedulingUnitTemplate()) # PUT new values, verify PUT_and_assert_expected_response(self, url, test_data_creator.SchedulingUnitTemplate("schedulingunittemplate2"), 200, test_data_creator.SchedulingUnitTemplate("schedulingunittemplate2")) - GET_and_assert_expected_response(self, url, 200, test_data_creator.SchedulingUnitTemplate("schedulingunittemplate2")) + GET_and_assert_equal_expected_response(self, url, 200, test_data_creator.SchedulingUnitTemplate("schedulingunittemplate2")) def test_scheduling_unit_template_PATCH(self): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_template/', test_data_creator.SchedulingUnitTemplate(), 201, test_data_creator.SchedulingUnitTemplate()) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, test_data_creator.SchedulingUnitTemplate()) + GET_and_assert_equal_expected_response(self, url, 200, test_data_creator.SchedulingUnitTemplate()) test_patch = {"version": 'v6.28318530718', "schema": {"mykey": "my better value"}} @@ -148,18 +187,30 @@ class SchedulingUnitTemplateTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(test_data_creator.SchedulingUnitTemplate()) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_scheduling_unit_template_DELETE(self): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_template/', test_data_creator.SchedulingUnitTemplate(), 201, test_data_creator.SchedulingUnitTemplate()) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, test_data_creator.SchedulingUnitTemplate()) + GET_and_assert_equal_expected_response(self, url, 200, test_data_creator.SchedulingUnitTemplate()) # DELETE and check it's gone DELETE_and_assert_gone(self, url) + def test_GET_scheduling_unit_template_view_returns_correct_entry(self): + """ + Construct two 'scheduling_unit_template' objects and check if GET of separate 'id' URLs results in correct data + """ + test_data_1 = SchedulingUnitTemplate_test_data("scheduling_unit_template_1") + test_data_2 = SchedulingUnitTemplate_test_data("scheduling_unit_template_2") + id1 = models.SchedulingUnitTemplate.objects.create(**test_data_1).id + id2 = models.SchedulingUnitTemplate.objects.create(**test_data_2).id + GET_and_assert_in_expected_response(self, BASE_URL + '/scheduling_unit_template/' + str(id1), test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/scheduling_unit_template/' + str(id2), test_data_2) + + class TaskTemplateTestCase(unittest.TestCase): def test_task_template_list_apiformat(self): @@ -168,14 +219,14 @@ class TaskTemplateTestCase(unittest.TestCase): self.assertTrue("Task Template List" in r.content.decode('utf8')) def test_task_template_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/task_template/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/task_template/1234321/', 404, {}) def test_task_template_POST_and_GET(self): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_template/', test_data_creator.TaskTemplate(), 201, test_data_creator.TaskTemplate()) url = r_dict['url'] - GET_and_assert_expected_response(self, url + '?format=json', 200, test_data_creator.TaskTemplate()) + GET_and_assert_equal_expected_response(self, url + '?format=json', 200, test_data_creator.TaskTemplate()) def test_task_template_PUT_invalid_raises_error(self): PUT_and_assert_expected_response(self, BASE_URL + '/task_template/9876789876/', test_data_creator.TaskTemplate(), 404, {}) @@ -185,18 +236,18 @@ class TaskTemplateTestCase(unittest.TestCase): r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_template/', test_data_creator.TaskTemplate(), 201, test_data_creator.TaskTemplate()) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, test_data_creator.TaskTemplate()) + GET_and_assert_equal_expected_response(self, url, 200, test_data_creator.TaskTemplate()) # PUT new values, verify PUT_and_assert_expected_response(self, url, test_data_creator.TaskTemplate("tasktemplate2"), 200, test_data_creator.TaskTemplate("tasktemplate2")) - GET_and_assert_expected_response(self, url, 200, test_data_creator.TaskTemplate("tasktemplate2")) + GET_and_assert_equal_expected_response(self, url, 200, test_data_creator.TaskTemplate("tasktemplate2")) def test_task_template_PATCH(self): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_template/', test_data_creator.TaskTemplate(), 201, test_data_creator.TaskTemplate()) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, test_data_creator.TaskTemplate()) + GET_and_assert_equal_expected_response(self, url, 200, test_data_creator.TaskTemplate()) test_patch = {"version": 'v6.28318530718', "schema": {"mykey": "my better value"}, @@ -205,18 +256,27 @@ class TaskTemplateTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(test_data_creator.TaskTemplate()) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_task_template_DELETE(self): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_template/', test_data_creator.TaskTemplate(), 201, test_data_creator.TaskTemplate()) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, test_data_creator.TaskTemplate()) + GET_and_assert_equal_expected_response(self, url, 200, test_data_creator.TaskTemplate()) # DELETE and check it's gone DELETE_and_assert_gone(self, url) + def test_GET_task_template_view_returns_correct_entry(self): + + test_data_1 = TaskTemplate_test_data("task_template_1") + test_data_2 = TaskTemplate_test_data("task_template_2") + id1 = models.TaskTemplate.objects.create(**test_data_1).id + id2 = models.TaskTemplate.objects.create(**test_data_2).id + GET_and_assert_in_expected_response(self, BASE_URL + '/task_template/' + str(id1), test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/task_template/' + str(id2), test_data_2) + class WorkRelationSelectionTemplateTestCase(unittest.TestCase): def test_work_relation_selection_template_list_apiformat(self): @@ -225,14 +285,14 @@ class WorkRelationSelectionTemplateTestCase(unittest.TestCase): self.assertTrue("Work Relation Selection Template List" in r.content.decode('utf8')) def test_work_relation_selection_template_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/work_relation_selection_template/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/work_relation_selection_template/1234321/', 404, {}) def test_work_relation_selection_template_POST_and_GET(self): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_relation_selection_template/', test_data_creator.WorkRelationSelectionTemplate(), 201, test_data_creator.WorkRelationSelectionTemplate()) url = r_dict['url'] - GET_and_assert_expected_response(self, url+'?format=json', 200, test_data_creator.WorkRelationSelectionTemplate()) + GET_and_assert_equal_expected_response(self, url+'?format=json', 200, test_data_creator.WorkRelationSelectionTemplate()) def test_work_relation_selection_template_PUT_invalid_raises_error(self): PUT_and_assert_expected_response(self, BASE_URL + '/work_relation_selection_template/9876789876/', test_data_creator.WorkRelationSelectionTemplate(), 404, {}) @@ -242,18 +302,18 @@ class WorkRelationSelectionTemplateTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_relation_selection_template/', test_data_creator.WorkRelationSelectionTemplate(), 201, test_data_creator.WorkRelationSelectionTemplate()) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, test_data_creator.WorkRelationSelectionTemplate()) + GET_and_assert_equal_expected_response(self, url, 200, test_data_creator.WorkRelationSelectionTemplate()) # PUT new values, verify PUT_and_assert_expected_response(self, url, test_data_creator.WorkRelationSelectionTemplate("workrelationselectiontemplate2"), 200, test_data_creator.WorkRelationSelectionTemplate("workrelationselectiontemplate2")) - GET_and_assert_expected_response(self, url, 200, test_data_creator.WorkRelationSelectionTemplate("workrelationselectiontemplate2")) + GET_and_assert_equal_expected_response(self, url, 200, test_data_creator.WorkRelationSelectionTemplate("workrelationselectiontemplate2")) def test_work_relation_selection_template_PATCH(self): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_relation_selection_template/', test_data_creator.WorkRelationSelectionTemplate(), 201, test_data_creator.WorkRelationSelectionTemplate()) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, test_data_creator.WorkRelationSelectionTemplate()) + GET_and_assert_equal_expected_response(self, url, 200, test_data_creator.WorkRelationSelectionTemplate()) test_patch = {"version": 'v6.28318530718', "schema": {"mykey": "my better value"}, @@ -263,18 +323,27 @@ class WorkRelationSelectionTemplateTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(test_data_creator.WorkRelationSelectionTemplate()) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_work_relation_selection_template_DELETE(self): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_relation_selection_template/', test_data_creator.WorkRelationSelectionTemplate(), 201, test_data_creator.WorkRelationSelectionTemplate()) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, test_data_creator.WorkRelationSelectionTemplate()) + GET_and_assert_equal_expected_response(self, url, 200, test_data_creator.WorkRelationSelectionTemplate()) # DELETE and check it's gone DELETE_and_assert_gone(self, url) + def test_GET_work_relation_selection_template_view_returns_correct_entry(self): + + test_data_1 = WorkRelationSelectionTemplate_test_data("work_relation_selection_template_1") + test_data_2 = WorkRelationSelectionTemplate_test_data("work_relation_selection_template_2") + id1 = models.WorkRelationSelectionTemplate.objects.create(**test_data_1).id + id2 = models.WorkRelationSelectionTemplate.objects.create(**test_data_2).id + GET_and_assert_in_expected_response(self, BASE_URL + '/work_relation_selection_template/' + str(id1), test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/work_relation_selection_template/' + str(id2), test_data_2) + class TaskConnectorsTestCase(unittest.TestCase): @classmethod @@ -288,14 +357,14 @@ class TaskConnectorsTestCase(unittest.TestCase): self.assertTrue("Task Connectors List" in r.content.decode('utf8')) def test_task_connectors_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/task_connectors/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/task_connectors/1234321/', 404, {}) def test_task_connectors_POST_and_GET(self): tc_test_data = test_data_creator.TaskConnectors(input_of_url=self.input_of_url, output_of_url=self.output_of_url) # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_connectors/', tc_test_data, 201, tc_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, tc_test_data) + GET_and_assert_equal_expected_response(self, url, 200, tc_test_data) def test_task_connectors_POST_invalid_role_raises_error(self): @@ -358,11 +427,11 @@ class TaskConnectorsTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_connectors/', tc_test_data1, 201, tc_test_data1) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, tc_test_data1) + GET_and_assert_equal_expected_response(self, url, 200, tc_test_data1) # PUT new values, verify PUT_and_assert_expected_response(self, url, tc_test_data2, 200, tc_test_data2) - GET_and_assert_expected_response(self, url, 200, tc_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, tc_test_data2) def test_task_connectors_PATCH(self): tc_test_data = test_data_creator.TaskConnectors(input_of_url=self.input_of_url, output_of_url=self.output_of_url) @@ -370,7 +439,7 @@ class TaskConnectorsTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_connectors/', tc_test_data, 201, tc_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, tc_test_data) + GET_and_assert_equal_expected_response(self, url, 200, tc_test_data) test_patch = {"role": BASE_URL + '/role/calibrator/', "dataformats": [BASE_URL + '/dataformat/Beamformed/', @@ -380,7 +449,7 @@ class TaskConnectorsTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(tc_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_task_connectors_DELETE(self): tc_test_data = test_data_creator.TaskConnectors(input_of_url=self.input_of_url, output_of_url=self.output_of_url) @@ -388,44 +457,43 @@ class TaskConnectorsTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_connectors/', tc_test_data, 201, tc_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, tc_test_data) + GET_and_assert_equal_expected_response(self, url, 200, tc_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) - def test_task_relation_blueprint_CASCADE_behavior_on_inputs_template_deleted(self): input_of_url = test_data_creator.post_data_and_get_url(test_data_creator.TaskTemplate(), '/task_template/') tc_test_data = test_data_creator.TaskConnectors(input_of_url=input_of_url, output_of_url=self.output_of_url) - # POST new item url = POST_and_assert_expected_response(self, BASE_URL + '/task_connectors/', tc_test_data, 201, tc_test_data)['url'] - # verify - GET_and_assert_expected_response(self, url, 200, tc_test_data) - + GET_and_assert_equal_expected_response(self, url, 200, tc_test_data) # DELETE dependency DELETE_and_assert_gone(self, input_of_url) - # assert - GET_and_assert_expected_response(self, url, 404, {}) - + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_task_relation_blueprint_CASCADE_behavior_on_outputs_template_deleted(self): output_of_url = test_data_creator.post_data_and_get_url(test_data_creator.TaskTemplate(), '/task_template/') tc_test_data = test_data_creator.TaskConnectors(input_of_url=self.input_of_url, output_of_url=output_of_url) - # POST new item url = POST_and_assert_expected_response(self, BASE_URL + '/task_connectors/', tc_test_data, 201, tc_test_data)['url'] - # verify - GET_and_assert_expected_response(self, url, 200, tc_test_data) - + GET_and_assert_equal_expected_response(self, url, 200, tc_test_data) # DELETE dependency DELETE_and_assert_gone(self, output_of_url) - # assert - GET_and_assert_expected_response(self, url, 404, {}) + GET_and_assert_equal_expected_response(self, url, 404, {}) + + def test_GET_task_connectors_view_returns_correct_entry(self): + + test_data_1 = TaskConnectors_test_data() + test_data_2 = TaskConnectors_test_data() + id1 = models.TaskConnectors.objects.create(**test_data_1).id + id2 = models.TaskConnectors.objects.create(**test_data_2).id + GET_and_assert_in_expected_response(self, BASE_URL + '/task_connectors/' + str(id1), test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/task_connectors/' + str(id2), test_data_2) class DefaultTemplates(unittest.TestCase): @@ -459,7 +527,6 @@ class DefaultTemplates(unittest.TestCase): test_data_1['template'] = url POST_and_assert_expected_response(self, BASE_URL + '/default_task_template/', test_data_1, 201, test_data_1) - def test_default_work_relation_selection_template_POST(self): r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_relation_selection_template/', test_data_creator.WorkRelationSelectionTemplate(), 201, @@ -486,7 +553,7 @@ class DefaultTemplates(unittest.TestCase): response = requests.delete(template_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, template_url, 200, test_data_creator.GeneratorTemplate()) + GET_and_assert_equal_expected_response(self, template_url, 200, test_data_creator.GeneratorTemplate()) def test_default_scheduling_unit_template_PROTECT_behavior_on_template_deleted(self): @@ -504,8 +571,7 @@ class DefaultTemplates(unittest.TestCase): response = requests.delete(template_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, template_url, 200, test_data_creator.SchedulingUnitTemplate()) - + GET_and_assert_equal_expected_response(self, template_url, 200, test_data_creator.SchedulingUnitTemplate()) def test_default_task_template_PROTECT_behavior_on_template_deleted(self): @@ -523,7 +589,7 @@ class DefaultTemplates(unittest.TestCase): response = requests.delete(template_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, template_url, 200, test_data_creator.TaskTemplate()) + GET_and_assert_equal_expected_response(self, template_url, 200, test_data_creator.TaskTemplate()) def test_default_work_relation_selection_template_PROTECT_behavior_on_template_deleted(self): @@ -541,7 +607,7 @@ class DefaultTemplates(unittest.TestCase): response = requests.delete(template_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, template_url, 200, test_data_creator.WorkRelationSelectionTemplate()) + GET_and_assert_equal_expected_response(self, template_url, 200, test_data_creator.WorkRelationSelectionTemplate()) class CycleTestCase(unittest.TestCase): @@ -551,7 +617,7 @@ class CycleTestCase(unittest.TestCase): self.assertTrue("Cycle List" in r.content.decode('utf8')) def test_cycle_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/cycle/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/cycle/1234321/', 404, {}) def test_cycle_POST_and_GET(self): @@ -559,7 +625,7 @@ class CycleTestCase(unittest.TestCase): cycle_test_data = test_data_creator.Cycle() r_dict = POST_and_assert_expected_response(self, BASE_URL + '/cycle/', cycle_test_data, 201, cycle_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, cycle_test_data) + GET_and_assert_equal_expected_response(self, url, 200, cycle_test_data) def test_cycle_PUT_invalid_raises_error(self): PUT_and_assert_expected_response(self, BASE_URL + '/cycle/9876789876/', test_data_creator.Cycle(), 404, {}) @@ -570,22 +636,20 @@ class CycleTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/cycle/', cycle_test_data, 201, cycle_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, cycle_test_data) + GET_and_assert_equal_expected_response(self, url, 200, cycle_test_data) # PUT new values, verify test_data = dict(test_data_creator.Cycle("other description")) test_data['name'] = cycle_test_data['name'] # since name is PK, need to keep that unchanged PUT_and_assert_expected_response(self, url, test_data, 200, test_data) - GET_and_assert_expected_response(self, url, 200, test_data) + GET_and_assert_equal_expected_response(self, url, 200, test_data) def test_cycle_PATCH(self): cycle_test_data = test_data_creator.Cycle() - # POST new item, verify - r_dict = POST_and_assert_expected_response(self, BASE_URL + '/cycle/', cycle_test_data, 201, cycle_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, cycle_test_data) + GET_and_assert_equal_expected_response(self, url, 200, cycle_test_data) test_patch = {"start": datetime(year=2015, month=10, day=21).isoformat()} @@ -593,19 +657,49 @@ class CycleTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(cycle_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_cycle_DELETE(self): cycle_test_data = test_data_creator.Cycle() - # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/cycle/', cycle_test_data, 201, cycle_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, cycle_test_data) - + GET_and_assert_equal_expected_response(self, url, 200, cycle_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) + def test_GET_cycle_list_shows_entry(self): + + test_data_1 = Cycle_test_data() # uuid makes name unique + models.Cycle.objects.create(**test_data_1) + nbr_results = models.Cycle.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/cycle/', test_data_1, nbr_results) + + def test_GET_cycle_view_returns_correct_entry(self): + + test_data_1 = Cycle_test_data() # uuid makes name unique + test_data_2 = Cycle_test_data() + id1 = models.Cycle.objects.create(**test_data_1).name # name is pk + id2 = models.Cycle.objects.create(**test_data_2).name # name is pk + GET_and_assert_in_expected_response(self, BASE_URL + '/cycle/' + str(id1), test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/cycle/' + str(id2), test_data_2) + + def test_cycle_contains_list_of_releated_projects(self): + + cycle_test_data_1 = Cycle_test_data() + project_test_data_1 = Project_test_data() # uuid makes name unique + project_test_data_2 = Project_test_data() # uuid makes name unique + + cycle = models.Cycle.objects.create(**cycle_test_data_1) + project1 = models.Project.objects.create(**project_test_data_1) + project1.cycle = cycle + project1.save() + project2 = models.Project.objects.create(**project_test_data_2) + project2.cycle = cycle + project2.save() + response_data = GET_and_assert_in_expected_response(self, BASE_URL + '/cycle/' + cycle.name, cycle_test_data_1) + assertUrlList(self, response_data['projects'], [project1, project2]) + class ProjectTestCase(unittest.TestCase): def test_project_list_apiformat(self): @@ -614,7 +708,7 @@ class ProjectTestCase(unittest.TestCase): self.assertTrue("Project List" in r.content.decode('utf8')) def test_project_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/project/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/project/1234321/', 404, {}) def test_project_POST_and_GET(self): project_test_data = test_data_creator.Project() @@ -622,7 +716,7 @@ class ProjectTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project/', project_test_data, 201, project_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, project_test_data) + GET_and_assert_equal_expected_response(self, url, 200, project_test_data) def test_project_PUT_invalid_raises_error(self): PUT_and_assert_expected_response(self, BASE_URL + '/project/9876789876/', test_data_creator.Project(), 404, {}) @@ -633,13 +727,13 @@ class ProjectTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project/', project_test_data, 201, project_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, project_test_data) + GET_and_assert_equal_expected_response(self, url, 200, project_test_data) # PUT new values, verify test_data = dict(test_data_creator.Project("other description")) test_data['name'] = project_test_data['name'] # since name is PK, need to keep that unchanged PUT_and_assert_expected_response(self, url, test_data, 200, test_data) - GET_and_assert_expected_response(self, url, 200, test_data) + GET_and_assert_equal_expected_response(self, url, 200, test_data) def test_project_PATCH(self): project_test_data = test_data_creator.Project() @@ -647,7 +741,7 @@ class ProjectTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project/', project_test_data, 201, project_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, project_test_data) + GET_and_assert_equal_expected_response(self, url, 200, project_test_data) test_patch = {"priority": 500, "tags": ["SUPERIMPORTANT"]} @@ -656,7 +750,7 @@ class ProjectTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(project_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_project_DELETE(self): project_test_data = test_data_creator.Project() @@ -664,7 +758,7 @@ class ProjectTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project/', project_test_data, 201, project_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, project_test_data) + GET_and_assert_equal_expected_response(self, url, 200, project_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -679,7 +773,7 @@ class ProjectTestCase(unittest.TestCase): url = POST_and_assert_expected_response(self, BASE_URL + '/project/', test_data, 201, test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, test_data) + GET_and_assert_equal_expected_response(self, url, 200, test_data) # add project reference to cycle test data (we make Django add that to the cycle in serializer) cycle_test_data['projects'] = [url] # add the @@ -689,7 +783,40 @@ class ProjectTestCase(unittest.TestCase): response = requests.delete(cycle_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, cycle_url, 200, cycle_test_data) + GET_and_assert_equal_expected_response(self, cycle_url, 200, cycle_test_data) + + def test_GET_project_list_shows_entry(self): + + test_data_1 = Project_test_data() # uuid makes name unique + models.Project.objects.create(**test_data_1) + nbr_results = models.Project.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/project/', test_data_1, nbr_results) + + def test_GET_project_view_returns_correct_entry(self): + + test_data_1 = Project_test_data() # uuid makes name unique + test_data_2 = Project_test_data() + id1 = models.Project.objects.create(**test_data_1).name # name is pk + id2 = models.Project.objects.create(**test_data_2).name + GET_and_assert_in_expected_response(self, BASE_URL + '/project/' + str(id1), test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/project/' + str(id2), test_data_2) + + def test_nested_projects_are_filtered_according_to_cycle(self): + + cycle_1 = models.Cycle.objects.create(**Cycle_test_data()) + cycle_2 = models.Cycle.objects.create(**Cycle_test_data()) + test_data_1 = dict(Project_test_data()) # uuid makes project unique + test_data_1['cycle'] = cycle_1 + project_1 = models.Project.objects.create(**test_data_1) + test_data_2 = dict(Project_test_data()) # uuid makes project unique + test_data_2['cycle'] = cycle_2 + project_2 = models.Project.objects.create(**test_data_2) + # assert the returned list contains related items, A list of length 1 is retrieved + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/cycle/%s/project/' % cycle_2.name, test_data_2, 1) + # assert an existing related item is returned, name is pk + GET_and_assert_in_expected_response(self, BASE_URL + '/cycle/%s/project/%s' % (cycle_2.name, project_2.name), test_data_2) + # assert an existing unrelated item is not returned, name is pk + GET_and_assert_equal_expected_code(self, BASE_URL + '/cycle/%s/project/%s' % (cycle_2.name, project_1.name), 404) class SchedulingSetTestCase(unittest.TestCase): @@ -699,7 +826,7 @@ class SchedulingSetTestCase(unittest.TestCase): self.assertTrue("Scheduling Set List" in r.content.decode('utf8')) def test_scheduling_set_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/scheduling_set/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/scheduling_set/1234321/', 404, {}) def test_scheduling_set_POST_and_GET(self): schedulingset_test_data = test_data_creator.SchedulingSet() @@ -707,7 +834,7 @@ class SchedulingSetTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_set/', schedulingset_test_data, 201, schedulingset_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, schedulingset_test_data) + GET_and_assert_equal_expected_response(self, url, 200, schedulingset_test_data) def test_scheduling_set_PUT_invalid_raises_error(self): schedulingset_test_data = test_data_creator.SchedulingSet() @@ -720,12 +847,12 @@ class SchedulingSetTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_set/', schedulingset_test_data, 201, schedulingset_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, schedulingset_test_data) + GET_and_assert_equal_expected_response(self, url, 200, schedulingset_test_data) schedulingset_test_data2 = test_data_creator.SchedulingSet("schedulingset2", project_url=project_url) # PUT new values, verify PUT_and_assert_expected_response(self, url, schedulingset_test_data2, 200, schedulingset_test_data2) - GET_and_assert_expected_response(self, url, 200, schedulingset_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, schedulingset_test_data2) def test_scheduling_set_PATCH(self): schedulingset_test_data = test_data_creator.SchedulingSet() @@ -733,7 +860,7 @@ class SchedulingSetTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_set/', schedulingset_test_data, 201, schedulingset_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, schedulingset_test_data) + GET_and_assert_equal_expected_response(self, url, 200, schedulingset_test_data) test_patch = {"description": "This is a new and improved description", "generator_doc": "{'para': 'meter'}"} @@ -742,7 +869,7 @@ class SchedulingSetTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(schedulingset_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_scheduling_set_DELETE(self): schedulingset_test_data = test_data_creator.SchedulingSet() @@ -750,46 +877,68 @@ class SchedulingSetTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_set/', schedulingset_test_data, 201, schedulingset_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, schedulingset_test_data) + GET_and_assert_equal_expected_response(self, url, 200, schedulingset_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) def test_scheduling_set_PROTECT_behavior_on_project_deleted(self): project_url = test_data_creator.post_data_and_get_url(test_data_creator.Project(), '/project/') - project_test_data = GET_and_assert_expected_response(self, project_url, 200, {}) + project_test_data = GET_and_assert_equal_expected_response(self, project_url, 200, {}) schedulingset_test_data = test_data_creator.SchedulingSet(project_url=project_url) - # POST new item url = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_set/', schedulingset_test_data, 201, schedulingset_test_data)['url'] - # verify - GET_and_assert_expected_response(self, url, 200, schedulingset_test_data) - + GET_and_assert_equal_expected_response(self, url, 200, schedulingset_test_data) # Try to DELETE dependency, verify that was not successful # Unfortunately we don't get a nice error in json, but a Django debug page on error 500... response = requests.delete(project_url, auth=AUTH) self.assertEqual(500, response.status_code) self.assertTrue("ProtectedError" in str(response.content)) - GET_and_assert_expected_response(self, project_url, 200, project_test_data) + GET_and_assert_equal_expected_response(self, project_url, 200, project_test_data) def test_scheduling_set_SET_NULL_behavior_on_generator_template_deleted(self): generator_template_url = test_data_creator.post_data_and_get_url(test_data_creator.GeneratorTemplate(), '/generator_template/') schedulingset_test_data = test_data_creator.SchedulingSet(generator_template_url=generator_template_url) - # POST new item test_data = dict(schedulingset_test_data) url = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_set/', test_data, 201, test_data)['url'] - # verify - GET_and_assert_expected_response(self, url, 200, test_data) - + GET_and_assert_equal_expected_response(self, url, 200, test_data) # DELETE dependency DELETE_and_assert_gone(self, generator_template_url) - # assert test_data['generator_template'] = None - GET_and_assert_expected_response(self, url, 200, test_data) + GET_and_assert_equal_expected_response(self, url, 200, test_data) + + def test_GET_SchedulingSet_list_shows_entry(self): + + test_data_1 = SchedulingSet_test_data() + models.SchedulingSet.objects.create(**test_data_1) + nbr_results = models.SchedulingSet.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/scheduling_set/', test_data_1, nbr_results) + + def test_GET_SchedulingSet_view_returns_correct_entry(self): + + test_data_1 = SchedulingSet_test_data() # uuid makes name unique + test_data_2 = SchedulingSet_test_data() + id1 = models.SchedulingSet.objects.create(**test_data_1).id + id2 = models.SchedulingSet.objects.create(**test_data_2).id + GET_and_assert_in_expected_response(self, BASE_URL + '/scheduling_set/' + str(id1), test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/scheduling_set/' + str(id2), test_data_2) + + def test_SchedulingSet_contains_list_of_releated_SchedulingUnitDraft(self): + + test_data_1 = SchedulingSet_test_data() + scheduling_set = models.SchedulingSet.objects.create(**test_data_1) + scheduling_unit_draft_1 = models.SchedulingUnitDraft.objects.create(**SchedulingUnitDraft_test_data("scheduler draft one")) + scheduling_unit_draft_1.scheduling_set = scheduling_set + scheduling_unit_draft_1.save() + scheduling_unit_draft_2 = models.SchedulingUnitDraft.objects.create(**SchedulingUnitDraft_test_data("scheduler draft one")) + scheduling_unit_draft_2.scheduling_set = scheduling_set + scheduling_unit_draft_2.save() + response_data = GET_and_assert_in_expected_response(self, BASE_URL + '/scheduling_set/%d' % scheduling_set.id, test_data_1) + assertUrlList(self, response_data['scheduling_unit_drafts'], [scheduling_unit_draft_1, scheduling_unit_draft_2]) class SchedulingUnitDraftTestCase(unittest.TestCase): @@ -804,7 +953,7 @@ class SchedulingUnitDraftTestCase(unittest.TestCase): self.assertTrue("Scheduling Unit Draft List" in r.content.decode('utf8')) def test_scheduling_unit_draft_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_draft/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/scheduling_unit_draft/1234321/', 404, {}) def test_scheduling_unit_draft_POST_and_GET(self): schedulingunitdraft_test_data = test_data_creator.SchedulingUnitDraft(scheduling_set_url=self.scheduling_set_url, template_url=self.template_url) @@ -812,7 +961,7 @@ class SchedulingUnitDraftTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_draft/', schedulingunitdraft_test_data, 201, schedulingunitdraft_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, schedulingunitdraft_test_data) + GET_and_assert_equal_expected_response(self, url, 200, schedulingunitdraft_test_data) def test_scheduling_unit_draft_PUT_invalid_raises_error(self): schedulingunitdraft_test_data = test_data_creator.SchedulingUnitDraft(scheduling_set_url=self.scheduling_set_url, template_url=self.template_url) @@ -824,13 +973,13 @@ class SchedulingUnitDraftTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_draft/', schedulingunitdraft_test_data, 201, schedulingunitdraft_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, schedulingunitdraft_test_data) + GET_and_assert_equal_expected_response(self, url, 200, schedulingunitdraft_test_data) schedulingunitdraft_test_data2 = test_data_creator.SchedulingUnitDraft("my_scheduling_unit_draft2", scheduling_set_url=self.scheduling_set_url, template_url=self.template_url) # PUT new values, verify PUT_and_assert_expected_response(self, url, schedulingunitdraft_test_data2, 200, schedulingunitdraft_test_data2) - GET_and_assert_expected_response(self, url, 200, schedulingunitdraft_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, schedulingunitdraft_test_data2) def test_scheduling_unit_draft_PATCH(self): schedulingunitdraft_test_data = test_data_creator.SchedulingUnitDraft(scheduling_set_url=self.scheduling_set_url, template_url=self.template_url) @@ -838,7 +987,7 @@ class SchedulingUnitDraftTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_draft/', schedulingunitdraft_test_data, 201, schedulingunitdraft_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, schedulingunitdraft_test_data) + GET_and_assert_equal_expected_response(self, url, 200, schedulingunitdraft_test_data) test_patch = {"description": "This is a new and improved description", "requirements_doc": "{'para': 'meter'}"} @@ -847,7 +996,7 @@ class SchedulingUnitDraftTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(schedulingunitdraft_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_scheduling_unit_draft_DELETE(self): schedulingunitdraft_test_data = test_data_creator.SchedulingUnitDraft(scheduling_set_url=self.scheduling_set_url, template_url=self.template_url) @@ -855,7 +1004,7 @@ class SchedulingUnitDraftTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_draft/', schedulingunitdraft_test_data, 201, schedulingunitdraft_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, schedulingunitdraft_test_data) + GET_and_assert_equal_expected_response(self, url, 200, schedulingunitdraft_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -863,34 +1012,26 @@ class SchedulingUnitDraftTestCase(unittest.TestCase): def test_scheduling_unit_draft_CASCADE_behavior_on_scheduling_unit_template_deleted(self): template_url = test_data_creator.post_data_and_get_url(test_data_creator.SchedulingUnitTemplate(), '/scheduling_unit_template/') schedulingunitdraft_test_data = test_data_creator.SchedulingUnitDraft(template_url=template_url, scheduling_set_url=self.scheduling_set_url) - # POST new item url = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_draft/', schedulingunitdraft_test_data, 201, schedulingunitdraft_test_data)['url'] - # verify - GET_and_assert_expected_response(self, url, 200, schedulingunitdraft_test_data) - + GET_and_assert_equal_expected_response(self, url, 200, schedulingunitdraft_test_data) # DELETE dependency DELETE_and_assert_gone(self, template_url) - # assert - GET_and_assert_expected_response(self, url, 404, {}) + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_scheduling_unit_draft_CASCADE_behavior_on_scheduling_set_deleted(self): scheduling_set_url = test_data_creator.post_data_and_get_url(test_data_creator.SchedulingSet(), '/scheduling_set/') schedulingunitdraft_test_data = test_data_creator.SchedulingUnitDraft(scheduling_set_url=scheduling_set_url, template_url=self.template_url) - # POST new item url = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_draft/', schedulingunitdraft_test_data, 201, schedulingunitdraft_test_data)['url'] - # verify - GET_and_assert_expected_response(self, url, 200, schedulingunitdraft_test_data) - + GET_and_assert_equal_expected_response(self, url, 200, schedulingunitdraft_test_data) # DELETE dependency DELETE_and_assert_gone(self, scheduling_set_url) - # assert - GET_and_assert_expected_response(self, url, 404, {}) + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_scheduling_unit_draft_SET_NULL_behavior_on_copies_deleted(self): schedulingunitdraft_test_data = test_data_creator.SchedulingUnitDraft(scheduling_set_url=self.scheduling_set_url, template_url=self.template_url) @@ -900,16 +1041,89 @@ class SchedulingUnitDraftTestCase(unittest.TestCase): test_data = dict(schedulingunitdraft_test_data) test_data['copies'] = copy_url url = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_draft/', test_data, 201, test_data)['url'] - # verify - GET_and_assert_expected_response(self, url, 200, test_data) - + GET_and_assert_equal_expected_response(self, url, 200, test_data) # DELETE dependency DELETE_and_assert_gone(self, copy_url) - # assert test_data['copies'] = None - GET_and_assert_expected_response(self, url, 200, test_data) + GET_and_assert_equal_expected_response(self, url, 200, test_data) + + def test_GET_SchedulingUnitDraft_list_view_shows_entry(self): + + test_data_1 = SchedulingUnitDraft_test_data("scheduler unit draft one") + models.SchedulingUnitDraft.objects.create(**test_data_1) + nbr_results = models.SchedulingUnitDraft.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/scheduling_unit_draft/', test_data_1, nbr_results) + + def test_GET_SchedulingUnitDraft_view_returns_correct_entry(self): + + test_data_1 = SchedulingUnitDraft_test_data("scheduler unit draft one one") + test_data_2 = SchedulingUnitDraft_test_data("scheduler unit draft one two") + id1 = models.SchedulingUnitDraft.objects.create(**test_data_1).id + id2 = models.SchedulingUnitDraft.objects.create(**test_data_2).id + GET_and_assert_in_expected_response(self, BASE_URL + '/scheduling_unit_draft/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/scheduling_unit_draft/%s/' % id2, test_data_2) + + def test_nested_SchedulingUnitDraft_are_filtered_according_to_SchedulingSet(self): + # setup + test_data_1 = SchedulingUnitDraft_test_data("scheduler unit draft two one") + test_data_2 = SchedulingUnitDraft_test_data("scheduler unit draft two two") + sst_test_data_1 = SchedulingSet_test_data("scheduler set one") + sst_test_data_2 = SchedulingSet_test_data("scheduler set two") + scheduling_set_1 = models.SchedulingSet.objects.create(**sst_test_data_1) + scheduling_set_2 = models.SchedulingSet.objects.create(**sst_test_data_2) + test_data_1 = dict(test_data_1) + test_data_1['scheduling_set'] = scheduling_set_1 + scheduling_unit_draft_1 = models.SchedulingUnitDraft.objects.create(**test_data_1) + test_data_2 = dict(test_data_2) + test_data_2['scheduling_set'] = scheduling_set_2 + scheduling_unit_draft_2 = models.SchedulingUnitDraft.objects.create(**test_data_2) + + # assert the returned list contains related items, A list of length 1 is retrieved + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/scheduling_set/%s/scheduling_unit_draft/' + % scheduling_set_2.id, test_data_2, 1) + # assert an existing related item is returned + GET_and_assert_in_expected_response(self, BASE_URL + '/scheduling_set/%s/scheduling_unit_draft/%s/' % + (scheduling_set_2.id, scheduling_unit_draft_2.id), test_data_2) + # assert an existing unrelated item is not returned + GET_and_assert_equal_expected_code(self, BASE_URL + '/scheduling_set/%s/scheduling_unit_draft/%s/' % + (scheduling_set_2.id, scheduling_unit_draft_1.id), 404) + + def test_SchedulingUnitDraft_contains_list_of_related_SchedulingUnitBlueprint(self): + + # setup + test_data_1 = SchedulingUnitDraft_test_data("scheduler unit draft one") + subt_test_data_1 = SchedulingUnitBlueprint_test_data("scheduler unit blue print one") + subt_test_data_2 = SchedulingUnitBlueprint_test_data("scheduler unit blue print two") + scheduling_unit_draft = models.SchedulingUnitDraft.objects.create(**test_data_1) + scheduling_unit_blueprint_1 = models.SchedulingUnitBlueprint.objects.create(**subt_test_data_1) + scheduling_unit_blueprint_1.draft = scheduling_unit_draft + scheduling_unit_blueprint_1.save() + scheduling_unit_blueprint_2 = models.SchedulingUnitBlueprint.objects.create(**subt_test_data_2) + scheduling_unit_blueprint_2.draft = scheduling_unit_draft + scheduling_unit_blueprint_2.save() + # assert + response_data = GET_and_assert_in_expected_response(self, BASE_URL + '/scheduling_unit_draft/%s/' % scheduling_unit_draft.id, test_data_1) + assertUrlList(self, response_data['related_scheduling_unit_blueprint'], [scheduling_unit_blueprint_1, scheduling_unit_blueprint_2]) + + def test_SchedulingUnitDraft_contains_list_of_related_TaskDraft(self): + + # setup + test_data_1 = SchedulingUnitDraft_test_data("scheduler unit draft one") + tdt_test_data_1 = TaskDraft_test_data("task draft one") + tdt_test_data_2 = TaskDraft_test_data("task draft two") + scheduling_unit_draft = models.SchedulingUnitDraft.objects.create(**test_data_1) + task_draft_1 = models.TaskDraft.objects.create(**tdt_test_data_1) + task_draft_1.scheduling_unit_draft = scheduling_unit_draft + task_draft_1.save() + task_draft_2 = models.TaskDraft.objects.create(**tdt_test_data_2) + task_draft_2.scheduling_unit_draft = scheduling_unit_draft + task_draft_2.save() + # assert + response_data = GET_and_assert_in_expected_response(self, BASE_URL + '/scheduling_unit_draft/%s/' % + scheduling_unit_draft.id, test_data_1) + assertUrlList(self, response_data['task_drafts'], [task_draft_1, task_draft_2]) class TaskDraftTestCase(unittest.TestCase): @@ -924,7 +1138,7 @@ class TaskDraftTestCase(unittest.TestCase): self.assertTrue("Task Draft List" in r.content.decode('utf8')) def test_task_draft_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/task_draft/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/task_draft/1234321/', 404, {}) def test_task_draft_POST_and_GET(self): taskdraft_test_data = test_data_creator.TaskDraft(scheduling_unit_draft_url=self.scheduling_unit_draft_url, template_url=self.template_url) @@ -932,7 +1146,7 @@ class TaskDraftTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_draft/', taskdraft_test_data, 201, taskdraft_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, taskdraft_test_data) + GET_and_assert_equal_expected_response(self, url, 200, taskdraft_test_data) def test_task_draft_PUT_invalid_raises_error(self): taskdraft_test_data = test_data_creator.TaskDraft(scheduling_unit_draft_url=self.scheduling_unit_draft_url, template_url=self.template_url) @@ -945,11 +1159,11 @@ class TaskDraftTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_draft/', taskdraft_test_data1, 201, taskdraft_test_data1) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, taskdraft_test_data1) + GET_and_assert_equal_expected_response(self, url, 200, taskdraft_test_data1) # PUT new values, verify PUT_and_assert_expected_response(self, url, taskdraft_test_data2, 200, taskdraft_test_data2) - GET_and_assert_expected_response(self, url, 200, taskdraft_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, taskdraft_test_data2) def test_task_draft_PATCH(self): taskdraft_test_data = test_data_creator.TaskDraft(scheduling_unit_draft_url=self.scheduling_unit_draft_url, template_url=self.template_url) @@ -957,7 +1171,7 @@ class TaskDraftTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_draft/', taskdraft_test_data, 201, taskdraft_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, taskdraft_test_data) + GET_and_assert_equal_expected_response(self, url, 200, taskdraft_test_data) test_patch = {"description": "This is a new and improved description", "specifications_doc": "{'para': 'meter'}"} @@ -966,7 +1180,7 @@ class TaskDraftTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(taskdraft_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_task_draft_DELETE(self): taskdraft_test_data = test_data_creator.TaskDraft(scheduling_unit_draft_url=self.scheduling_unit_draft_url, template_url=self.template_url) @@ -974,7 +1188,7 @@ class TaskDraftTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_draft/', taskdraft_test_data, 201, taskdraft_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, taskdraft_test_data) + GET_and_assert_equal_expected_response(self, url, 200, taskdraft_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -987,13 +1201,13 @@ class TaskDraftTestCase(unittest.TestCase): url = POST_and_assert_expected_response(self, BASE_URL + '/task_draft/', taskdraft_test_data, 201, taskdraft_test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, taskdraft_test_data) + GET_and_assert_equal_expected_response(self, url, 200, taskdraft_test_data) # DELETE dependency DELETE_and_assert_gone(self, template_url) # assert - GET_and_assert_expected_response(self, url, 404, {}) + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_task_draft_CASCADE_behavior_on_scheduling_unit_draft_deleted(self): scheduling_unit_draft_url = test_data_creator.post_data_and_get_url(test_data_creator.SchedulingUnitDraft(), '/scheduling_unit_draft/') @@ -1003,13 +1217,13 @@ class TaskDraftTestCase(unittest.TestCase): url = POST_and_assert_expected_response(self, BASE_URL + '/task_draft/', taskdraft_test_data, 201, taskdraft_test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, taskdraft_test_data) + GET_and_assert_equal_expected_response(self, url, 200, taskdraft_test_data) # DELETE dependency DELETE_and_assert_gone(self, scheduling_unit_draft_url) # assert - GET_and_assert_expected_response(self, url, 404, {}) + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_task_draft_SET_NULL_behavior_on_copies_deleted(self): taskdraft_test_data1 = test_data_creator.TaskDraft(name="the one", scheduling_unit_draft_url=self.scheduling_unit_draft_url, template_url=self.template_url) @@ -1022,14 +1236,89 @@ class TaskDraftTestCase(unittest.TestCase): url = POST_and_assert_expected_response(self, BASE_URL + '/task_draft/', test_data, 201, test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, test_data) + GET_and_assert_equal_expected_response(self, url, 200, test_data) # DELETE dependency DELETE_and_assert_gone(self, copy_url) # assert test_data['copies'] = None - GET_and_assert_expected_response(self, url, 200, test_data) + GET_and_assert_equal_expected_response(self, url, 200, test_data) + + def test_GET_TaskDraft_list_view_shows_entry(self): + + test_data_1 = TaskDraft_test_data("task draft") + models.TaskDraft.objects.create(**test_data_1) + nbr_results = models.TaskDraft.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/task_draft/', test_data_1, nbr_results) + + def test_GET_TaskDraft_view_returns_correct_entry(self): + + # setup + test_data_1 = TaskDraft_test_data("task draft one") + test_data_2 = TaskDraft_test_data("task draft two") + id1 = models.TaskDraft.objects.create(**test_data_1).id + id2 = models.TaskDraft.objects.create(**test_data_2).id + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/task_draft/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/task_draft/%s/' % id2, test_data_2) + + def test_nested_TaskDraft_are_filtered_according_to_SchedulingUnitDraft(self): + + # setup + test_data_1 = TaskDraft_test_data("task draft one") + test_data_2 = TaskDraft_test_data("task draft two") + sudt_test_data_1 = SchedulingUnitDraft_test_data("scheduling unit draft one") + sudt_test_data_2 = SchedulingUnitDraft_test_data("scheduling unit draft two") + scheduling_unit_draft_1 = models.SchedulingUnitDraft.objects.create(**sudt_test_data_1) + scheduling_unit_draft_2 = models.SchedulingUnitDraft.objects.create(**sudt_test_data_2) + test_data_1 = dict(test_data_1) + test_data_1['scheduling_unit_draft'] = scheduling_unit_draft_1 + task_draft_1 = models.TaskDraft.objects.create(**test_data_1) + test_data_2 = dict(test_data_2) + test_data_2['scheduling_unit_draft'] = scheduling_unit_draft_2 + task_draft_2 = models.TaskDraft.objects.create(**test_data_2) + # assert the returned list contains related items, A list of length 1 is retrieved + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/scheduling_unit_draft/%s/task_draft/' % scheduling_unit_draft_2.id, test_data_2, 1) + # assert an existing related item is returned + GET_and_assert_in_expected_response(self, BASE_URL + '/scheduling_unit_draft/%s/task_draft/%s/' % (scheduling_unit_draft_2.id, task_draft_2.id), test_data_2) + # assert an existing unrelated item is not returned + GET_and_assert_equal_expected_code(self, BASE_URL + '/scheduling_unit_draft/%s/task_draft/%s/' % (scheduling_unit_draft_2.id, task_draft_1.id), 404) + + def test_TaskDraft_contains_list_of_related_TaskBlueprint(self): + + # setup + test_data_1 = TaskDraft_test_data("task draft one") + tbt_test_data_1 = TaskBlueprint_test_data() + tbt_test_data_2 = TaskBlueprint_test_data() + task_draft = models.TaskDraft.objects.create(**test_data_1) + task_blueprint_1 = models.TaskBlueprint.objects.create(**tbt_test_data_1) + task_blueprint_1.draft = task_draft + task_blueprint_1.save() + task_blueprint_2 = models.TaskBlueprint.objects.create(**tbt_test_data_2) + task_blueprint_2.draft = task_draft + task_blueprint_2.save() + # assert + response_data = GET_and_assert_in_expected_response(self, BASE_URL + '/task_draft/%s/' % task_draft.id, test_data_1) + assertUrlList(self, response_data['related_task_blueprint'], [task_blueprint_1, task_blueprint_2]) + + def test_TaskDraft_contains_lists_of_related_TaskRelationDraft(self): + + # setup + test_data_1 = TaskDraft_test_data("task draft one") + trdt_test_data_1 = TaskRelationDraft_test_data() + trdt_test_data_2 = TaskRelationDraft_test_data() + task_draft = models.TaskDraft.objects.create(**test_data_1) + task_relation_draft_1 = models.TaskRelationDraft.objects.create(**trdt_test_data_1) + task_relation_draft_1.producer = task_draft + task_relation_draft_1.save() + task_relation_draft_2 = models.TaskRelationDraft.objects.create(**trdt_test_data_2) + task_relation_draft_2.consumer = task_draft + task_relation_draft_2.save() + # assert + response_data = GET_and_assert_in_expected_response(self, BASE_URL + '/task_draft/%s/' % task_draft.id, test_data_1) + assertUrlList(self, response_data['produced_by'], [task_relation_draft_1]) + assertUrlList(self, response_data['consumed_by'], [task_relation_draft_2]) class TaskRelationDraftTestCase(unittest.TestCase): @@ -1047,7 +1336,7 @@ class TaskRelationDraftTestCase(unittest.TestCase): self.assertTrue("Task Relation Draft List" in r.content.decode('utf8')) def test_task_relation_draft_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/task_relation_draft/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/task_relation_draft/1234321/', 404, {}) def test_task_relation_draft_POST_and_GET(self): trd_test_data = test_data_creator.TaskRelationDraft(producer_url=self.producer_url, consumer_url=self.consumer_url, template_url=self.template_url, input_url=self.input_url, output_url=self.output_url) @@ -1055,7 +1344,7 @@ class TaskRelationDraftTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_relation_draft/', trd_test_data, 201, trd_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, trd_test_data) + GET_and_assert_equal_expected_response(self, url, 200, trd_test_data) def test_task_relation_draft_PUT_invalid_raises_error(self): trd_test_data = test_data_creator.TaskRelationDraft(producer_url=self.producer_url, consumer_url=self.consumer_url, template_url=self.template_url, input_url=self.input_url, output_url=self.output_url) @@ -1068,11 +1357,11 @@ class TaskRelationDraftTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_relation_draft/', trd_test_data1, 201, trd_test_data1) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, trd_test_data1) + GET_and_assert_equal_expected_response(self, url, 200, trd_test_data1) # PUT new values, verify PUT_and_assert_expected_response(self, url, trd_test_data2, 200, trd_test_data2) - GET_and_assert_expected_response(self, url, 200, trd_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, trd_test_data2) def test_task_relation_draft_PATCH(self): trd_test_data = test_data_creator.TaskRelationDraft(producer_url=self.producer_url, consumer_url=self.consumer_url, template_url=self.template_url, input_url=self.input_url, output_url=self.output_url) @@ -1080,7 +1369,7 @@ class TaskRelationDraftTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_relation_draft/', trd_test_data, 201, trd_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, trd_test_data) + GET_and_assert_equal_expected_response(self, url, 200, trd_test_data) test_patch = {"selection_doc": "{'para': 'meter'}"} @@ -1088,7 +1377,7 @@ class TaskRelationDraftTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(trd_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_task_relation_draft_DELETE(self): trd_test_data = test_data_creator.TaskRelationDraft(producer_url=self.producer_url, consumer_url=self.consumer_url, template_url=self.template_url, input_url=self.input_url, output_url=self.output_url) @@ -1096,7 +1385,7 @@ class TaskRelationDraftTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_relation_draft/', trd_test_data, 201, trd_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, trd_test_data) + GET_and_assert_equal_expected_response(self, url, 200, trd_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -1109,13 +1398,13 @@ class TaskRelationDraftTestCase(unittest.TestCase): url = POST_and_assert_expected_response(self, BASE_URL + '/task_relation_draft/', trd_test_data, 201, trd_test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, trd_test_data) + GET_and_assert_equal_expected_response(self, url, 200, trd_test_data) # DELETE dependency DELETE_and_assert_gone(self, template_url) # assert - GET_and_assert_expected_response(self, url, 404, {}) + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_task_relation_draft_CASCADE_behavior_on_producer_deleted(self): producer_url = test_data_creator.post_data_and_get_url(test_data_creator.TaskDraft(), '/task_draft/') @@ -1126,14 +1415,13 @@ class TaskRelationDraftTestCase(unittest.TestCase): trd_test_data, 201, trd_test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, trd_test_data) + GET_and_assert_equal_expected_response(self, url, 200, trd_test_data) # DELETE dependency DELETE_and_assert_gone(self, producer_url) # assert - GET_and_assert_expected_response(self, url, 404, {}) - + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_task_relation_draft_CASCADE_behavior_on_consumer_deleted(self): consumer_url = test_data_creator.post_data_and_get_url(test_data_creator.TaskDraft(), '/task_draft/') @@ -1144,14 +1432,13 @@ class TaskRelationDraftTestCase(unittest.TestCase): trd_test_data, 201, trd_test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, trd_test_data) + GET_and_assert_equal_expected_response(self, url, 200, trd_test_data) # DELETE dependency DELETE_and_assert_gone(self, consumer_url) # assert - GET_and_assert_expected_response(self, url, 404, {}) - + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_task_relation_draft_CASCADE_behavior_on_input_deleted(self): input_url = test_data_creator.post_data_and_get_url(test_data_creator.TaskConnectors(), '/task_connectors/') @@ -1162,14 +1449,13 @@ class TaskRelationDraftTestCase(unittest.TestCase): trd_test_data, 201, trd_test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, trd_test_data) + GET_and_assert_equal_expected_response(self, url, 200, trd_test_data) # DELETE dependency DELETE_and_assert_gone(self, input_url) # assert - GET_and_assert_expected_response(self, url, 404, {}) - + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_task_relation_draft_CASCADE_behavior_on_output_deleted(self): output_url = test_data_creator.post_data_and_get_url(test_data_creator.TaskConnectors(), '/task_connectors/') @@ -1180,13 +1466,55 @@ class TaskRelationDraftTestCase(unittest.TestCase): trd_test_data, 201, trd_test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, trd_test_data) + GET_and_assert_equal_expected_response(self, url, 200, trd_test_data) # DELETE dependency DELETE_and_assert_gone(self, output_url) # assert - GET_and_assert_expected_response(self, url, 404, {}) + GET_and_assert_equal_expected_response(self, url, 404, {}) + + def test_GET_TaskRelationDraft_list_view_shows_entry(self): + + test_data_1 = TaskRelationDraft_test_data() + models.TaskRelationDraft.objects.create(**test_data_1) + nbr_results = models.TaskRelationDraft.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/task_relation_draft/', test_data_1, nbr_results) + + def test_GET_TaskRelationDraft_view_returns_correct_entry(self): + + # setup + test_data_1 = TaskRelationDraft_test_data() + test_data_2 = TaskRelationDraft_test_data() + id1 = models.TaskRelationDraft.objects.create(**test_data_1).id + id2 = models.TaskRelationDraft.objects.create(**test_data_2).id + GET_and_assert_in_expected_response(self, BASE_URL + '/task_relation_draft/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/task_relation_draft/%s/' % id2, test_data_2) + + def test_nested_TaskRelationDraft_are_filtered_according_to_TaskDraft(self): + + # setup + test_data_1 = TaskRelationDraft_test_data() + test_data_2 = TaskRelationDraft_test_data() + tdt_test_data_1 = TaskDraft_test_data() + tdt_test_data_2 = TaskDraft_test_data() + task_draft_1 = models.TaskDraft.objects.create(**tdt_test_data_1) + task_draft_2 = models.TaskDraft.objects.create(**tdt_test_data_2) + test_data_1 = dict(test_data_1) + test_data_1['producer'] = task_draft_1 + task_relation_draft_1 = models.TaskRelationDraft.objects.create(**test_data_1) + test_data_2 = dict(test_data_2) + test_data_2['consumer'] = task_draft_2 + task_relation_draft_2 = models.TaskRelationDraft.objects.create(**test_data_2) + + # assert the returned list contains related items, A list of length 1 is retrieved + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/task_draft/%s/task_relation_draft/' % task_draft_2.id, test_data_2, 1) + # assert an existing related producer is returned + GET_and_assert_in_expected_response(self, BASE_URL + '/task_draft/%s/task_relation_draft/%s/' % (task_draft_1.id, task_relation_draft_1.id), test_data_1) + # assert an existing related consumer is returned + GET_and_assert_in_expected_response(self, BASE_URL + '/task_draft/%s/task_relation_draft/%s/' % (task_draft_2.id, task_relation_draft_2.id), test_data_2) + # assert an existing unrelated item is not returned + GET_and_assert_equal_expected_code(self, BASE_URL + '/task_draft/%s/task_relation_draft/%s/' % (task_draft_2.id, task_relation_draft_1.id), 404) class SchedulingUnitBlueprintTestCase(unittest.TestCase): @@ -1201,7 +1529,7 @@ class SchedulingUnitBlueprintTestCase(unittest.TestCase): self.assertTrue("Scheduling Unit Blueprint List" in r.content.decode('utf8')) def test_scheduling_unit_blueprint_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_blueprint/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/scheduling_unit_blueprint/1234321/', 404, {}) def test_scheduling_unit_blueprint_POST_and_GET(self): sub_test_data = test_data_creator.SchedulingUnitBlueprint(scheduling_unit_draft_url=self.scheduling_unit_draft_url, template_url=self.template_url) @@ -1209,7 +1537,7 @@ class SchedulingUnitBlueprintTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_blueprint/', sub_test_data, 201, sub_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, sub_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sub_test_data) def test_scheduling_unit_blueprint_PUT_invalid_raises_error(self): sub_test_data = test_data_creator.SchedulingUnitBlueprint(scheduling_unit_draft_url=self.scheduling_unit_draft_url, template_url=self.template_url) @@ -1222,11 +1550,11 @@ class SchedulingUnitBlueprintTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_blueprint/', sub_test_data1, 201, sub_test_data1) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, sub_test_data1) + GET_and_assert_equal_expected_response(self, url, 200, sub_test_data1) # PUT new values, verify PUT_and_assert_expected_response(self, url, sub_test_data2, 200, sub_test_data2) - GET_and_assert_expected_response(self, url, 200, sub_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, sub_test_data2) def test_scheduling_unit_blueprint_PATCH(self): sub_test_data = test_data_creator.SchedulingUnitBlueprint(scheduling_unit_draft_url=self.scheduling_unit_draft_url, template_url=self.template_url) @@ -1234,7 +1562,7 @@ class SchedulingUnitBlueprintTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_blueprint/', sub_test_data, 201, sub_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, sub_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sub_test_data) test_patch = {"description": "This is an updated description", "do_cancel": True} @@ -1243,7 +1571,7 @@ class SchedulingUnitBlueprintTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(sub_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_scheduling_unit_blueprint_DELETE(self): sub_test_data = test_data_creator.SchedulingUnitBlueprint(scheduling_unit_draft_url=self.scheduling_unit_draft_url, template_url=self.template_url) @@ -1251,7 +1579,7 @@ class SchedulingUnitBlueprintTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_blueprint/', sub_test_data, 201, sub_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, sub_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sub_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -1264,13 +1592,13 @@ class SchedulingUnitBlueprintTestCase(unittest.TestCase): url = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_blueprint/', sub_test_data, 201, sub_test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, sub_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sub_test_data) # DELETE dependency DELETE_and_assert_gone(self, template_url) # assert - GET_and_assert_expected_response(self, url, 404, {}) + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_scheduling_unit_blueprint_CASCADE_behavior_on_scheduling_unit_draft_deleted(self): scheduling_unit_draft_url = test_data_creator.post_data_and_get_url(test_data_creator.SchedulingUnitDraft(), '/scheduling_unit_draft/') @@ -1280,13 +1608,55 @@ class SchedulingUnitBlueprintTestCase(unittest.TestCase): url = POST_and_assert_expected_response(self, BASE_URL + '/scheduling_unit_blueprint/', sub_test_data, 201, sub_test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, sub_test_data) + GET_and_assert_equal_expected_response(self, url, 200, sub_test_data) # DELETE dependency DELETE_and_assert_gone(self, scheduling_unit_draft_url) # assert - GET_and_assert_expected_response(self, url, 404, {}) + GET_and_assert_equal_expected_response(self, url, 404, {}) + + def test_GET_SchedulingUnitBlueprint_list_view_shows_entry(self): + + test_data_1 = SchedulingUnitBlueprint_test_data("scheduler unit blue print one") + models.SchedulingUnitBlueprint.objects.create(**test_data_1) + nbr_results = models.SchedulingUnitBlueprint.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/scheduling_unit_blueprint/', test_data_1, nbr_results) + + def test_GET_SchedulingUnitBlueprint_view_returns_correct_entry(self): + + # setup + test_data_1 = SchedulingUnitBlueprint_test_data("scheduler unit blue print two one ") + test_data_2 = SchedulingUnitBlueprint_test_data("scheduler unit blue print two two ") + id1 = models.SchedulingUnitBlueprint.objects.create(**test_data_1).id + id2 = models.SchedulingUnitBlueprint.objects.create(**test_data_2).id + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/scheduling_unit_blueprint/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/scheduling_unit_blueprint/%s/' % id2, test_data_2) + + def test_nested_SchedulingUnitBlueprint_are_filtered_according_to_SchedulingUnitDraft(self): + + # setup + test_data_1 = SchedulingUnitBlueprint_test_data("scheduler unit blue print three one") + test_data_2 = SchedulingUnitBlueprint_test_data("scheduler unit blue print three two") + sudt_test_data_1 = SchedulingUnitDraft_test_data() + sudt_test_data_2 = SchedulingUnitDraft_test_data() + scheduling_unit_draft_1 = models.SchedulingUnitDraft.objects.create(**sudt_test_data_1) + scheduling_unit_draft_2 = models.SchedulingUnitDraft.objects.create(**sudt_test_data_2) + test_data_1 = dict(test_data_1) + test_data_1['draft'] = scheduling_unit_draft_1 + scheduling_unit_blueprint_1 = models.SchedulingUnitBlueprint.objects.create(**test_data_1) + test_data_2 = dict(test_data_2) + test_data_2['draft'] = scheduling_unit_draft_2 + scheduling_unit_blueprint_2 = models.SchedulingUnitBlueprint.objects.create(**test_data_2) + + # assert the returned list contains related items, A list of length 1 is retrieved + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/scheduling_unit_draft/%s/scheduling_unit_blueprint/' % scheduling_unit_draft_2.id, test_data_2, 1) + # assert an existing related item is returned + GET_and_assert_in_expected_response(self, BASE_URL + '/scheduling_unit_draft/%s/scheduling_unit_blueprint/%s/' % (scheduling_unit_draft_2.id, scheduling_unit_blueprint_2.id), test_data_2) + # assert an existing unrelated item is not returned + GET_and_assert_equal_expected_code(self, BASE_URL + '/scheduling_unit_draft/%s/scheduling_unit_blueprint/%s/' % (scheduling_unit_draft_2.id, scheduling_unit_blueprint_1.id), 404) + class TaskBlueprintTestCase(unittest.TestCase): @classmethod @@ -1301,7 +1671,7 @@ class TaskBlueprintTestCase(unittest.TestCase): self.assertTrue("Task Blueprint List" in r.content.decode('utf8')) def test_task_blueprint_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/task_blueprint/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/task_blueprint/1234321/', 404, {}) def test_task_blueprint_POST_and_GET(self): tb_test_data = test_data_creator.TaskBlueprint(draft_url=self.draft_url, template_url=self.template_url, scheduling_unit_blueprint_url=self.scheduling_unit_blueprint_url) @@ -1309,7 +1679,7 @@ class TaskBlueprintTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_blueprint/', tb_test_data, 201, tb_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, tb_test_data) + GET_and_assert_equal_expected_response(self, url, 200, tb_test_data) def test_task_blueprint_PUT_invalid_raises_error(self): tb_test_data = test_data_creator.TaskBlueprint(draft_url=self.draft_url, template_url=self.template_url, scheduling_unit_blueprint_url=self.scheduling_unit_blueprint_url) @@ -1322,11 +1692,11 @@ class TaskBlueprintTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_blueprint/', tb_test_data1, 201, tb_test_data1) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, tb_test_data1) + GET_and_assert_equal_expected_response(self, url, 200, tb_test_data1) # PUT new values, verify PUT_and_assert_expected_response(self, url, tb_test_data2, 200, tb_test_data2) - GET_and_assert_expected_response(self, url, 200, tb_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, tb_test_data2) def test_task_blueprint_PATCH(self): tb_test_data = test_data_creator.TaskBlueprint(draft_url=self.draft_url, template_url=self.template_url, scheduling_unit_blueprint_url=self.scheduling_unit_blueprint_url) @@ -1334,7 +1704,7 @@ class TaskBlueprintTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_blueprint/', tb_test_data, 201, tb_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, tb_test_data) + GET_and_assert_equal_expected_response(self, url, 200, tb_test_data) test_patch = {"description": "This is an updated description", "do_cancel": True} @@ -1343,7 +1713,7 @@ class TaskBlueprintTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(tb_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_task_blueprint_DELETE(self): tb_test_data = test_data_creator.TaskBlueprint(draft_url=self.draft_url, template_url=self.template_url, scheduling_unit_blueprint_url=self.scheduling_unit_blueprint_url) @@ -1351,7 +1721,7 @@ class TaskBlueprintTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_blueprint/', tb_test_data, 201, tb_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, tb_test_data) + GET_and_assert_equal_expected_response(self, url, 200, tb_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -1397,13 +1767,13 @@ class TaskBlueprintTestCase(unittest.TestCase): url = POST_and_assert_expected_response(self, BASE_URL + '/task_blueprint/', tb_test_data, 201, tb_test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, tb_test_data) + GET_and_assert_equal_expected_response(self, url, 200, tb_test_data) # DELETE dependency DELETE_and_assert_gone(self, template_url) # assert - GET_and_assert_expected_response(self, url, 404, {}) + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_task_blueprint_CASCADE_behavior_on_task_draft_deleted(self): draft_url = test_data_creator.post_data_and_get_url(test_data_creator.TaskDraft(), '/task_draft/') @@ -1413,13 +1783,13 @@ class TaskBlueprintTestCase(unittest.TestCase): url = POST_and_assert_expected_response(self, BASE_URL + '/task_blueprint/', tb_test_data, 201, tb_test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, tb_test_data) + GET_and_assert_equal_expected_response(self, url, 200, tb_test_data) # DELETE dependency DELETE_and_assert_gone(self, draft_url) # assert - GET_and_assert_expected_response(self, url, 404, {}) + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_task_blueprint_CASCADE_behavior_on_scheduling_unit_blueprint_deleted(self): scheduling_unit_blueprint_url = test_data_creator.post_data_and_get_url(test_data_creator.SchedulingUnitBlueprint(), '/scheduling_unit_blueprint/') @@ -1429,13 +1799,91 @@ class TaskBlueprintTestCase(unittest.TestCase): url = POST_and_assert_expected_response(self, BASE_URL + '/task_blueprint/', tb_test_data, 201, tb_test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, tb_test_data) + GET_and_assert_equal_expected_response(self, url, 200, tb_test_data) # DELETE dependency DELETE_and_assert_gone(self, scheduling_unit_blueprint_url) # assert - GET_and_assert_expected_response(self, url, 404, {}) + GET_and_assert_equal_expected_response(self, url, 404, {}) + + def test_GET_TaskBlueprint_list_view_shows_entry(self): + + test_data_1 = TaskBlueprint_test_data() + models.TaskBlueprint.objects.create(**test_data_1) + nbr_results = models.TaskBlueprint.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/task_blueprint/', test_data_1, nbr_results) + + def test_GET_TaskBlueprint_view_returns_correct_entry(self): + + # setup + test_data_1 = TaskBlueprint_test_data("task blue print two one") + test_data_2 = TaskBlueprint_test_data("task blue print two two") + id1 = models.TaskBlueprint.objects.create(**test_data_1).id + id2 = models.TaskBlueprint.objects.create(**test_data_2).id + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/task_blueprint/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/task_blueprint/%s/' % id2, test_data_2) + + def test_nested_TaskBlueprint_are_filtered_according_to_TaskDraft(self): + + # setup + test_data_1 = TaskBlueprint_test_data("task blue print three one") + test_data_2 = TaskBlueprint_test_data("task blue print three two") + tdt_test_data_1 = TaskDraft_test_data("task draft two one") + tdt_test_data_2 = TaskDraft_test_data("task draft two one") + task_draft_1 = models.TaskDraft.objects.create(**tdt_test_data_1) + task_draft_2 = models.TaskDraft.objects.create(**tdt_test_data_2) + test_data_1 = dict(test_data_1) + test_data_1['draft'] = task_draft_1 + task_blueprint_1 = models.TaskBlueprint.objects.create(**test_data_1) + test_data_2 = dict(test_data_2) + test_data_2['draft'] = task_draft_2 + task_blueprint_2 = models.TaskBlueprint.objects.create(**test_data_2) + + # assert the returned list contains related items, A list of length 1 is retrieved + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/task_draft/%s/task_blueprint/' % task_draft_2.id, test_data_2, 1) + # assert an existing related item is returned + GET_and_assert_in_expected_response(self, BASE_URL + '/task_draft/%s/task_blueprint/%s/' % (task_draft_2.id, task_blueprint_2.id), test_data_2) + # assert an existing unrelated item is not returned + GET_and_assert_equal_expected_code(self, BASE_URL + '/task_draft/%s/task_blueprint/%s/' % (task_draft_2.id, task_blueprint_1.id), 404) + + def test_TaskBlueprint_contains_list_of_related_Subtask(self): + + # setup + test_data_1 = TaskBlueprint_test_data() + test_data_2 = TaskBlueprint_test_data() + st_test_data_1 = Subtask_test_data() + st_test_data_2 = Subtask_test_data() + task_blueprint = models.TaskBlueprint.objects.create(**test_data_1) + subtask_1 = models.Subtask.objects.create(**st_test_data_1) + subtask_1.task_blueprint = task_blueprint + subtask_1.save() + subtask_2 = models.Subtask.objects.create(**st_test_data_2) + subtask_2.task_blueprint = task_blueprint + subtask_2.save() + # assert + response_data = GET_and_assert_equal_expected_code(self, BASE_URL + '/task_blueprint/%s/' % task_blueprint.id, 200) + assertUrlList(self, response_data['subtasks'], [subtask_1, subtask_2]) + + def test_TaskBlueprint_contains_lists_of_related_TaskRelationBlueprint(self): + + # setup + test_data_1 = TaskBlueprint_test_data() + test_data_2 = TaskBlueprint_test_data() + trbt_test_data_1 = TaskRelationBlueprint_test_data() + trbt_test_data_2 = TaskRelationBlueprint_test_data() + task_blueprint = models.TaskBlueprint.objects.create(**test_data_1) + task_relation_blueprint_1 = models.TaskRelationBlueprint.objects.create(**trbt_test_data_1) + task_relation_blueprint_1.producer = task_blueprint + task_relation_blueprint_1.save() + task_relation_blueprint_2 = models.TaskRelationBlueprint.objects.create(**trbt_test_data_2) + task_relation_blueprint_2.consumer = task_blueprint + task_relation_blueprint_2.save() + # assert + response_data = GET_and_assert_equal_expected_code(self, BASE_URL + '/task_blueprint/%s/' % task_blueprint.id, 200) + assertUrlList(self, response_data['produced_by'], [task_relation_blueprint_1]) + assertUrlList(self, response_data['consumed_by'], [task_relation_blueprint_2]) class TaskRelationBlueprintTestCase(unittest.TestCase): @@ -1455,7 +1903,7 @@ class TaskRelationBlueprintTestCase(unittest.TestCase): self.assertTrue("Task Relation Blueprint List" in r.content.decode('utf8')) def test_task_relation_blueprint_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/task_relation_blueprint/1234321/', 404, {}) + GET_and_assert_equal_expected_response(self, BASE_URL + '/task_relation_blueprint/1234321/', 404, {}) def test_task_relation_blueprint_POST_and_GET(self): trb_test_data = test_data_creator.TaskRelationBlueprint(draft_url=self.draft_url, template_url=self.template_url, input_url=self.input_url, output_url=self.output_url, consumer_url=self.consumer_url, producer_url=self.producer_url) @@ -1463,7 +1911,7 @@ class TaskRelationBlueprintTestCase(unittest.TestCase): # POST and GET a new item and assert correctness r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_relation_blueprint/', trb_test_data, 201, trb_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, trb_test_data) + GET_and_assert_equal_expected_response(self, url, 200, trb_test_data) def test_task_relation_blueprint_PUT_invalid_raises_error(self): trb_test_data = test_data_creator.TaskRelationBlueprint(draft_url=self.draft_url, template_url=self.template_url, input_url=self.input_url, output_url=self.output_url, consumer_url=self.consumer_url, producer_url=self.producer_url) @@ -1476,11 +1924,11 @@ class TaskRelationBlueprintTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_relation_blueprint/', trb_test_data1, 201, trb_test_data1) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, trb_test_data1) + GET_and_assert_equal_expected_response(self, url, 200, trb_test_data1) # PUT new values, verify PUT_and_assert_expected_response(self, url, trb_test_data2, 200, trb_test_data2) - GET_and_assert_expected_response(self, url, 200, trb_test_data2) + GET_and_assert_equal_expected_response(self, url, 200, trb_test_data2) def test_task_relation_blueprint_PATCH(self): trb_test_data = test_data_creator.TaskRelationBlueprint(draft_url=self.draft_url, template_url=self.template_url, input_url=self.input_url, output_url=self.output_url, consumer_url=self.consumer_url, producer_url=self.producer_url) @@ -1488,7 +1936,7 @@ class TaskRelationBlueprintTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_relation_blueprint/', trb_test_data, 201, trb_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, trb_test_data) + GET_and_assert_equal_expected_response(self, url, 200, trb_test_data) test_patch = {"selection_doc": "{'new': 'doc'}"} @@ -1496,7 +1944,7 @@ class TaskRelationBlueprintTestCase(unittest.TestCase): PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) expected_data = dict(trb_test_data) expected_data.update(test_patch) - GET_and_assert_expected_response(self, url, 200, expected_data) + GET_and_assert_equal_expected_response(self, url, 200, expected_data) def test_task_relation_blueprint_DELETE(self): trb_test_data = test_data_creator.TaskRelationBlueprint(draft_url=self.draft_url, template_url=self.template_url, input_url=self.input_url, output_url=self.output_url, consumer_url=self.consumer_url, producer_url=self.producer_url) @@ -1504,7 +1952,7 @@ class TaskRelationBlueprintTestCase(unittest.TestCase): # POST new item, verify r_dict = POST_and_assert_expected_response(self, BASE_URL + '/task_relation_blueprint/', trb_test_data, 201, trb_test_data) url = r_dict['url'] - GET_and_assert_expected_response(self, url, 200, trb_test_data) + GET_and_assert_equal_expected_response(self, url, 200, trb_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) @@ -1583,13 +2031,13 @@ class TaskRelationBlueprintTestCase(unittest.TestCase): url = POST_and_assert_expected_response(self, BASE_URL + '/task_relation_blueprint/', trb_test_data, 201, trb_test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, trb_test_data) + GET_and_assert_equal_expected_response(self, url, 200, trb_test_data) # DELETE dependency DELETE_and_assert_gone(self, template_url) # assert - GET_and_assert_expected_response(self, url, 404, {}) + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_task_relation_blueprint_CASCADE_behavior_on_producer_deleted(self): producer_url = test_data_creator.post_data_and_get_url(test_data_creator.TaskBlueprint(), '/task_blueprint/') @@ -1600,14 +2048,13 @@ class TaskRelationBlueprintTestCase(unittest.TestCase): trb_test_data, 201, trb_test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, trb_test_data) + GET_and_assert_equal_expected_response(self, url, 200, trb_test_data) # DELETE dependency DELETE_and_assert_gone(self, producer_url) # assert - GET_and_assert_expected_response(self, url, 404, {}) - + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_task_relation_blueprint_CASCADE_behavior_on_consumer_deleted(self): consumer_url = test_data_creator.post_data_and_get_url(test_data_creator.TaskBlueprint(), '/task_blueprint/') @@ -1618,14 +2065,13 @@ class TaskRelationBlueprintTestCase(unittest.TestCase): trb_test_data, 201, trb_test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, trb_test_data) + GET_and_assert_equal_expected_response(self, url, 200, trb_test_data) # DELETE dependency DELETE_and_assert_gone(self, consumer_url) # assert - GET_and_assert_expected_response(self, url, 404, {}) - + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_task_relation_blueprint_CASCADE_behavior_on_input_deleted(self): input_url = test_data_creator.post_data_and_get_url(test_data_creator.TaskConnectors(), '/task_connectors/') @@ -1636,14 +2082,13 @@ class TaskRelationBlueprintTestCase(unittest.TestCase): trb_test_data, 201, trb_test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, trb_test_data) + GET_and_assert_equal_expected_response(self, url, 200, trb_test_data) # DELETE dependency DELETE_and_assert_gone(self, input_url) # assert - GET_and_assert_expected_response(self, url, 404, {}) - + GET_and_assert_equal_expected_response(self, url, 404, {}) def test_task_relation_blueprint_CASCADE_behavior_on_output_deleted(self): output_url = test_data_creator.post_data_and_get_url(test_data_creator.TaskConnectors(), '/task_connectors/') @@ -1654,13 +2099,78 @@ class TaskRelationBlueprintTestCase(unittest.TestCase): trb_test_data, 201, trb_test_data)['url'] # verify - GET_and_assert_expected_response(self, url, 200, trb_test_data) + GET_and_assert_equal_expected_response(self, url, 200, trb_test_data) # DELETE dependency DELETE_and_assert_gone(self, output_url) # assert - GET_and_assert_expected_response(self, url, 404, {}) + GET_and_assert_equal_expected_response(self, url, 404, {}) + + def test_GET_TaskRelationBlueprint_list_view_shows_entry(self): + + test_data_1 = TaskRelationBlueprint_test_data() + models.TaskRelationBlueprint.objects.create(**test_data_1) + nbr_results = models.TaskRelationBlueprint.objects.count() + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/task_relation_blueprint/', test_data_1, nbr_results) + + def test_GET_TaskRelationBlueprint_view_returns_correct_entry(self): + + # setup + test_data_1 = TaskRelationBlueprint_test_data() + test_data_2 = TaskRelationBlueprint_test_data() + id1 = models.TaskRelationBlueprint.objects.create(**test_data_1).id + id2 = models.TaskRelationBlueprint.objects.create(**test_data_2).id + # assert + GET_and_assert_in_expected_response(self, BASE_URL + '/task_relation_blueprint/%s/' % id1, test_data_1) + GET_and_assert_in_expected_response(self, BASE_URL + '/task_relation_blueprint/%s/' % id2, test_data_2) + + def test_nested_TaskRelationBlueprint_are_filtered_according_to_TaskRelationDraft(self): + + # setup + test_data_1 = TaskRelationBlueprint_test_data() + test_data_2 = TaskRelationBlueprint_test_data() + trdt_test_data_1 = TaskRelationDraft_test_data() + trdt_test_data_2 = TaskRelationDraft_test_data() + task_relation_draft_1 = models.TaskRelationDraft.objects.create(**trdt_test_data_1) + task_relation_draft_2 = models.TaskRelationDraft.objects.create(**trdt_test_data_2) + test_data_1 = dict(test_data_1) + test_data_1['draft'] = task_relation_draft_1 + task_relation_blueprint_1 = models.TaskRelationBlueprint.objects.create(**test_data_1) + test_data_2 = dict(test_data_2) + test_data_2['draft'] = task_relation_draft_2 + task_relation_blueprint_2 = models.TaskRelationBlueprint.objects.create(**test_data_2) + + # assert the returned list contains related items, A list of length 1 is retrieved + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/task_relation_draft/%s/task_relation_blueprint/' % task_relation_draft_2.id, test_data_2, 1) + # assert an existing related item is returned + GET_and_assert_in_expected_response(self, BASE_URL + '/task_relation_draft/%s/task_relation_blueprint/%s/' % (task_relation_draft_2.id, task_relation_blueprint_2.id), test_data_2) + # assert an existing unrelated item is not returned + GET_and_assert_equal_expected_code(self, BASE_URL + '/task_relation_draft/%s/task_relation_blueprint/%s/' % (task_relation_draft_2.id, task_relation_blueprint_1.id), 404) + + def test_nested_TaskRelationBlueprint_are_filtered_according_to_TaskBlueprint(self): + + # setup + test_data_1 = TaskRelationBlueprint_test_data() + test_data_2 = TaskRelationBlueprint_test_data() + tbt_test_data_1 = TaskBlueprint_test_data() + tbt_test_data_2 = TaskBlueprint_test_data() + task_blueprint_1 = models.TaskBlueprint.objects.create(**tbt_test_data_1) + task_blueprint_2 = models.TaskBlueprint.objects.create(**tbt_test_data_2) + test_data_1 = dict(test_data_1) + test_data_1['producer'] = task_blueprint_1 + task_relation_blueprint_1 = models.TaskRelationBlueprint.objects.create(**test_data_1) + test_data_2 = dict(test_data_2) + test_data_2['consumer'] = task_blueprint_2 + task_relation_blueprint_2 = models.TaskRelationBlueprint.objects.create(**test_data_2) + # assert the returned list contains related producer + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/task_blueprint/%s/task_relation_blueprint/' % task_blueprint_1.id, test_data_1, 1) + # assert the returned list contains related consumer + GET_and_assert_in_expected_response_result_list(self, BASE_URL + '/task_blueprint/%s/task_relation_blueprint/' % task_blueprint_2.id, test_data_2, 1) + # assert an existing related item is returned + GET_and_assert_in_expected_response(self, BASE_URL + '/task_blueprint/%s/task_relation_blueprint/%s/' % (task_blueprint_2.id, task_relation_blueprint_2.id), test_data_2) + # assert an existing unrelated item is not returned + GET_and_assert_equal_expected_code(self, BASE_URL + '/task_blueprint/%s/task_relation_blueprint/%s/' % (task_blueprint_2.id, task_relation_blueprint_1.id), 404) if __name__ == "__main__": diff --git a/SAS/TMSS/test/test_utils.py b/SAS/TMSS/test/test_utils.py index c1204e0eebd54258df3784e8c7375d8bc423b22f..28c522c246de34e20526e6d7886a687e13552a18 100644 --- a/SAS/TMSS/test/test_utils.py +++ b/SAS/TMSS/test/test_utils.py @@ -44,7 +44,9 @@ def assertDataWithUrls(self, data, expected): if isinstance(v, models.Model): v = str(v.pk) v = v.replace(' ', '%20') - self.assertTrue(str(v) in data[k]) + err_msg = "The value '%s' (key is %s) is not in expected %s" % (str(v), str(data[k]), k) + self.assertTrue(str(v) in data[k], err_msg) + else: self.assertEqual(v, data[k]) diff --git a/SAS/TMSS/test/tmss_test_data_django_models.py b/SAS/TMSS/test/tmss_test_data_django_models.py index adf787e0a9608cf60c2bf4981ef4203f23f61d74..4c4d6a45c51f0bb19ca93be37896b98b92fb31d7 100644 --- a/SAS/TMSS/test/tmss_test_data_django_models.py +++ b/SAS/TMSS/test/tmss_test_data_django_models.py @@ -46,23 +46,23 @@ def DefaultGeneratorTemplate_test_data(name=None, template=None) -> dict: 'template': template, 'tags':[]} -def SchedulingUnitTemplate_test_data() -> dict: - return {"name": "My SchedulingUnitTemplate", +def SchedulingUnitTemplate_test_data(name="my_SchedulingUnitTemplate") -> dict: + return {"name": name, "description": 'My SchedulingUnitTemplate description', "version": 'v0.314159265359', "schema": {"mykey": "my value"}, "tags": ["TMSS", "TESTING"]} -def TaskTemplate_test_data() -> dict: +def TaskTemplate_test_data(name="my TaskTemplate") -> dict: return {"validation_code_js":"", - "name": "my TaskTemplate", + "name": name, "description": 'My TaskTemplate description', "version": 'v0.314159265359', "schema": {"mykey": "my value"}, "tags": ["TMSS", "TESTING"]} -def WorkRelationSelectionTemplate_test_data() -> dict: - return {"name": "my WorkRelationSelectionTemplate", +def WorkRelationSelectionTemplate_test_data(name="my_WorkRelationSelectionTemplate") -> dict: + return {"name": name, "description": 'My WorkRelationSelectionTemplate description', "version": 'v0.314159265359', "schema": {"mykey": "my value"}, @@ -79,8 +79,8 @@ def Cycle_test_data() -> dict: return {"name": 'my_cycle' + str(uuid.uuid4()), "description": "", "tags": [], - "start": datetime.utcnow(), - "stop": datetime.utcnow(), + "start": datetime.utcnow().isoformat(), + "stop": datetime.utcnow().isoformat(), "number": 1, "standard_hours": 2, "expert_hours": 3, @@ -97,8 +97,8 @@ def Project_test_data() -> dict: "expert": True, "filler": False} -def SchedulingSet_test_data() -> dict: - return {"name": 'my_scheduling_set', +def SchedulingSet_test_data(name="my_scheduling_set") -> dict: + return {"name": name, "description": "", "tags": [], "generator_doc": "{}", @@ -106,16 +106,16 @@ def SchedulingSet_test_data() -> dict: "generator_template": models.GeneratorTemplate.objects.create(**GeneratorTemplate_test_data()), "generator_source": None} -def SchedulingUnitDraft_test_data() -> dict: - return {"name": 'my_scheduling_unit_draft', - "description": "", - "tags": [], - "requirements_doc": "{}", - "copy_reason": models.CopyReason.objects.get(value='template'), - "generator_instance_doc": "para", - "copies": None, - "scheduling_set": models.SchedulingSet.objects.create(**SchedulingSet_test_data()), - "requirements_template": models.SchedulingUnitTemplate.objects.create(**SchedulingUnitTemplate_test_data())} +def SchedulingUnitDraft_test_data(name="my_scheduling_unit_draft") -> dict: + return {"name": name, + "description": "", + "tags": [], + "requirements_doc": "{}", + "copy_reason": models.CopyReason.objects.get(value='template'), + "generator_instance_doc": "para", + "copies": None, + "scheduling_set": models.SchedulingSet.objects.create(**SchedulingSet_test_data()), + "requirements_template": models.SchedulingUnitTemplate.objects.create(**SchedulingUnitTemplate_test_data())} def TaskDraft_test_data(name: str="my_task_draft", specifications_template: models.TaskTemplate=None) -> dict: if specifications_template is None: @@ -140,8 +140,8 @@ def TaskRelationDraft_test_data() -> dict: "output": models.TaskConnectors.objects.create(**TaskConnectors_test_data()), "selection_template": models.WorkRelationSelectionTemplate.objects.create(**WorkRelationSelectionTemplate_test_data())} -def SchedulingUnitBlueprint_test_data() -> dict: - return {"name": 'my_scheduling_unit_blueprint', +def SchedulingUnitBlueprint_test_data(name='my_scheduling_unit_blueprint') -> dict: + return {"name": name, "description": "", "tags": [], "requirements_doc": "{}", @@ -149,11 +149,11 @@ def SchedulingUnitBlueprint_test_data() -> dict: "draft": models.SchedulingUnitDraft.objects.create(**SchedulingUnitDraft_test_data()), "requirements_template": models.SchedulingUnitTemplate.objects.create(**SchedulingUnitTemplate_test_data())} -def TaskBlueprint_test_data(task_draft: models.TaskDraft = None) -> dict: +def TaskBlueprint_test_data(name='my_task_blueprint', task_draft: models.TaskDraft = None) -> dict: if task_draft is None: task_draft = models.TaskDraft.objects.create(**TaskDraft_test_data()) - return {"name": 'my_task_blueprint', + return {"name": name, "description": "", "tags": [], "specifications_doc": str(task_draft.specifications_doc), @@ -235,10 +235,10 @@ def Subtask_test_data(task_blueprint: models.TaskBlueprint=None, subtask_templat specifications_doc = get_default_json_object_for_schema(subtask_template.schema) if start_time is None: - start_time = datetime.utcnow() + start_time = datetime.utcnow().isoformat() if stop_time is None: - stop_time = datetime.utcnow() + stop_time = datetime.utcnow().isoformat() if cluster_object is None: cluster_object = models.Cluster.objects.create(name="dummy cluster", location="downstairs", tags=[]) @@ -250,7 +250,7 @@ def Subtask_test_data(task_blueprint: models.TaskBlueprint=None, subtask_templat "task_blueprint": task_blueprint, "specifications_template": subtask_template, "tags": ["TMSS", "TESTING"], - "do_cancel": datetime.utcnow(), + "do_cancel": datetime.utcnow().isoformat(), "priority": 1, "schedule_method": models.ScheduleMethod.objects.get(value='manual'), "cluster": cluster_object, @@ -263,13 +263,13 @@ def Dataproduct_test_data(producer: models.SubtaskOutput=None, filename: str="my return {"filename": filename, "directory": directory, "dataformat": models.Dataformat.objects.get(value='Beamformed'), - "deleted_since": datetime.utcnow(), - "pinned_since": datetime.utcnow(), + "deleted_since": datetime.utcnow().isoformat(), + "pinned_since": datetime.utcnow().isoformat(), "specifications_doc": "{}", "specifications_template": models.DataproductSpecificationsTemplate.objects.create(**DataproductSpecificationsTemplate_test_data()), "tags": ["TMSS", "TESTING"], "producer": producer, - "do_cancel": datetime.utcnow(), + "do_cancel": datetime.utcnow().isoformat(), "expected_size": 1234, "size": 123, "feedback_doc": "{}", @@ -316,8 +316,8 @@ def Cluster_test_data(name="default cluster") -> dict: def DataproductArchiveInfo_test_data() -> dict: return {"dataproduct": models.Dataproduct.objects.create(**Dataproduct_test_data()), "storage_ticket": "myticket_1", - "public_since": datetime.utcnow(), - "corrupted_since": datetime.utcnow(), + "public_since": datetime.utcnow().isoformat(), + "corrupted_since": datetime.utcnow().isoformat(), "tags": ['tmss', 'testing']} def DataproductHash_test_data() -> dict: diff --git a/SAS/TMSS/test/tmss_test_environment_unittest_setup.py b/SAS/TMSS/test/tmss_test_environment_unittest_setup.py index e52f8ccf97cbebf10d40373f937949ecc499523e..bec8ad5b7ea6bd9b32a86a1365d522189caa4e5f 100644 --- a/SAS/TMSS/test/tmss_test_environment_unittest_setup.py +++ b/SAS/TMSS/test/tmss_test_environment_unittest_setup.py @@ -44,6 +44,8 @@ import requests AUTH = requests.auth.HTTPBasicAuth(tmss_test_env.ldap_server.dbcreds.user, tmss_test_env.ldap_server.dbcreds.password) BASE_URL = tmss_test_env.django_server.url OIDC_URL = tmss_test_env.django_server.oidc_url +from lofar.sas.tmss.test.test_utils import assertDataWithUrls + def _call_API_and_assert_expected_response(test_instance, url, call, data, expected_code, expected_content): """ @@ -69,13 +71,23 @@ def _call_API_and_assert_expected_response(test_instance, url, call, data, expec content = response.content.decode('utf-8') +<<<<<<< Updated upstream if response.status_code in range(200, 300): +======= + from django.db import models + + if response.status_code in range(200, 300) and expected_content is not None: +>>>>>>> Stashed changes r_dict = json.loads(content) for key, value in expected_content.items(): if key not in r_dict.keys(): print('!!! Missing key: %s in %s' % (key, r_dict.keys())) test_instance.assertTrue(key in r_dict.keys()) - if type(value) is list: + if isinstance(value, models.Model): + value = str(value.pk) + value = value.replace(' ', '%20') + test_instance.assertTrue(str(value) in r_dict[key]) + elif type(value) is list: test_instance.assertEqual(sorted(value), sorted(r_dict[key])) # compare lists independent of ordering else: test_instance.assertEqual(value, r_dict[key]) @@ -91,36 +103,84 @@ def PUT_and_assert_expected_response(test_instance, url, data, expected_code, ex """ PUT data on url and assert the expected code is returned and the expected content is in the response content """ - r_dict = _call_API_and_assert_expected_response(test_instance, url, 'PUT', data, expected_code, expected_content) return r_dict + def POST_and_assert_expected_response(test_instance, url, data, expected_code, expected_content): """ POST data on url and assert the expected code is returned and the expected content is in the response content :return: response dict """ - r_dict = _call_API_and_assert_expected_response(test_instance, url, 'POST', data, expected_code, expected_content) return r_dict -def GET_and_assert_expected_response(test_instance, url, expected_code, expected_content): + +def GET_and_assert_equal_expected_code(test_instance, url, expected_code): + """ + GET from url and assert the expected code is returned and the expected content is in the response content + """ + r_dict = _call_API_and_assert_expected_response(test_instance, url, 'GET', {}, expected_code, None) + return r_dict + + +def GET_and_assert_in_expected_response(test_instance, url, expected_content): """ GET from url and assert the expected code is returned and the expected content is in the response content + Because of the objects can not be compared with some objects check the keys only """ + r_dict = _call_API_and_assert_expected_response(test_instance, url, 'GET', {}, 200, None) + for key in expected_content.keys(): + test_instance.assertIn(key, r_dict.keys()) + assertDataWithUrls(test_instance, r_dict, expected_content) + return r_dict + +def GET_and_assert_in_expected_response_result_list(test_instance, url, expected_content, expected_nbr_results): + """ + GET from url and assert the expected code is returned and the expected content is in the response content + Use this when multiple results are returned + """ + r_dict = _call_API_and_assert_expected_response(test_instance, url, 'GET', {}, 200, None) + if expected_nbr_results > 50: + print("WARNING: Limited result length due to pagination setting (50)") + test_instance.assertEqual(50, len(r_dict["results"])) + test_instance.assertEqual(50, len(r_dict["results"])) + test_instance.assertEqual(expected_nbr_results, r_dict["count"]) + test_instance.assertNotEqual(None, r_dict['next']) + url_check = False + else: + test_instance.assertEqual(expected_nbr_results, len(r_dict["results"])) + test_instance.assertEqual(r_dict["count"], len(r_dict["results"])) + test_instance.assertEqual(None, r_dict['next']) + url_check = True + + for item in r_dict["results"]: + for key in expected_content.keys(): + test_instance.assertIn(key, item.keys()) + + if url_check: + assertDataWithUrls(test_instance, r_dict['results'][expected_nbr_results-1], expected_content) + return r_dict + + +def GET_and_assert_equal_expected_response(test_instance, url, expected_code, expected_content): + """ + GET from url and assert the expected code is returned and the expected content is equal the response content + """ r_dict = _call_API_and_assert_expected_response(test_instance, url, 'GET', {}, expected_code, expected_content) return r_dict + def PATCH_and_assert_expected_response(test_instance, url, data, expected_code, expected_content): """ POST data on url and assert the provided values have changed based on the server response. :return: url for new item """ - r_dict = _call_API_and_assert_expected_response(test_instance, url, 'PATCH', data, expected_code, expected_content) return r_dict + def DELETE_and_assert_gone(test_instance, url): """ DELETE item at provided url and assert that the request was accepted by the server @@ -135,3 +195,6 @@ def DELETE_and_assert_gone(test_instance, url): if response.status_code != 404: print("!!! Unexpected: [%s] - %s %s: %s" % (test_instance.id(), 'GET', url, response.content)) test_instance.assertEqual(response.status_code, 404) + + +