Skip to content

Commit

Permalink
Merge pull request #54 from robberwick/consents-real-world-evidence
Browse files Browse the repository at this point in the history
Handle `realWorldEvidence` in login response payload
  • Loading branch information
robberwick authored Jan 26, 2025
2 parents 124edb7 + 8e66995 commit 8d5c87e
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/pylibrelinkup/models/login.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List

from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, field_validator

__all__ = [
"Llu",
Expand All @@ -26,8 +26,21 @@ class Llu(BaseModel):
touAccept: int = Field(default=0)


class HistoryItem(BaseModel):
policyAccept: int = Field(default=0)
declined: bool | None = None


class RealWorldEvidence(BaseModel):
policyAccept: int = Field(default=0)
declined: bool = False
touAccept: int = Field(default=0)
history: List[HistoryItem] = []


class Consents(BaseModel):
llu: Llu
llu: Llu = Llu()
realWorldEvidence: RealWorldEvidence = RealWorldEvidence()


class SystemMessages(BaseModel):
Expand Down Expand Up @@ -88,6 +101,10 @@ class Data(BaseModel):
authTicket: AuthTicket
invitations: List[str]

@field_validator("invitations", mode="before")
def coerce_null_to_empty_list(cls, v):
return v if v is not None else []


class LoginResponse(BaseModel):
status: int = Field(default=0)
Expand Down
82 changes: 82 additions & 0 deletions tests/data/realworldevidence_consent_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"status": 0,
"data": {
"user": {
"id": "<Id>",
"firstName": "<name>",
"lastName": "<name>",
"email": "<email>",
"country": "GB",
"uiLanguage": "en-GB",
"communicationLanguage": "en-GB",
"accountType": "pat",
"uom": "0",
"dateFormat": "2",
"timeFormat": "2",
"emailDay": [
1
],
"system": {
"messages": {
"appReviewBanner": 1704319358,
"firstUsePhoenix": 1704288789,
"firstUsePhoenixReportsDataMerged": 1704288789,
"lluGettingStartedBanner": 1704319384,
"lluNewFeatureModal": 1704319219,
"lvWebPostRelease": "3.16.19",
"streamingTourMandatory": 1704319433
}
},
"details": {},
"twoFactor": {
"primaryMethod": "phone",
"primaryValue": "<number>",
"secondaryMethod": "email",
"secondaryValue": "<email>"
},
"created": 1704288789,
"lastLogin": 1737891119,
"programs": {},
"dateOfBirth": 29894400,
"practices": {},
"devices": {
"<device id>": {
"id": "<device id>",
"nickname": "",
"sn": "<sn>",
"type": 40066,
"uploadDate": 1737891498
}
},
"consents": {
"realWorldEvidence": {
"policyAccept": 1737890544,
"declined": true,
"touAccept": 0,
"history": [
{
"policyAccept": 1704288796
},
{
"policyAccept": 1737890544,
"declined": true
}
]
}
}
},
"messages": {
"unread": 0
},
"notifications": {
"unresolved": 0
},
"authTicket": {
"token": "parp",
"expires": 1753443551,
"duration": 15552000000
},
"invitations": null,
"trustedDeviceToken": ""
}
}
15 changes: 15 additions & 0 deletions tests/test_client_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,18 @@ def test_redirection_response_raises_redirect_error(

with pytest.raises(RedirectError):
pylibrelinkup_client.client.authenticate()


def test_realworldevidence_consent_in_login_response(
mocked_responses, pylibrelinkup_client, get_response_json
):
"""Test that the authenticate method raises an error when the user needs to accept the real world evidence consent."""

mocked_responses.add(
responses.POST,
f"{pylibrelinkup_client.api_url.value}/llu/auth/login",
json=get_response_json("realworldevidence_consent_response.json"),
status=200,
)

pylibrelinkup_client.client.authenticate()

0 comments on commit 8d5c87e

Please sign in to comment.