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

IDPF-302 create workday endpoint #113

Merged
merged 9 commits into from
Mar 3, 2025
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
19 changes: 19 additions & 0 deletions core/api/people_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,22 @@ def get_remote_working(request):
return 500, {
"message": f"Could not get remote working options, reason: {unknown_error}"
}


@reference_router.get(
"workday/",
response={
200: list[TextChoiceResponseSchema],
500: Error,
},
)
def get_workday(request):
try:
workday_options = [
{"key": key, "value": value} for key, value in core_services.get_workday()
]
return 200, workday_options
except Exception as unknown_error:
return 500, {
"message": f"Could not get workday options, reason: {unknown_error}"
}
8 changes: 8 additions & 0 deletions core/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Optional

from profiles import services as profile_services
from profiles.models import Workday
from profiles.models.combined import Profile
from profiles.models.generic import Country, UkStaffLocation
from profiles.models.peoplefinder import PeopleFinderProfile, RemoteWorking
Expand Down Expand Up @@ -303,3 +304,10 @@ def get_remote_working() -> list[tuple[RemoteWorking, str]]:
Function for getting a list of all remote working options
"""
return profile_services.get_remote_working()


def get_workday() -> list[tuple[Workday, str]]:
"""
Function for getting a list of all workday options
"""
return profile_services.get_workday()
1 change: 1 addition & 0 deletions docs/apis/people-finder.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ The ID service exposes an API that provides read and edit functionality designed
#### Reference data can be accessed via `/api/peoplefinder/reference/<endpoint>/`. Here is the list of reference endpoints:

`remote_working/` : lists remote working options
`workday/` : lists workday options
60 changes: 60 additions & 0 deletions e2e_tests/test_peoplefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.urls import reverse

from core.schemas.peoplefinder import CreateProfileRequest
from profiles.models import Workday
from profiles.models.peoplefinder import RemoteWorking


Expand Down Expand Up @@ -50,6 +51,11 @@ def test_get_profile(peoplefinder_profile):

url = reverse("people-finder:get_profile", args=(str(uuid.uuid4()),))

response = client.get(
url,
content_type="application/json",
)

assert response.status_code == 404


Expand Down Expand Up @@ -124,6 +130,11 @@ def test_get_remote_working(mocker):
},
)

response = client.get(
url,
content_type="application/json",
)

assert response.status_code == 500
assert json.loads(response.content) == {
"message": "Could not get remote working options, reason: too many values to unpack (expected 2)"
Expand All @@ -143,3 +154,52 @@ def test_get_remote_working(mocker):
assert json.loads(response.content) == {
"message": "Could not get remote working options, reason: mocked-test-exception"
}


def test_get_workday(mocker):
url = reverse("people-finder:get_workday")
client = Client()
response = client.get(
url,
content_type="application/json",
)
assert response.status_code == 200
assert json.loads(response.content) == [
{"key": key, "value": value} for key, value in Workday.choices
]

mocker.patch(
"core.services.get_workday",
return_value={
"Monday": "Mon",
"Tuesday": "Tue",
"Wednesday": "Wed",
"Thursday": "Thu",
"Friday": "Fri",
"Saturday": "Sat",
"Sunday": "Sun",
},
)

response = client.get(
url,
content_type="application/json",
)

assert response.status_code == 500
assert json.loads(response.content) == {
"message": "Could not get workday options, reason: too many values to unpack (expected 2)"
}

mocker.patch(
"core.services.get_workday", side_effect=Exception("mocked-test-exception")
)
response = client.get(
url,
content_type="application/json",
)

assert response.status_code == 500
assert json.loads(response.content) == {
"message": "Could not get workday options, reason: mocked-test-exception"
}
8 changes: 8 additions & 0 deletions profiles/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.db import models

from profiles.exceptions import NonCombinedProfileExists
from profiles.models import Workday
from profiles.models.combined import Profile
from profiles.models.generic import Country, UkStaffLocation
from profiles.models.peoplefinder import PeopleFinderProfile, RemoteWorking
Expand Down Expand Up @@ -419,3 +420,10 @@ def get_remote_working() -> list[tuple[RemoteWorking, str]]:
Gets all remote working options
"""
return peoplefinder.get_remote_working()


def get_workday() -> list[tuple[Workday, str]]:
"""
Gets all workday options
"""
return peoplefinder.get_workday()
8 changes: 8 additions & 0 deletions profiles/services/peoplefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.contrib.auth import get_user_model

from profiles.exceptions import ProfileExists
from profiles.models import Workday
from profiles.models.generic import Country, Email, UkStaffLocation
from profiles.models.peoplefinder import PeopleFinderProfile, RemoteWorking
from profiles.types import UNSET, Unset
Expand Down Expand Up @@ -447,3 +448,10 @@ def get_remote_working() -> list[tuple[RemoteWorking, str]]:
Gets all remote working options
"""
return RemoteWorking.choices


def get_workday() -> list[tuple[Workday, str]]:
"""
Gets all workday options
"""
return Workday.choices
14 changes: 14 additions & 0 deletions profiles/tests/test_services_peoplefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,17 @@ def test_get_remote_working_options():
("remote_worker", "Remote Worker"),
("split", "Split"),
]


def test_get_workday_options():
options = peoplefinder_services.get_workday()

assert options == [
("Monday", "Mon"),
("Tuesday", "Tue"),
("Wednesday", "Wed"),
("Thursday", "Thu"),
("Friday", "Fri"),
("Saturday", "Sat"),
("Sunday", "Sun"),
]