From ac1b64c860a2dff9c62ffd83b740b844c7fc02c4 Mon Sep 17 00:00:00 2001 From: Jorrit Schaap <schaap@astron.nl> Date: Fri, 17 Apr 2020 08:55:38 +0200 Subject: [PATCH] TMSS-165: replaced quotum(s) by quota --- ...projectquotum_resourcetype_resourceunit.py | 4 +- .../src/tmss/tmssapp/models/specification.py | 7 +- .../tmss/tmssapp/serializers/specification.py | 6 +- .../tmss/tmssapp/viewsets/specification.py | 6 +- SAS/TMSS/src/tmss/urls.py | 2 +- .../test/t_tmssapp_specification_REST_API.py | 68 +++++++++---------- .../t_tmssapp_specification_django_API.py | 16 ++--- SAS/TMSS/test/tmss_test_data_django_models.py | 4 +- SAS/TMSS/test/tmss_test_data_rest.py | 8 +-- 9 files changed, 59 insertions(+), 62 deletions(-) diff --git a/SAS/TMSS/src/tmss/tmssapp/migrations/0003_projectquotum_resourcetype_resourceunit.py b/SAS/TMSS/src/tmss/tmssapp/migrations/0003_projectquotum_resourcetype_resourceunit.py index eca4f0ecf01..ab5689f6fd8 100644 --- a/SAS/TMSS/src/tmss/tmssapp/migrations/0003_projectquotum_resourcetype_resourceunit.py +++ b/SAS/TMSS/src/tmss/tmssapp/migrations/0003_projectquotum_resourcetype_resourceunit.py @@ -40,7 +40,7 @@ class Migration(migrations.Migration): }, ), migrations.CreateModel( - name='ProjectQuotum', + name='ProjectQuota', fields=[ ('tags', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=128), blank=True, default=list, help_text='User-defined search keywords for object.', size=8)), ('created_at', models.DateTimeField(auto_now_add=True, help_text='Moment of object creation.')), @@ -48,7 +48,7 @@ class Migration(migrations.Migration): ('description', models.CharField(help_text='A longer description of this object.', max_length=255)), ('name', models.CharField(help_text='Human-readable name of this object.', max_length=128, primary_key=True, serialize=False)), ('resource_quota', models.FloatField(help_text='Resource Quota value')), - ('project', models.ForeignKey(help_text='Project to wich this quota belongs.', on_delete=django.db.models.deletion.PROTECT, related_name='project_quotums', to='tmssapp.Project')), + ('project', models.ForeignKey(help_text='Project to wich this quota belongs.', on_delete=django.db.models.deletion.PROTECT, related_name='project_quota', to='tmssapp.Project')), ('resource_type', models.ForeignKey(help_text='Resource type.', on_delete=django.db.models.deletion.PROTECT, related_name='resource_type', to='tmssapp.ResourceType')), ], options={ diff --git a/SAS/TMSS/src/tmss/tmssapp/models/specification.py b/SAS/TMSS/src/tmss/tmssapp/models/specification.py index 1c60c549399..50dac3cedb0 100644 --- a/SAS/TMSS/src/tmss/tmssapp/models/specification.py +++ b/SAS/TMSS/src/tmss/tmssapp/models/specification.py @@ -211,13 +211,10 @@ class Project(NamedCommonPK): expert = BooleanField(default=False, help_text='Expert projects put more responsibility on the PI.') filler = BooleanField(default=False, help_text='Use this project to fill up idle telescope time.') -class ProjectQuotum(NamedCommonPK): - project = ForeignKey('Project', related_name="project_quotums", on_delete=PROTECT, help_text='Project to wich this quota belongs.') # protected to avoid accidents +class ProjectQuota(NamedCommonPK): + project = ForeignKey('Project', related_name="project_quota", on_delete=PROTECT, help_text='Project to wich this quota belongs.') # protected to avoid accidents resource_quota = FloatField(help_text='Resource Quota value') resource_type = ForeignKey('ResourceType', related_name="resource_type", on_delete=PROTECT, help_text='Resource type.') # protected to avoid accidents - #lta_storage = FloatField(help_text='LTA storage offered for the project') - #observation_hours = IntegerField(help_text='Number of offered hours for observations.') - #processing_hours = IntegerField(help_text='Number of offered hours for processing.') class ResourceType(NamedCommonPK): resource_unit = ForeignKey('ResourceUnit', related_name="resource_types", on_delete=PROTECT, help_text='Unit of current resource.') diff --git a/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py b/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py index 892dff998eb..76da0a35a75 100644 --- a/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py +++ b/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py @@ -122,11 +122,11 @@ class ProjectSerializer(RelationalHyperlinkedModelSerializer): class Meta: model = models.Project fields = '__all__' - extra_fields = ['name','project_quotums'] + extra_fields = ['name','project_quota'] -class ProjectQuotumSerializer(RelationalHyperlinkedModelSerializer): +class ProjectQuotaSerializer(RelationalHyperlinkedModelSerializer): class Meta: - model = models.ProjectQuotum + model = models.ProjectQuota fields = '__all__' extra_fields = ['name','resource_type'] diff --git a/SAS/TMSS/src/tmss/tmssapp/viewsets/specification.py b/SAS/TMSS/src/tmss/tmssapp/viewsets/specification.py index 5732999bbd0..16f25c43c2a 100644 --- a/SAS/TMSS/src/tmss/tmssapp/viewsets/specification.py +++ b/SAS/TMSS/src/tmss/tmssapp/viewsets/specification.py @@ -126,9 +126,9 @@ class ProjectViewSet(LOFARViewSet): else: return models.Project.objects.all() -class ProjectQuotumViewSet(LOFARViewSet): - queryset = models.ProjectQuotum.objects.all() - serializer_class = serializers.ProjectQuotumSerializer +class ProjectQuotaViewSet(LOFARViewSet): + queryset = models.ProjectQuota.objects.all() + serializer_class = serializers.ProjectQuotaSerializer class ResourceTypeViewSet(LOFARViewSet): diff --git a/SAS/TMSS/src/tmss/urls.py b/SAS/TMSS/src/tmss/urls.py index d1afc07d461..c8349448bdc 100644 --- a/SAS/TMSS/src/tmss/urls.py +++ b/SAS/TMSS/src/tmss/urls.py @@ -87,7 +87,7 @@ router.register(r'cycle', viewsets.CycleViewSet) router.register(r'project', viewsets.ProjectViewSet) router.register(r'resource_unit', viewsets.ResourceUnitViewSet) router.register(r'resource_type', viewsets.ResourceTypeViewSet) -router.register(r'project_quotum', viewsets.ProjectQuotumViewSet) +router.register(r'project_quota', viewsets.ProjectQuotaViewSet) router.register(r'scheduling_set', viewsets.SchedulingSetViewSet) router.register(r'scheduling_unit_draft', viewsets.SchedulingUnitDraftViewSet) diff --git a/SAS/TMSS/test/t_tmssapp_specification_REST_API.py b/SAS/TMSS/test/t_tmssapp_specification_REST_API.py index e991c6e6489..55b04c17fa0 100755 --- a/SAS/TMSS/test/t_tmssapp_specification_REST_API.py +++ b/SAS/TMSS/test/t_tmssapp_specification_REST_API.py @@ -810,84 +810,84 @@ class ResourceTypeTestCase(unittest.TestCase): url = r_dict['url'] GET_and_assert_expected_response(self, url, 200, resource_type_test_data) -class ProjectQuotumTestCase(unittest.TestCase): - def test_project_quotum_list_apiformat(self): - r = requests.get(BASE_URL + '/project_quotum/?format=api', auth=AUTH) +class ProjectQuotaTestCase(unittest.TestCase): + def test_project_quota_list_apiformat(self): + r = requests.get(BASE_URL + '/project_quota/?format=api', auth=AUTH) self.assertEqual(r.status_code, 200) - self.assertTrue("Project Quotum List" in r.content.decode('utf8')) + self.assertTrue("Project Quota List" in r.content.decode('utf8')) - def test_project_quotum_GET_nonexistant_raises_error(self): - GET_and_assert_expected_response(self, BASE_URL + '/project_quotum/1234321/', 404, {}) + def test_project_quota_GET_nonexistant_raises_error(self): + GET_and_assert_expected_response(self, BASE_URL + '/project_quota/1234321/', 404, {}) - def test_project_quotum_POST_and_GET(self): - project_quotum_test_data = test_data_creator.ProjectQuotum() + def test_project_quota_POST_and_GET(self): + project_quota_test_data = test_data_creator.ProjectQuota() # POST and GET a new item and assert correctness - r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project_quotum/', project_quotum_test_data, 201, project_quotum_test_data) + 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_quotum_test_data) + GET_and_assert_expected_response(self, url, 200, project_quota_test_data) - def test_project_quotum_POST_and_GET(self): - project_quotum_test_data = test_data_creator.ProjectQuotum() + def test_project_quota_POST_and_GET(self): + project_quota_test_data = test_data_creator.ProjectQuota() # POST and GET a new item and assert correctness - r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project_quotum/', project_quotum_test_data, 201, project_quotum_test_data) + 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_quotum_test_data) + GET_and_assert_expected_response(self, url, 200, project_quota_test_data) - def test_project_quotum_PUT_invalid_raises_error(self): - PUT_and_assert_expected_response(self, BASE_URL + '/project_quotum/9876789876/', test_data_creator.Project(), 404, {}) + 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, {}) - def test_project_quotum_PUT(self): - project_quotum_test_data = test_data_creator.ProjectQuotum() + def test_project_quota_PUT(self): + project_quota_test_data = test_data_creator.ProjectQuota() # POST new item, verify - r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project_quotum/', project_quotum_test_data, 201, project_quotum_test_data) + 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_quotum_test_data) + GET_and_assert_expected_response(self, url, 200, project_quota_test_data) # PUT new values, verify - test_data = dict(test_data_creator.ProjectQuotum("other description")) - test_data['name'] = project_quotum_test_data['name'] # since name is PK, need to keep that unchanged + 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) - def test_project_quotum_PATCH(self): - project_quotum_test_data = test_data_creator.ProjectQuotum() + def test_project_quota_PATCH(self): + project_quota_test_data = test_data_creator.ProjectQuota() # POST new item, verify - r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project_quotum/', project_quotum_test_data, 201, project_quotum_test_data) + 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_quotum_test_data) + GET_and_assert_expected_response(self, url, 200, project_quota_test_data) test_patch = {"resource_quota": 500} # PATCH item and verify PATCH_and_assert_expected_response(self, url, test_patch, 200, test_patch) - expected_data = dict(project_quotum_test_data) + expected_data = dict(project_quota_test_data) expected_data.update(test_patch) GET_and_assert_expected_response(self, url, 200, expected_data) - def test_project_quotum_DELETE(self): - project_quotum_test_data = test_data_creator.ProjectQuotum() + def test_project_quota_DELETE(self): + project_quota_test_data = test_data_creator.ProjectQuota() # POST new item, verify - r_dict = POST_and_assert_expected_response(self, BASE_URL + '/project_quotum/', project_quotum_test_data, 201, project_quotum_test_data) + 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_quotum_test_data) + GET_and_assert_expected_response(self, url, 200, project_quota_test_data) # DELETE and check it's gone DELETE_and_assert_gone(self, url) - def test_project_quotum_PROTECT_behavior_on_project_deleted(self): + def test_project_quota_PROTECT_behavior_on_project_deleted(self): # POST new item with dependencies 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.ProjectQuotum(project_url=project_url)) - url = POST_and_assert_expected_response(self, BASE_URL + '/project_quotum/', test_data, 201, 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'] # verify GET_and_assert_expected_response(self, url, 200, test_data) diff --git a/SAS/TMSS/test/t_tmssapp_specification_django_API.py b/SAS/TMSS/test/t_tmssapp_specification_django_API.py index 4f9e5514dac..96755c50846 100755 --- a/SAS/TMSS/test/t_tmssapp_specification_django_API.py +++ b/SAS/TMSS/test/t_tmssapp_specification_django_API.py @@ -234,11 +234,11 @@ class ProjectTest(unittest.TestCase): self.assertGreater(after, entry.updated_at) -class ProjectQuotumTest(unittest.TestCase): - def test_ProjectQuotum_gets_created_with_correct_creation_timestamp(self): +class ProjectQuotaTest(unittest.TestCase): + def test_ProjectQuota_gets_created_with_correct_creation_timestamp(self): # setup before = datetime.utcnow() - entry = models.ProjectQuotum.objects.create(**ProjectQuotum_test_data()) + entry = models.ProjectQuota.objects.create(**ProjectQuota_test_data()) after = datetime.utcnow() @@ -246,9 +246,9 @@ class ProjectQuotumTest(unittest.TestCase): self.assertLess(before, entry.created_at) self.assertGreater(after, entry.created_at) - def test_ProjectQuotum_update_timestamp_gets_changed_correctly(self): + def test_ProjectQuota_update_timestamp_gets_changed_correctly(self): # setup - entry = models.ProjectQuotum.objects.create(**ProjectQuotum_test_data()) + entry = models.ProjectQuota.objects.create(**ProjectQuota_test_data()) before = datetime.utcnow() entry.save() after = datetime.utcnow() @@ -257,14 +257,14 @@ class ProjectQuotumTest(unittest.TestCase): self.assertLess(before, entry.updated_at) self.assertGreater(after, entry.updated_at) - def test_ProjectQuotum_prevents_missing_project(self): + def test_ProjectQuota_prevents_missing_project(self): # setup - test_data = dict(ProjectQuotum_test_data()) + test_data = dict(ProjectQuota_test_data()) test_data['project'] = None # assert with self.assertRaises(IntegrityError): - models.ProjectQuotum.objects.create(**test_data) + models.ProjectQuota.objects.create(**test_data) class SchedulingSetTest(unittest.TestCase): diff --git a/SAS/TMSS/test/tmss_test_data_django_models.py b/SAS/TMSS/test/tmss_test_data_django_models.py index 130992098a0..9dfdb6639b6 100644 --- a/SAS/TMSS/test/tmss_test_data_django_models.py +++ b/SAS/TMSS/test/tmss_test_data_django_models.py @@ -113,14 +113,14 @@ def ResourceType_test_data() -> dict: "name": 'my_resource_type_' + str(uuid.uuid4()), } -def ProjectQuotum_test_data() -> dict: +def ProjectQuota_test_data() -> dict: return { "tags": [], "description": 'my description ' + str(uuid.uuid4()), "resource_quota": '1000', "project": models.Project.objects.create(**Project_test_data()), "resource_type": models.ResourceType.objects.create(**ResourceType_test_data()), - "name": 'my_project_quotum_' + str(uuid.uuid4()), + "name": 'my_project_quota_' + str(uuid.uuid4()), } def SchedulingSet_test_data(name="my_scheduling_set") -> dict: diff --git a/SAS/TMSS/test/tmss_test_data_rest.py b/SAS/TMSS/test/tmss_test_data_rest.py index 47e7b94a607..d6ee684fda5 100644 --- a/SAS/TMSS/test/tmss_test_data_rest.py +++ b/SAS/TMSS/test/tmss_test_data_rest.py @@ -110,7 +110,7 @@ class TMSSRESTTestDataCreator(): return {"name": 'my_project_' + str(uuid.uuid4()), "description": description, "tags": [], - "project_quotums": [], + "project_quota": [], "priority": 1, "can_trigger": False, "private_data": True} @@ -123,7 +123,7 @@ class TMSSRESTTestDataCreator(): "name": 'my_resource_unit_' + str(uuid.uuid4()) } - def ResourceType(self, description="my project quotum description", resource_url=None): + def ResourceType(self, description="my project quota description", resource_url=None): if resource_url is None: resource_url = self.post_data_and_get_url(self.ResourceUnit(), '/resource_unit/') return { @@ -135,14 +135,14 @@ class TMSSRESTTestDataCreator(): - def ProjectQuotum(self, description="my project quotum description", project_url=None, resource_url=None): + def ProjectQuota(self, description="my project quota description", project_url=None, resource_url=None): if project_url is None: project_url = self.post_data_and_get_url(self.Project(), '/project/') if resource_url is None: resource_url = self.post_data_and_get_url(self.ResourceType(), '/resource_type/') return { - "name": 'my_project_quotum_' + str(uuid.uuid4()), + "name": 'my_project_quota_' + str(uuid.uuid4()), "description": description, "tags": [], "resource_quota": 1000, -- GitLab