Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/role-title-constants #155

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cdp_backend/database/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 6 additions & 2 deletions cdp_backend/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
EventMinutesItemDecision,
MatterStatusDecision,
Order,
RoleTitle,
VoteDecision,
)
from .types import IndexedField, IndexedFieldSet
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions cdp_backend/pipeline/mock_get_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ..database.constants import (
EventMinutesItemDecision,
MatterStatusDecision,
RoleTitle,
VoteDecision,
)
from ..utils.constants_utils import get_all_class_attr_values
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions cdp_backend/tests/database/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from cdp_backend.database.constants import (
EventMinutesItemDecision,
MatterStatusDecision,
RoleTitle,
VoteDecision,
)

Expand Down Expand Up @@ -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