From a3a3d0fecdcd57ac1453bdcf441c5cb83fd3956b Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Tue, 4 Aug 2020 16:18:36 +0200
Subject: [PATCH] TMSS-287: fixed tests

---
 .../test/t_tmssapp_specification_REST_API.py  | 24 +++++++++----------
 SAS/TMSS/test/tmss_test_data_django_models.py |  1 +
 SAS/TMSS/test/tmss_test_data_rest.py          |  7 +++---
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/SAS/TMSS/test/t_tmssapp_specification_REST_API.py b/SAS/TMSS/test/t_tmssapp_specification_REST_API.py
index b089abdc084..bc95e9ccebc 100755
--- a/SAS/TMSS/test/t_tmssapp_specification_REST_API.py
+++ b/SAS/TMSS/test/t_tmssapp_specification_REST_API.py
@@ -722,7 +722,7 @@ class ProjectTestCase(unittest.TestCase):
 
         # POST and GET a new item and assert correctness
         expected = project_test_data.copy()
-        expected.pop('project_quota')  # exclude project_quota from comparison, because these get auto-generated
+        expected.pop('quota')  # exclude quota from comparison, because these get auto-generated
         r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project/', project_test_data, 201, expected)
         url = r_dict['url']
         GET_OK_and_assert_equal_expected_response(self, url, expected)
@@ -735,7 +735,7 @@ class ProjectTestCase(unittest.TestCase):
 
         # POST new item, verify
         expected = project_test_data.copy()
-        expected.pop('project_quota')  # exclude project_quota from comparison, because these get auto-generated
+        expected.pop('quota')  # exclude quota from comparison, because these get auto-generated
         r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project/', project_test_data, 201, expected)
         url = r_dict['url']
         GET_OK_and_assert_equal_expected_response(self, url, expected)
@@ -744,7 +744,7 @@ class ProjectTestCase(unittest.TestCase):
         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
         expected = test_data.copy()
-        expected.pop('project_quota')  # exclude project_quota from comparison, because these get auto-generated
+        expected.pop('quota')  # exclude quota from comparison, because these get auto-generated
         PUT_and_assert_expected_response(self, url, test_data, 200, expected)
         GET_OK_and_assert_equal_expected_response(self, url, expected)
 
@@ -753,7 +753,7 @@ class ProjectTestCase(unittest.TestCase):
 
         # POST new item, verify
         expected = project_test_data.copy()
-        expected.pop('project_quota')  # exclude project_quota from comparison, because these get auto-generated
+        expected.pop('quota')  # exclude quota from comparison, because these get auto-generated
         r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project/', project_test_data, 201, expected)
         url = r_dict['url']
         GET_OK_and_assert_equal_expected_response(self, url, expected)
@@ -771,15 +771,15 @@ class ProjectTestCase(unittest.TestCase):
 
         # POST new item, verify
         expected = project_test_data.copy()
-        expected.pop('project_quota')  # exclude project_quota from comparison, because these get auto-generated
+        expected.pop('quota')  # exclude quota from comparison, because these get auto-generated
         r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project/', project_test_data, 201, expected)
         url = r_dict['url']
         GET_OK_and_assert_equal_expected_response(self, url, expected)
 
-        # DELETE related auto-generated project_quota first
-        project_quotas = r_dict['project_quota']
-        for project_quota in project_quotas:
-            DELETE_and_assert_gone(self, project_quota)
+        # DELETE related auto-generated quota first
+        quotas = r_dict['quota']
+        for quota in quotas:
+            DELETE_and_assert_gone(self, quota)
 
         # DELETE and check it's gone
         DELETE_and_assert_gone(self, url)
@@ -792,7 +792,7 @@ class ProjectTestCase(unittest.TestCase):
         test_data = dict(test_data_creator.Project())
         test_data['cycles'] = [cycle_url]
         expected = test_data.copy()
-        expected.pop('project_quota')  # exclude project_quota from comparison, because these get auto-generated
+        expected.pop('quota')  # exclude quota from comparison, because these get auto-generated
         url = POST_and_assert_expected_response(self, BASE_URL + '/project/', test_data, 201, expected)['url']
 
         # verify
@@ -835,7 +835,7 @@ class ProjectTestCase(unittest.TestCase):
 
         # 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_1.name, test_data_1, 1)
-      
+
 class ResourceTypeTestCase(unittest.TestCase):
     def test_resource_type_list_apiformat(self):
         r = requests.get(BASE_URL + '/resource_type/?format=api', auth=AUTH)
@@ -925,7 +925,7 @@ class ProjectQuotaTestCase(unittest.TestCase):
         # POST new item with dependencies
         project_test_data = test_data_creator.Project()
         expected = project_test_data.copy()
-        expected.pop('project_quota')  # exclude project_quota from comparison, because these get auto-generated
+        expected.pop('quota')  # exclude quota from comparison, because these get auto-generated
         project_url = POST_and_assert_expected_response(self, BASE_URL + '/project/', project_test_data, 201, expected)['url']
 
         project_quota_test_data = dict(test_data_creator.ProjectQuota(project_url=project_url))
diff --git a/SAS/TMSS/test/tmss_test_data_django_models.py b/SAS/TMSS/test/tmss_test_data_django_models.py
index 83c88f982ba..21ee23b0d2e 100644
--- a/SAS/TMSS/test/tmss_test_data_django_models.py
+++ b/SAS/TMSS/test/tmss_test_data_django_models.py
@@ -112,6 +112,7 @@ def ResourceType_test_data() -> dict:
         "tags": [],
         "description": 'my description ' + str(uuid.uuid4()),
         "name": 'my_resource_type_' + str(uuid.uuid4()),
+        "quantity": models.Quantity.objects.get(value=models.Quantity.Choices.NUMBER.value)
      }
 
 def ProjectQuota_test_data() -> dict:
diff --git a/SAS/TMSS/test/tmss_test_data_rest.py b/SAS/TMSS/test/tmss_test_data_rest.py
index 5e488592d2b..a58cb44b971 100644
--- a/SAS/TMSS/test/tmss_test_data_rest.py
+++ b/SAS/TMSS/test/tmss_test_data_rest.py
@@ -128,13 +128,13 @@ class TMSSRESTTestDataCreator():
                 "start": datetime.utcnow().isoformat(),
                 "stop": datetime.utcnow().isoformat(),
                 "projects": [],
-                "cycle_quota": []}
+                "quota": []}
     
     def Project(self, description="my project description"):
         return {"name": 'my_project_' + str(uuid.uuid4()),
                 "description": description,
                 "tags": [],
-                "project_quota": [],
+                "quota": [],
                 "priority_rank": 1.0,
                 "trigger_priority": 1000,
                 "can_trigger": False,
@@ -145,7 +145,8 @@ class TMSSRESTTestDataCreator():
         return {
             "tags": [],
             "description": description,
-            "name": 'my_resource_type_' + str(uuid.uuid4())
+            "name": 'my_resource_type_' + str(uuid.uuid4()),
+            "quantity": self.django_api_url + '/quantity/number/'
         }
 
     
-- 
GitLab