From 0c0af11b1c44c2414f13a60e7b2cfce77d6505eb Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Fri, 17 Apr 2020 11:05:22 +0200
Subject: [PATCH] TMSS-165: fixed tests after renaming

---
 .../test/t_tmssapp_specification_REST_API.py  | 40 +++++++++----------
 SAS/TMSS/test/tmss_test_data_rest.py          |  7 +---
 2 files changed, 20 insertions(+), 27 deletions(-)

diff --git a/SAS/TMSS/test/t_tmssapp_specification_REST_API.py b/SAS/TMSS/test/t_tmssapp_specification_REST_API.py
index 55b04c17fa0..8c51bdb7dd7 100755
--- a/SAS/TMSS/test/t_tmssapp_specification_REST_API.py
+++ b/SAS/TMSS/test/t_tmssapp_specification_REST_API.py
@@ -792,8 +792,6 @@ class ProjectTestCase(unittest.TestCase):
         # 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 ResourceTypeTestCase(unittest.TestCase):
     def test_resource_type_list_apiformat(self):
         r = requests.get(BASE_URL + '/resource_type/?format=api', auth=AUTH)
@@ -801,15 +799,15 @@ class ResourceTypeTestCase(unittest.TestCase):
         self.assertTrue("Resource Type List" in r.content.decode('utf8'))
    
     def test_resource_type_GET_nonexistant_raises_error(self):
-        GET_and_assert_expected_response(self, BASE_URL + '/resource_type/1234321/', 404, {})
-    
+        GET_and_assert_equal_expected_code(self, BASE_URL + '/resource_type/1234321/', 404)
+
     def test_resource_type_POST_and_GET(self):
         resource_type_test_data = test_data_creator.ResourceType()
         # POST and GET a new item and assert correctness
         r_dict = POST_and_assert_expected_response(self, BASE_URL + '/resource_type/', resource_type_test_data, 201, resource_type_test_data)
         url = r_dict['url']
-        GET_and_assert_expected_response(self, url, 200, resource_type_test_data)
-  
+        GET_OK_and_assert_equal_expected_response(self, url, resource_type_test_data)
+
 class ProjectQuotaTestCase(unittest.TestCase):
     def test_project_quota_list_apiformat(self):
         r = requests.get(BASE_URL + '/project_quota/?format=api', auth=AUTH)
@@ -817,7 +815,7 @@ class ProjectQuotaTestCase(unittest.TestCase):
         self.assertTrue("Project Quota List" in r.content.decode('utf8'))
    
     def test_project_quota_GET_nonexistant_raises_error(self):
-        GET_and_assert_expected_response(self, BASE_URL + '/project_quota/1234321/', 404, {})
+        GET_and_assert_equal_expected_code(self, BASE_URL + '/project_quota/1234321/', 404)
 
     def test_project_quota_POST_and_GET(self):
         project_quota_test_data = test_data_creator.ProjectQuota()
@@ -825,7 +823,7 @@ class ProjectQuotaTestCase(unittest.TestCase):
         # POST and GET a new item and assert correctness
         r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project_quota/', project_quota_test_data, 201, project_quota_test_data)
         url = r_dict['url']
-        GET_and_assert_expected_response(self, url, 200, project_quota_test_data)
+        GET_OK_and_assert_equal_expected_response(self, url, project_quota_test_data)
 
     def test_project_quota_POST_and_GET(self):
         project_quota_test_data = test_data_creator.ProjectQuota()
@@ -833,8 +831,7 @@ class ProjectQuotaTestCase(unittest.TestCase):
         # POST and GET a new item and assert correctness
         r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project_quota/', project_quota_test_data, 201, project_quota_test_data)
         url = r_dict['url']
-        GET_and_assert_expected_response(self, url, 200, project_quota_test_data)
-  
+        GET_OK_and_assert_equal_expected_response(self, url, project_quota_test_data)
 
     def test_project_quota_PUT_invalid_raises_error(self):
         PUT_and_assert_expected_response(self, BASE_URL + '/project_quota/9876789876/', test_data_creator.Project(), 404, {})
@@ -845,13 +842,12 @@ class ProjectQuotaTestCase(unittest.TestCase):
         # POST new item, verify
         r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project_quota/', project_quota_test_data, 201, project_quota_test_data)
         url = r_dict['url']
