From 44acffaf9a1b7802488334fb3620ad4366fe8e94 Mon Sep 17 00:00:00 2001 From: Aakash Singh Date: Tue, 17 Sep 2024 15:35:47 +0530 Subject: [PATCH] fixes --- care/facility/api/serializers/facility.py | 1 + care/users/tests/test_api.py | 1 + care/utils/registries/feature_flag.py | 18 +++++++++++------- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/care/facility/api/serializers/facility.py b/care/facility/api/serializers/facility.py index 17ade57db4..99c00bbe69 100644 --- a/care/facility/api/serializers/facility.py +++ b/care/facility/api/serializers/facility.py @@ -145,6 +145,7 @@ class Meta: "read_cover_image_url", "patient_count", "bed_count", + "facility_flags", ] read_only_fields = ("modified_date", "created_date") diff --git a/care/users/tests/test_api.py b/care/users/tests/test_api.py index ef58f25e7c..28b87af4bf 100644 --- a/care/users/tests/test_api.py +++ b/care/users/tests/test_api.py @@ -46,6 +46,7 @@ def get_detail_representation(self, obj=None) -> dict: "doctor_qualification": obj.doctor_qualification, "weekly_working_hours": obj.weekly_working_hours, "video_connect_link": obj.video_connect_link, + "user_flags": [], **self.get_local_body_district_state_representation(obj), } diff --git a/care/utils/registries/feature_flag.py b/care/utils/registries/feature_flag.py index c672c5c6b1..337413e1ed 100644 --- a/care/utils/registries/feature_flag.py +++ b/care/utils/registries/feature_flag.py @@ -11,6 +11,10 @@ class FlagNotFoundException(ValidationError): pass +class InvalidFlagTypeException(ValidationError): + pass + + class FlagType(enum.Enum): USER = "USER" FACILITY = "FACILITY" @@ -27,7 +31,7 @@ class FlagRegistry: @classmethod def register(cls, flag_type: FlagType, flag_name: FlagName) -> None: if flag_type not in FlagType: - return + raise InvalidFlagTypeException("Invalid Flag Type") if flag_type not in cls._flags: cls._flags[flag_type] = {} cls._flags[flag_type][flag_name] = True @@ -52,6 +56,12 @@ def validate_flag_type(cls, flag_type: FlagType) -> None: if flag_type not in FlagType or flag_type not in cls._flags: raise FlagNotFoundException("Invalid Flag Type") + @classmethod + def validate_flag_name(cls, flag_type: FlagType, flag_name): + cls.validate_flag_type(flag_type) + if flag_name not in cls._flags[flag_type]: + raise FlagNotFoundException("Flag not registered") + @classmethod def get_all_flags(cls, flag_type: FlagType) -> list[FlagName]: cls.validate_flag_type(flag_type) @@ -63,11 +73,5 @@ def get_all_flags_as_choices( ) -> list[tuple[FlagName, FlagName]]: return ((x, x) for x in cls._flags.get(flag_type, {}).keys()) - @classmethod - def validate_flag_name(cls, flag_type: FlagType, flag_name): - cls.validate_flag_type(flag_type) - if flag_name not in cls._flags[flag_type]: - raise FlagNotFoundException("Flag not registered") - FlagRegistry.register(FlagType.USER, "USER_TEST_FLAG")