feat: get org response mirrors get user orgs structure
All checks were successful
ci / lint_and_test (push) Successful in 13s

This commit is contained in:
Chris Milne 2026-06-10 09:49:05 +01:00
parent 939abaefe9
commit 3b82025abb
5 changed files with 52 additions and 46 deletions

View file

@ -92,17 +92,26 @@ async def get_org_by_id(org_model: org_model_root_claim_query_dependency):
Returns organisation details including key member email addresses
"""
response = {
"id": org_model.id,
"organisation_id": org_model.id,
"name": org_model.name,
"status": org_model.status,
"owner_contact": org_model.owner_contact_rel.email,
"billing_contact": org_model.billing_contact_rel.email,
"security_contact": org_model.security_contact_rel.email,
"root_user": org_model.root_user_email,
"intake_questionnaire": org_model.intake_questionnaire,
"root_user_email": org_model.root_user_email,
"billing_contact": {
"id": org_model.billing_contact_id,
"email": org_model.billing_contact_rel.email,
},
"owner_contact": {
"id": org_model.owner_contact_id,
"email": org_model.owner_contact_rel.email,
},
"security_contact": {
"id": org_model.security_contact_id,
"email": org_model.security_contact_rel.email,
},
}
return response
return {"organisations": [response]}
@router.post(

View file

@ -22,11 +22,27 @@ class Questionnaire(CustomBaseModel):
question_three: Optional[str] = None
class OrgSchema(CustomBaseModel):
class OrgSummary(CustomBaseModel):
id: int
name: str
class ContactSummary(CustomBaseModel):
id: int
email: Optional[EmailStr] = None
class OrgSchema(OrgIDMixin):
name: str
status: Status
root_user_email: EmailStr
intake_questionnaire: Optional[Questionnaire] = None
billing_contact: ContactSummary
owner_contact: ContactSummary
security_contact: ContactSummary
class OrgPostOrgRequest(CustomBaseModel):
name: str
intake_questionnaire: Optional[Questionnaire] = None
@ -93,7 +109,7 @@ class OrgPatchRootResponse(CustomBaseModel):
class OrgGetUserResponse(CustomBaseModel):
users: list[dict[str, str | int]]
organisation: OrgSchema
organisation: OrgSummary
class OrgGetGroupResponse(CustomBaseModel):
@ -104,22 +120,15 @@ class OrgGetContactResponse(CustomBaseModel):
model_config = ConfigDict(from_attributes=True, extra="ignore")
contact: ContactModel
organisation: OrgSchema
organisation: OrgSummary
class OrgPatchContactResponse(CustomBaseModel):
model_config = ConfigDict(from_attributes=True, extra="ignore")
contact: ContactModel
organisation: OrgSchema
organisation: OrgSummary
class OrgGetOrgResponse(CustomBaseModel):
id: int
name: str
status: Status
root_user: Optional[str] = None
owner_contact: Optional[str] = None
billing_contact: Optional[str] = None
security_contact: Optional[str] = None
intake_questionnaire: Optional[Questionnaire] = None
organisations: list[OrgSchema]

View file

@ -5,27 +5,10 @@ Pydantic models for the user module
from typing import Optional
from pydantic import EmailStr
from src.organisation.constants import Status
from src.organisation.schemas import Questionnaire
from src.organisation.schemas import OrgSchema
from src.schemas import CustomBaseModel, OrgIDMixin
class ContactModel(CustomBaseModel):
id: int
email: Optional[EmailStr] = None
class OrgSchema(OrgIDMixin):
name: str
status: Status
root_user_email: EmailStr
intake_questionnaire: Optional[Questionnaire] = None
billing_contact: ContactModel
owner_contact: ContactModel
security_contact: ContactModel
class OIDCClaims(CustomBaseModel):
exp: int
iat: int

View file

@ -40,4 +40,4 @@ async def test_get_org_auth_root_su(default_client: AsyncClient, db_session):
resp = await default_client.get("/org?org_id=2")
assert resp.status_code != 422
assert resp.status_code == 200
assert resp.json()["name"] == "Test Org Two"
assert resp.json()["organisations"][0]["name"] == "Test Org Two"

View file

@ -21,15 +21,20 @@ async def test_get_org_success(default_client: AsyncClient):
data = resp.json()
assert resp.status_code == 200
assert data["id"] == 1
assert data["name"] == "Test Org"
assert data["status"] == "approved"
assert data["root_user"] == "admin@test.com"
assert data["billing_contact"] == "billing@test.org"
assert data["owner_contact"] == "owner@test.org"
assert data["security_contact"] == "security@test.org"
assert "intake_questionnaire" in data
assert isinstance(data["intake_questionnaire"], dict)
org = data["organisations"][0]
assert isinstance(org, dict)
assert org["organisation_id"] == 1
assert org["name"] == "Test Org"
assert org["status"] == "approved"
assert org["root_user_email"] == "admin@test.com"
assert "intake_questionnaire" in org
assert isinstance(org["intake_questionnaire"], dict)
assert org["billing_contact"]["email"] == "billing@test.org"
assert org["owner_contact"]["email"] == "owner@test.org"
assert org["security_contact"]["email"] == "security@test.org"
@pytest.mark.parametrize(