An open source, non-profit web search engine
Wrap marketing-consent GET response in an object
Daoud Clarke25916757eeeb
diff --git a/mwmbl/platform/api.py b/mwmbl/platform/api.pyindex e3148a3..0e0974c 100644--- a/mwmbl/platform/api.py+++ b/mwmbl/platform/api.py@@ -24,7 +24,7 @@ from mwmbl.platform.schemas import (UserProfileResponse, SubscriptionResponse, CheckoutRequest, CheckoutResponse, ChangePlanRequest,ForgotPasswordRequest, ResetPasswordRequest,AgreementAcceptRequest, AgreementResponse,- MarketingConsentRequest, MarketingConsentResponse,+ MarketingConsentRequest, MarketingConsentResponse, MarketingConsentListResponse,)logger = logging.getLogger(__name__)@@ -483,7 +483,7 @@ def get_agreement_history(request) -> list[AgreementResponse]:@router.get("/marketing-consent",auth=JWTAuth(),- response=list[MarketingConsentResponse],+ response=MarketingConsentListResponse,summary="Get marketing email consent",description=("Returns the current marketing email consent state for each source the user has a "@@ -493,9 +493,9 @@ def get_agreement_history(request) -> list[AgreementResponse]:),tags=["Marketing"],)-def get_marketing_consent(request) -> list[MarketingConsentResponse]:+def get_marketing_consent(request) -> MarketingConsentListResponse:check_email_verified(request)- result = []+ consent = []for source in MarketingSource:latest = (MarketingConsent.objects.filter(user=request.user, source=source)@@ -503,12 +503,12 @@ def get_marketing_consent(request) -> list[MarketingConsentResponse]:.first())if latest:- result.append(MarketingConsentResponse(+ consent.append(MarketingConsentResponse(source=latest.source,opted_in=latest.opted_in,timestamp=latest.timestamp,))- return result+ return MarketingConsentListResponse(consent=consent)@router.post(diff --git a/mwmbl/platform/schemas.py b/mwmbl/platform/schemas.pyindex 1302a23..cd81ee9 100644--- a/mwmbl/platform/schemas.py+++ b/mwmbl/platform/schemas.py@@ -115,6 +115,12 @@ class MarketingConsentResponse(Schema):timestamp: datetime = Field(description="When this consent decision was recorded.")+class MarketingConsentListResponse(Schema):+ consent: list[MarketingConsentResponse] = Field(+ description="Current marketing consent state per source the user has a record for.",+ )++class Registration(Schema):email: str = Field(description="Email address for the new account. Must be unique.")password: str = Field(description="Password for the new account.")diff --git a/test/test_marketing_consent.py b/test/test_marketing_consent.pyindex 322fb24..96c24e4 100644--- a/test/test_marketing_consent.py+++ b/test/test_marketing_consent.py@@ -84,7 +84,7 @@ def test_get_marketing_consent_returns_latest_per_source(client, verified_user,response = client.get(CONSENT_URL, HTTP_AUTHORIZATION=f"Bearer {access_token}")assert response.status_code == 200- data = response.json()+ data = response.json()["consent"]assert len(data) == 1assert data[0]["source"] == "API"assert data[0]["opted_in"] is False@@ -106,7 +106,7 @@ def test_update_marketing_consent_appends_row(client, verified_user, access_tokeassert MarketingConsent.objects.filter(user=verified_user, source=MarketingSource.GUI).count() == 2# GET now reflects the withdrawal.- latest = client.get(CONSENT_URL, HTTP_AUTHORIZATION=f"Bearer {access_token}").json()+ latest = client.get(CONSENT_URL, HTTP_AUTHORIZATION=f"Bearer {access_token}").json()["consent"]assert latest[0]["opted_in"] is False