diff --git a/cdp_backend/database/constants.py b/cdp_backend/database/constants.py index 207c421b..482a3054 100644 --- a/cdp_backend/database/constants.py +++ b/cdp_backend/database/constants.py @@ -38,3 +38,12 @@ class MatterStatusDecision: ADOPTED = "Adopted" REJECTED = "Rejected" IN_PROGRESS = "In Progress" + + +class RoleTitle: + COUNCILMEMBER = "Councilmember" + COUNCILPRESIDENT = "Council President" + CHAIR = "Chair" + VICE_CHAIR = "Vice Chair" + ALTERNATE = "Alternate" + MEMBER = "Member" diff --git a/cdp_backend/database/models.py b/cdp_backend/database/models.py index 0edd21ee..be244940 100644 --- a/cdp_backend/database/models.py +++ b/cdp_backend/database/models.py @@ -15,6 +15,7 @@ EventMinutesItemDecision, MatterStatusDecision, Order, + RoleTitle, VoteDecision, ) from .types import IndexedField, IndexedFieldSet @@ -187,7 +188,10 @@ class Role(Model): """ id = fields.IDField() - title = fields.TextField(required=True) + title = fields.TextField( + required=True, + validator=validators.create_constant_value_validator(RoleTitle, True), + ) person_ref = fields.ReferenceField(Person, required=True, auto_load=False) body_ref = fields.ReferenceField(Body, auto_load=False) seat_ref = fields.ReferenceField(Seat, required=True, auto_load=False) @@ -201,7 +205,7 @@ class Meta: @classmethod def Example(cls) -> Model: role = cls() - role.title = "Council President" + role.title = RoleTitle.COUNCILPRESIDENT role.person_ref = Person.Example() role.body_ref = Body.Example() role.seat_ref = Seat.Example() diff --git a/cdp_backend/pipeline/mock_get_events.py b/cdp_backend/pipeline/mock_get_events.py index 7cc5a45a..1364cff3 100644 --- a/cdp_backend/pipeline/mock_get_events.py +++ b/cdp_backend/pipeline/mock_get_events.py @@ -9,6 +9,7 @@ from ..database.constants import ( EventMinutesItemDecision, MatterStatusDecision, + RoleTitle, VoteDecision, ) from ..utils.constants_utils import get_all_class_attr_values @@ -76,14 +77,14 @@ def _get_example_person(seat_num: int) -> Person: """ # Create a list of roles roles = [ - Role(title="Councilmember", body=Body(name="Example Committee")), - Role(title="Chair", body=Body(name=f"Example Committee {seat_num}")), + Role(title=RoleTitle.COUNCILMEMBER, body=Body(name="Example Committee")), + Role(title=RoleTitle.CHAIR, body=Body(name=f"Example Committee {seat_num}")), ] # Add Council President role for seat position 1 if seat_num == 1: roles.append( - Role(title="Council President", body=Body(name="Example Committee")) + Role(title=RoleTitle.COUNCILPRESIDENT, body=Body(name="Example Committee")) ) # Get the seat electoral type num diff --git a/cdp_backend/tests/database/test_validators.py b/cdp_backend/tests/database/test_validators.py index 92a95123..3e6cfca1 100644 --- a/cdp_backend/tests/database/test_validators.py +++ b/cdp_backend/tests/database/test_validators.py @@ -10,6 +10,7 @@ from cdp_backend.database.constants import ( EventMinutesItemDecision, MatterStatusDecision, + RoleTitle, VoteDecision, ) @@ -178,3 +179,17 @@ def test_matter_status_decision_is_valid(decision: str, expected_result: bool) - ) actual_result = validator_func(decision) assert actual_result == expected_result + + +@pytest.mark.parametrize( + "title, expected_result", + [ + (None, False), + ("Councilmember", True), + ("INVALID", False), + ], +) +def test_role_title_is_valid(title: str, expected_result: bool) -> None: + validator_func = validators.create_constant_value_validator(RoleTitle, True) + actual_result = validator_func(title) + assert actual_result == expected_result