Skip to content

Commit

Permalink
update pr
Browse files Browse the repository at this point in the history
  • Loading branch information
alsyx committed Feb 24, 2025
1 parent 11cf50f commit 4458251
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
10 changes: 5 additions & 5 deletions core/api/people_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ def update_profile(


@router.get(
"ukstafflocations/",
"uk_staff_locations/",
response={
200: list[UkStaffLocationSchema],
404: Error,
},
)
def get_uk_staff_location(request) -> tuple[int, list[dict] | dict]:
def get_uk_staff_locations(request) -> tuple[int, list[dict] | dict]:
try:
locations = [location for location in UkStaffLocation.objects.all()]
if len(locations) > 0:
return 200, locations
uk_staff_locations = core_services.get_uk_staff_locations()
if len(uk_staff_locations) > 0:
return 200, uk_staff_locations
else:
return 404, {"message": "No UK staff locations to display"}
except Exception as unknown_error:
Expand Down
4 changes: 4 additions & 0 deletions core/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,7 @@ def delete_identity(profile: Profile) -> None:
if not all_remaining_profiles:
user = user_services.get_by_id(sso_email_id=profile_id, include_inactive=True)
user_services.delete_from_database(user=user)


def get_uk_staff_locations() -> list[dict]:
return profile_services.get_uk_staff_locations()
5 changes: 4 additions & 1 deletion profiles/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from profiles.exceptions import NonCombinedProfileExists
from profiles.models.combined import Profile
from profiles.models.generic import Country, UkStaffLocation
from profiles.models.peoplefinder import PeopleFinderProfile
from profiles.models.staff_sso import StaffSSOProfile
from profiles.services import combined, peoplefinder, staff_sso
Expand Down Expand Up @@ -392,3 +391,7 @@ def delete(profile_id: str) -> dict[str, models.Model]:
del all_profiles["combined"]

return all_profiles


def get_uk_staff_locations() -> list[dict]:
return peoplefinder.get_uk_staff_locations()
5 changes: 5 additions & 0 deletions profiles/services/peoplefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,8 @@ def delete_from_database(
)

peoplefinder_profile.delete()


def get_uk_staff_locations() -> list[dict]:
locations = [location for location in UkStaffLocation.objects.all()]
return locations
11 changes: 11 additions & 0 deletions profiles/tests/test_services_peoplefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,14 @@ def test_get_by_id(peoplefinder_profile):
with pytest.raises(PeopleFinderProfile.DoesNotExist) as ex:
peoplefinder_services.get_by_slug(slug="550e8400-e29b-41d4-a716-446655440000")
assert str(ex.value.args[0]) == "PeopleFinderProfile matching query does not exist."


def test_get_uk_staff_locations():
locations = peoplefinder_services.get_uk_staff_locations()
# Check if code, name, organisation and building_name exists in the location dict
assert {
"code": "location_1",
"name": "OAB_UK",
"organisation": "DBT",
"building_name": "OAB",
}.items() <= locations[0].__dict__.items()

0 comments on commit 4458251

Please sign in to comment.