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 eca4f0ecf01f6b3cffe61d8a7772ac5cbd5f88ab..ab5689f6fd8cd6bfced44aecda587b949a86267e 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 1c60c5493991f9cc61299a52e5846450c4f34a9f..50dac3cedb00629124bf3871727030f6c04fe311 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 892dff998ebe701d1549025db37b811cec866c2e..76da0a35a754e48e2c7d58bb1d59cfd96bb21eb2 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 5732999bbd0ecaf02df183dcc60c16c901e01d50..16f25c43c2a58715bfba2ed1fc87ac401db3a410 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 d1afc07d461104a2985bdef261cee836a92fc923..c8349448bdc8bec2c0071547af8dd4104de26d9b 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 e991c6e648948a0bf672bafece4ac84b4f4ba505..55b04c17fa0d48881019f0cdf273485fb458e1cc 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 4f9e5514dac008358852a13ca65bf1ee4237eef2..96755c50846fe04d203d18a84116bd99ff93dedc 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 130992098a045d87424990111082910c6863529e..9dfdb6639b630c88ceb5d3ddfd8458c7b7228c59 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 47e7b94a607dc5fa6430407f5493984d84bfd9dd..d6ee684fda53b9e50127b036251bd3c579f01839 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,