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-310 Create RemoteWorking endpoint #114

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions core/api/people_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from core.schemas.profiles import (
PeopleFinderProfileRequestSchema,
PeopleFinderProfileResponseSchema,
TextChoiceResponseSchema,
UkStaffLocationSchema,
)
from profiles.models.combined import Profile
Expand Down Expand Up @@ -130,3 +131,23 @@ def get_uk_staff_locations(request) -> tuple[int, list[UkStaffLocation] | dict]:
return 404, {
"message": f"Could not get UK staff locations, reason: {unknown_error}"
}


@reference_router.get(
"remote_working/",
response={
200: list[TextChoiceResponseSchema],
500: Error,
},
)
def get_remote_working(request):
try:
remote_working_options = [
{"key": key, "value": value}
for key, value in core_services.get_remote_working()
]
return 200, remote_working_options
except Exception as unknown_error:
return 500, {
"message": f"Could not get remote working options, reason: {unknown_error}"
}
5 changes: 5 additions & 0 deletions core/schemas/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,8 @@ class Meta:
"organisation",
"building_name",
]


class TextChoiceResponseSchema(Schema):
key: str
value: str
13 changes: 11 additions & 2 deletions core/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
from datetime import datetime
from typing import Optional

from conftest import peoplefinder_profile
from profiles import services as profile_services
from profiles.models.combined import Profile
from profiles.models.generic import Country, UkStaffLocation
from profiles.models.peoplefinder import PeopleFinderProfile
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 @@ -293,4 +292,14 @@ def get_countries() -> list[Country]:


def get_uk_staff_locations() -> list[UkStaffLocation]:
"""
Function for getting a list of all UK staff locations
"""
return profile_services.get_uk_staff_locations()


def get_remote_working() -> list[tuple[RemoteWorking, str]]:
"""
Function for getting a list of all remote working options
"""
return profile_services.get_remote_working()
4 changes: 4 additions & 0 deletions docs/apis/people-finder.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
> This API is available at `/api/peoplefinder/`

The ID service exposes an API that provides read and edit functionality designed for the PeopleFinder / Intranet integration.

#### Reference data can be accessed via `/api/peoplefinder/reference/<endpoint>/`. Here is the list of reference endpoints:

`remote_working/` : lists remote working options
59 changes: 59 additions & 0 deletions e2e_tests/test_peoplefinder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import json

import pytest
from django.test.client import Client
from django.urls import reverse

from profiles.models.peoplefinder import RemoteWorking


pytestmark = [
pytest.mark.django_db,
pytest.mark.e2e,
]


def test_get_remote_working(mocker):
url = reverse("people-finder:get_remote_working")
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 RemoteWorking.choices
]

mocker.patch(
"core.services.get_remote_working",
return_value={
"remote_worker": "REMOTE WORKER",
"office_worker": "OFFICE WORKER",
"split": "SPLIT",
},
)
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)"
}

mocker.patch(
"core.services.get_remote_working",
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 remote working options, reason: mocked-test-exception"
}
12 changes: 11 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.combined import Profile
from profiles.models.generic import Country, UkStaffLocation
from profiles.models.peoplefinder import PeopleFinderProfile
from profiles.models.peoplefinder import PeopleFinderProfile, RemoteWorking
from profiles.models.staff_sso import StaffSSOProfile
from profiles.services import combined, peoplefinder, staff_sso
from profiles.types import Unset
Expand Down Expand Up @@ -408,4 +408,14 @@ def get_countries() -> list[Country]:


def get_uk_staff_locations() -> list[UkStaffLocation]:
"""
Gets all UK staff locations
"""
return peoplefinder.get_uk_staff_locations()


def get_remote_working() -> list[tuple[RemoteWorking, str]]:
"""
Gets all remote working options
"""
return peoplefinder.get_remote_working()
12 changes: 11 additions & 1 deletion profiles/services/peoplefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.contrib.auth import get_user_model

from profiles.models.generic import Country, Email, UkStaffLocation
from profiles.models.peoplefinder import PeopleFinderProfile
from profiles.models.peoplefinder import PeopleFinderProfile, RemoteWorking
from profiles.types import UNSET, Unset


Expand Down Expand Up @@ -431,4 +431,14 @@ def get_countries() -> list[Country]:


def get_uk_staff_locations() -> list[UkStaffLocation]:
"""
Gets all UK staff locations
"""
return list(UkStaffLocation.objects.all())


def get_remote_working() -> list[tuple[RemoteWorking, str]]:
"""
Gets all remote working options
"""
return RemoteWorking.choices
11 changes: 11 additions & 0 deletions profiles/tests/test_services_peoplefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from profiles.models import PeopleFinderProfile
from profiles.models.generic import Country, Grade, UkStaffLocation
from profiles.models.peoplefinder import RemoteWorking
from profiles.services import peoplefinder as peoplefinder_services
from profiles.types import UNSET
from user.models import User
Expand Down Expand Up @@ -139,3 +140,13 @@ def test_get_uk_staff_locations():
"organisation": "DBT",
"building_name": "OAB",
}.items() <= locations[0].__dict__.items()


def test_get_remote_working_options():
options = peoplefinder_services.get_remote_working()

assert options == [
("office_worker", "Office Worker"),
("remote_worker", "Remote Worker"),
("split", "Split"),
]