-        GET_and_assert_expected_response(self, url, 200, project_quota_test_data)
+        GET_OK_and_assert_equal_expected_response(self, url, project_quota_test_data)
 
         # PUT new values, verify
         test_data = dict(test_data_creator.ProjectQuota("other description"))
-        test_data['name'] = project_quota_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_OK_and_assert_equal_expected_response(self, url, test_data)
 
     def test_project_quota_PATCH(self):
         project_quota_test_data = test_data_creator.ProjectQuota()
@@ -859,15 +855,15 @@ class ProjectQuotaTestCase(unittest.TestCase):
         # POST new item, verify
         r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project_quota/', project_quota_test_data, 201, project_quota_test_data)
         url = r_dict['url']
-        GET_and_assert_expected_response(self, url, 200, project_quota_test_data)
+        GET_OK_and_assert_equal_expected_response(self, url, project_quota_test_data)
 
-        test_patch = {"resource_quota": 500}
+        test_patch = {"value": 500}
 
         # PATCH item and verify
         PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch)
         expected_data = dict(project_quota_test_data)
         expected_data.update(test_patch)
-        GET_and_assert_expected_response(self, url, 200, expected_data)
+        GET_OK_and_assert_equal_expected_response(self, url, expected_data)
 
     def test_project_quota_DELETE(self):
         project_quota_test_data = test_data_creator.ProjectQuota()
@@ -875,7 +871,7 @@ class ProjectQuotaTestCase(unittest.TestCase):
         # POST new item, verify
         r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project_quota/', project_quota_test_data, 201, project_quota_test_data)
         url = r_dict['url']
-        GET_and_assert_expected_response(self, url, 200, project_quota_test_data)
+        GET_OK_and_assert_equal_expected_response(self, url, project_quota_test_data)
 
         # DELETE and check it's gone
         DELETE_and_assert_gone(self, url)
@@ -886,20 +882,20 @@ class ProjectQuotaTestCase(unittest.TestCase):
         project_test_data = test_data_creator.Project()
         project_url = POST_and_assert_expected_response(self, BASE_URL + '/project/', project_test_data, 201, project_test_data)['url']
         
-        test_data = dict(test_data_creator.ProjectQuota(project_url=project_url))
-        url = POST_and_assert_expected_response(self, BASE_URL + '/project_quota/', test_data, 201, test_data)['url']
+        project_quota_test_data = dict(test_data_creator.ProjectQuota(project_url=project_url))
+        project_quota_url = POST_and_assert_expected_response(self, BASE_URL + '/project_quota/', project_quota_test_data, 201, project_quota_test_data)['url']
 
         # verify
-        GET_and_assert_expected_response(self, url, 200, test_data)
+        GET_OK_and_assert_equal_expected_response(self, project_quota_url, project_quota_test_data)
 
-        project_test_data['project'] = [url]  # add the
+        project_test_data['project'] = [project_quota_url]  # add the
 
         # 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_OK_and_assert_equal_expected_response(self, project_quota_url, project_quota_test_data)
 
 
 
diff --git a/SAS/TMSS/test/tmss_test_data_rest.py b/SAS/TMSS/test/tmss_test_data_rest.py
index 0ad95dcc6c4..656a2f5cd70 100644
--- a/SAS/TMSS/test/tmss_test_data_rest.py
+++ b/SAS/TMSS/test/tmss_test_data_rest.py
@@ -122,7 +122,7 @@ class TMSSRESTTestDataCreator():
                 "name": 'my_resource_unit_' + str(uuid.uuid4())
             }
 
-    def ResourceType(self, description="my project quota description", resource_url=None):
+    def ResourceType(self, description="my resource_type description", resource_url=None):
         if resource_url is None:
             resource_url = self.post_data_and_get_url(self.ResourceUnit(), '/resource_unit/')
         return {
@@ -140,10 +140,7 @@ class TMSSRESTTestDataCreator():
             resource_url = self.post_data_and_get_url(self.ResourceType(), '/resource_type/')
 
         return {
-            "name": 'my_project_quota_' + str(uuid.uuid4()),
-            "description": description,
-            "tags": [],
-            "resource_quota": 1000,
+            "value": 1000,
             "project": project_url,
             "resource_type": resource_url
             }
-- 
GitLab