From d5e40d35768bd6d6b503548a3d8a08236575cd70 Mon Sep 17 00:00:00 2001 From: Quan Pham Date: Thu, 4 Jun 2026 14:36:07 -0400 Subject: [PATCH] Include whether allocation's project is externally funded Updated test cases to work with the latest version of `coldfront-plugin-cloud`, as changes to the quota system [1] broke the tests. [1] https://github.com/nerc-project/coldfront-plugin-cloud/pull/287 --- src/coldfront_plugin_api/serializers.py | 28 +++++++++++++++++-- .../tests/unit/test_allocations.py | 9 ++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/coldfront_plugin_api/serializers.py b/src/coldfront_plugin_api/serializers.py index 8a29059..8e06707 100644 --- a/src/coldfront_plugin_api/serializers.py +++ b/src/coldfront_plugin_api/serializers.py @@ -1,17 +1,27 @@ from rest_framework import serializers from coldfront.core.allocation.models import Allocation, AllocationAttribute -from coldfront.core.allocation.models import Project +from coldfront.core.project.models import Project, ProjectAttribute class ProjectSerializer(serializers.ModelSerializer): class Meta: model = Project - fields = ["id", "title", "pi", "description", "field_of_science", "status"] + fields = [ + "id", + "title", + "pi", + "description", + "field_of_science", + "status", + "attributes", + ] pi = serializers.SerializerMethodField() field_of_science = serializers.SerializerMethodField() status = serializers.SerializerMethodField() + # is_externally_funded = serializers.SerializerMethodField() + attributes = serializers.SerializerMethodField() def get_pi(self, obj: Project) -> str: return obj.pi.email @@ -22,6 +32,20 @@ def get_field_of_science(self, obj: Project) -> str: def get_status(self, obj: Project) -> str: return obj.status.name + def get_attributes(self, obj: Project): + attrs = ProjectAttribute.objects.filter(project=obj) + return {a.proj_attr_type.name: a.value for a in attrs} + + # def get_is_externally_funded(self, obj: Project) -> bool | None: + # is_externally_funded_attr = ProjectAttribute.objects.filter( + # project=obj, proj_attr_type__name="Is Externally Funded" + # ).first() + # return ( + # is_externally_funded_attr.value.lower() == "yes" + # if is_externally_funded_attr + # else None + # ) + class AllocationSerializer(serializers.ModelSerializer): class Meta: diff --git a/src/coldfront_plugin_api/tests/unit/test_allocations.py b/src/coldfront_plugin_api/tests/unit/test_allocations.py index af71803..12642af 100644 --- a/src/coldfront_plugin_api/tests/unit/test_allocations.py +++ b/src/coldfront_plugin_api/tests/unit/test_allocations.py @@ -1,4 +1,5 @@ from os import devnull +import logging import sys from coldfront.core.allocation import models as allocation_models @@ -17,9 +18,11 @@ def setUp(self) -> None: call_command("register_cloud_attributes") sys.stdout = backup - self.resource = self.new_openstack_resource( - name="Devstack", auth_url="http://localhost" - ) + self.resource = self.new_openshift_resource(name="Microshift") + + logging.disable(logging.CRITICAL) + call_command("register_default_quotas", apply=True) + logging.disable(logging.NOTSET) @staticmethod def new_allocation_attribute(allocation, attribute, value):