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

Handle realWorldEvidence in login response payload #54

Merged
merged 2 commits into from
Jan 26, 2025
Merged
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: 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()
Loading