Skip to content

Commit

Permalink
IDPF-304 Create professions endpoint (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
alsyx authored Mar 3, 2025
1 parent e4a4f6b commit d89d477
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 3 deletions.
18 changes: 18 additions & 0 deletions core/api/people_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,21 @@ def get_learning_interests(request):
return 500, {
"message": f"Could not get learning interests, reason: {unknown_error}"
}


@reference_router.get(
"professions/",
response={
200: list[TextChoiceResponseSchema],
500: Error,
},
)
def get_professions(request):
try:
professions = [
{"key": key, "value": value}
for key, value in core_services.get_professions()
]
return 200, professions
except Exception as unknown_error:
return 500, {"message": f"Could not get professions, reason: {unknown_error}"}
9 changes: 8 additions & 1 deletion core/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from profiles import services as profile_services
from profiles.models import LearningInterest, Workday
from profiles.models.combined import Profile
from profiles.models.generic import Country, UkStaffLocation
from profiles.models.generic import Country, Profession, UkStaffLocation
from profiles.models.peoplefinder import PeopleFinderProfile, RemoteWorking
from profiles.types import UNSET, Unset # noqa
from user import services as user_services
Expand Down Expand Up @@ -318,3 +318,10 @@ def get_learning_interests() -> list[tuple[LearningInterest, str]]:
Function for getting a list of all learning interests
"""
return profile_services.get_learning_interests()


def get_professions() -> list[tuple[Profession, str]]:
"""
Function for getting a list of all professions
"""
return profile_services.get_professions()
1 change: 1 addition & 0 deletions docs/apis/people-finder.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ The ID service exposes an API that provides read and edit functionality designed
`remote_working/` : lists remote working options
`workdays/` : lists workday options
`learning_interests/` : lists learning interests
`professions/` : lists professions
48 changes: 48 additions & 0 deletions e2e_tests/test_peoplefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from core.schemas.peoplefinder import CreateProfileRequest
from profiles.models import LearningInterest, Workday
from profiles.models.generic import Profession
from profiles.models.peoplefinder import RemoteWorking


Expand Down Expand Up @@ -254,3 +255,50 @@ def test_get_learning_interest(mocker):
assert json.loads(response.content) == {
"message": "Could not get learning interests, reason: mocked-test-exception"
}


def test_get_professions(mocker):
url = reverse("people-finder:get_professions")
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 Profession.choices
]

mocker.patch(
"core.services.get_professions",
return_value={
"COMMERCIAL": "Government commercial and contract management",
"CORP_FINANCE": "Corporate finance profession",
"COUNTER_FRAUD": "Counter-fraud standards and profession",
"DIGITAL_DATA_TECH": "Digital, data and technology profession",
"GOV_COMMS": "Government communication service",
},
)

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

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

mocker.patch(
"core.services.get_professions", 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 professions, reason: mocked-test-exception"
}
9 changes: 8 additions & 1 deletion profiles/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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.generic import Country, Profession, UkStaffLocation
from profiles.models.peoplefinder import (
LearningInterest,
PeopleFinderProfile,
Expand Down Expand Up @@ -438,3 +438,10 @@ def get_learning_interests() -> list[tuple[LearningInterest, str]]:
Gets all learning interests
"""
return peoplefinder.get_learning_interests()


def get_professions() -> list[tuple[Profession, str]]:
"""
Gets all professions
"""
return peoplefinder.get_professions()
9 changes: 8 additions & 1 deletion profiles/services/peoplefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from profiles.exceptions import ProfileExists
from profiles.models import LearningInterest, Workday
from profiles.models.generic import Country, Email, UkStaffLocation
from profiles.models.generic import Country, Email, Profession, UkStaffLocation
from profiles.models.peoplefinder import PeopleFinderProfile, RemoteWorking
from profiles.types import UNSET, Unset

Expand Down Expand Up @@ -462,3 +462,10 @@ def get_learning_interests() -> list[tuple[LearningInterest, str]]:
Gets all learning interests
"""
return LearningInterest.choices


def get_professions() -> list[tuple[Profession, str]]:
"""
Gets all professions
"""
return Profession.choices
37 changes: 37 additions & 0 deletions profiles/tests/test_services_peoplefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,40 @@ def test_get_learning_interest_options():
("Ministerial submissions", "Ministerial Submissions"),
("Coding", "Coding"),
]


def test_get_professions():
options = peoplefinder_services.get_professions()

assert options == [
("Government commercial and contract management", "Commercial"),
("Corporate finance profession", "Corp Finance"),
("Counter-fraud standards and profession", "Counter Fraud"),
("Digital, data and technology profession", "Digital Data Tech"),
("Government communication service", "Gov Comms"),
("Government economic service", "Gov Economics"),
("Government finance profession", "Gov Finance"),
("Government IT profession", "Gov It"),
("Government knowledge and information management profession", "Gov Knowledge"),
("Government legal service", "Gov Legal"),
("Government occupational psychology profession", "Gov Occupational"),
("Government operational research service", "Gov Operational"),
("Government planning inspectors", "Gov Planning Inspectors"),
("Government planning profession", "Gov Planning Profession"),
("Government property profession", "Gov Property"),
("Government security profession", "Gov Security"),
("Government science and engineering profession", "Gov Science"),
("Government social research profession", "Gov Social"),
("Government statistical service profession", "Gov Statistical"),
("Government tax profession", "Gov Tax"),
("Government veterinary profession", "Gov Vet"),
("Human resources profession", "Human Resources"),
("Intelligence analysis", "Intelligence Analysis"),
("Internal audit profession", "Internal Audit"),
("Medical profession", "Medical Profession"),
("Operational delivery profession", "Operation Delivery"),
("Policy profession", "Policy Profiession"),
("Procurement profession", "Procurement Profession"),
("Project delivery profession", "Project Delivery"),
("International trade profession", "International Trade"),
]

0 comments on commit d89d477

Please sign in to comment.