Skip to content

Commit

Permalink
Fix #814: add timestamps to newsletters and waitlists in contact resp…
Browse files Browse the repository at this point in the history
…onses
  • Loading branch information
leplatrem committed Sep 8, 2023
1 parent de9a6a1 commit ce19805
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 21 deletions.
12 changes: 9 additions & 3 deletions ctms/schemas/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
)
from .fxa import FirefoxAccountsInSchema, FirefoxAccountsSchema
from .mofo import MozillaFoundationInSchema, MozillaFoundationSchema
from .newsletter import NewsletterInSchema, NewsletterSchema, NewsletterTableSchema
from .newsletter import (
NewsletterInSchema,
NewsletterSchema,
NewsletterTableSchema,
NewsletterTimestampedSchema,
)
from .product import ProductBaseSchema, ProductSegmentEnum
from .waitlist import (
RelayWaitlistInSchema,
Expand All @@ -26,6 +31,7 @@
WaitlistInSchema,
WaitlistSchema,
WaitlistTableSchema,
WaitlistTimestampedSchema,
validate_waitlist_newsletters,
)

Expand Down Expand Up @@ -360,8 +366,8 @@ class CTMSResponse(BaseModel):
email: EmailSchema
fxa: FirefoxAccountsSchema
mofo: MozillaFoundationSchema
newsletters: List[NewsletterSchema]
waitlists: List[WaitlistSchema]
newsletters: List[NewsletterTimestampedSchema]
waitlists: List[WaitlistTimestampedSchema]
# Retro-compat fields
vpn_waitlist: VpnWaitlistSchema
relay_waitlist: RelayWaitlistSchema
Expand Down
13 changes: 8 additions & 5 deletions ctms/schemas/newsletter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ class Config:
NewsletterSchema = NewsletterBase


class NewsletterTableSchema(NewsletterBase):
email_id: UUID4 = Field(
description=EMAIL_ID_DESCRIPTION,
example=EMAIL_ID_EXAMPLE,
)
class NewsletterTimestampedSchema(NewsletterBase):
create_timestamp: datetime = Field(
description="Newsletter data creation timestamp",
example="2020-12-05T19:21:50.908000+00:00",
Expand All @@ -64,5 +60,12 @@ class NewsletterTableSchema(NewsletterBase):
example="2021-02-04T15:36:57.511000+00:00",
)


class NewsletterTableSchema(NewsletterTimestampedSchema):
email_id: UUID4 = Field(
description=EMAIL_ID_DESCRIPTION,
example=EMAIL_ID_EXAMPLE,
)

class Config:
extra = "forbid"
13 changes: 8 additions & 5 deletions ctms/schemas/waitlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ class Config:
WaitlistInSchema = WaitlistBase


class WaitlistTableSchema(WaitlistBase):
email_id: UUID4 = Field(
description=EMAIL_ID_DESCRIPTION,
example=EMAIL_ID_EXAMPLE,
)
class WaitlistTimestampedSchema(WaitlistBase):
create_timestamp: datetime = Field(
description="Waitlist data creation timestamp",
example="2020-12-05T19:21:50.908000+00:00",
Expand All @@ -74,6 +70,13 @@ class WaitlistTableSchema(WaitlistBase):
example="2021-02-04T15:36:57.511000+00:00",
)


class WaitlistTableSchema(WaitlistTimestampedSchema):
email_id: UUID4 = Field(
description=EMAIL_ID_DESCRIPTION,
example=EMAIL_ID_EXAMPLE,
)

class Config:
extra = "forbid"

Expand Down
12 changes: 12 additions & 0 deletions tests/integration/test_basket_waitlist_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def fetch_created():

contact_details = fetch_created()
assert contact_details["newsletters"] == []
del contact_details["waitlists"][0]["create_timestamp"]
del contact_details["waitlists"][0]["update_timestamp"]
assert contact_details["waitlists"] == [
{
"name": "vpn",
Expand Down Expand Up @@ -163,6 +165,8 @@ def fetch_created():
# Request the full contact details again.
contact_details = ctms_fetch(email, ctms_headers)
assert contact_details["newsletters"] == []
del contact_details["waitlists"][0]["create_timestamp"]
del contact_details["waitlists"][0]["update_timestamp"]
assert contact_details["waitlists"] == [
{
"name": "vpn",
Expand Down Expand Up @@ -222,6 +226,8 @@ def fetch_created():
contact_details = fetch_created()

# 3. CTMS should show both formats (legacy `relay_waitlist` field, and entry in `waitlists` list)
del contact_details["waitlists"][0]["create_timestamp"]
del contact_details["waitlists"][0]["update_timestamp"]
assert contact_details["waitlists"] == [
{
"name": "relay",
Expand Down Expand Up @@ -256,6 +262,10 @@ def check_subscribed():

contact_details = check_subscribed()
assert contact_details["newsletters"] == []
del contact_details["waitlists"][0]["create_timestamp"]
del contact_details["waitlists"][0]["update_timestamp"]
del contact_details["waitlists"][1]["create_timestamp"]
del contact_details["waitlists"][1]["update_timestamp"]
assert contact_details["waitlists"] == [
{
"name": "relay",
Expand Down Expand Up @@ -298,6 +308,8 @@ def check_unsubscribed():
contact_details = check_unsubscribed()
# And only one newsletter subscribed.
assert contact_details["newsletters"] == []
del contact_details["waitlists"][0]["create_timestamp"]
del contact_details["waitlists"][0]["update_timestamp"]
assert contact_details["waitlists"] == [
{
"fields": {"geo": "es"},
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/routers/contacts/test_api_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def test_get_ctms_for_minimal_contact(client, dbsession, email_factory):
"source": newsletter.source,
"subscribed": newsletter.subscribed,
"unsub_reason": newsletter.unsub_reason,
"create_timestamp": newsletter.create_timestamp.isoformat(),
"update_timestamp": newsletter.update_timestamp.isoformat(),
}
],
"status": "ok",
Expand Down Expand Up @@ -133,6 +135,8 @@ def test_get_ctms_for_maximal_contact(client, maximal_contact):
"source": "https://www.mozilla.org/en-US/contribute/studentambassadors/",
"subscribed": False,
"unsub_reason": "Graduated, don't have time for FSA",
"create_timestamp": "2010-01-01T08:04:00+00:00",
"update_timestamp": "2020-01-28T14:50:00+00:00",
},
{
"format": "T",
Expand All @@ -141,6 +145,8 @@ def test_get_ctms_for_maximal_contact(client, maximal_contact):
"source": "https://commonvoice.mozilla.org/fr",
"subscribed": True,
"unsub_reason": None,
"create_timestamp": "2010-01-01T08:04:00+00:00",
"update_timestamp": "2020-01-28T14:50:00+00:00",
},
{
"format": "H",
Expand All @@ -149,6 +155,8 @@ def test_get_ctms_for_maximal_contact(client, maximal_contact):
"source": "https://www.mozilla.org/fr/firefox/accounts/",
"subscribed": False,
"unsub_reason": "done with this mailing list",
"create_timestamp": "2010-01-01T08:04:00+00:00",
"update_timestamp": "2020-01-28T14:50:00+00:00",
},
{
"format": "H",
Expand All @@ -157,6 +165,8 @@ def test_get_ctms_for_maximal_contact(client, maximal_contact):
"source": None,
"subscribed": True,
"unsub_reason": None,
"create_timestamp": "2010-01-01T08:04:00+00:00",
"update_timestamp": "2020-01-28T14:50:00+00:00",
},
{
"format": "H",
Expand All @@ -165,6 +175,8 @@ def test_get_ctms_for_maximal_contact(client, maximal_contact):
"source": None,
"subscribed": True,
"unsub_reason": None,
"create_timestamp": "2010-01-01T08:04:00+00:00",
"update_timestamp": "2020-01-28T14:50:00+00:00",
},
{
"format": "H",
Expand All @@ -173,6 +185,8 @@ def test_get_ctms_for_maximal_contact(client, maximal_contact):
"source": None,
"subscribed": True,
"unsub_reason": None,
"create_timestamp": "2010-01-01T08:04:00+00:00",
"update_timestamp": "2020-01-28T14:50:00+00:00",
},
{
"format": "H",
Expand All @@ -181,6 +195,8 @@ def test_get_ctms_for_maximal_contact(client, maximal_contact):
"source": None,
"subscribed": True,
"unsub_reason": None,
"create_timestamp": "2010-01-01T08:04:00+00:00",
"update_timestamp": "2020-01-28T14:50:00+00:00",
},
],
"status": "ok",
Expand All @@ -193,27 +209,35 @@ def test_get_ctms_for_maximal_contact(client, maximal_contact):
"source": "https://a-software.mozilla.org/",
"subscribed": True,
"unsub_reason": None,
"create_timestamp": "2010-01-01T08:04:00+00:00",
"update_timestamp": "2020-01-28T14:50:00+00:00",
},
{
"fields": {"geo": "cn"},
"name": "relay",
"source": None,
"subscribed": True,
"unsub_reason": None,
"create_timestamp": "2010-01-01T08:04:00+00:00",
"update_timestamp": "2020-01-28T14:50:00+00:00",
},
{
"fields": {"geo": "fr", "platform": "win64"},
"name": "super-product",
"source": "https://super-product.mozilla.org/",
"subscribed": True,
"unsub_reason": None,
"create_timestamp": "2010-01-01T08:04:00+00:00",
"update_timestamp": "2020-01-28T14:50:00+00:00",
},
{
"fields": {"geo": "ca", "platform": "windows,android"},
"name": "vpn",
"source": None,
"subscribed": True,
"unsub_reason": None,
"create_timestamp": "2010-01-01T08:04:00+00:00",
"update_timestamp": "2020-01-28T14:50:00+00:00",
},
],
}
Expand Down Expand Up @@ -277,6 +301,8 @@ def test_get_ctms_for_api_example(client, example_contact):
"source": None,
"subscribed": True,
"unsub_reason": None,
"create_timestamp": "2020-12-05T19:21:50.908000+00:00",
"update_timestamp": "2021-02-04T15:36:57.511000+00:00",
},
{
"format": "H",
Expand All @@ -285,6 +311,8 @@ def test_get_ctms_for_api_example(client, example_contact):
"source": None,
"subscribed": True,
"unsub_reason": None,
"create_timestamp": "2020-12-05T19:21:50.908000+00:00",
"update_timestamp": "2021-02-04T15:36:57.511000+00:00",
},
],
"status": "ok",
Expand All @@ -297,20 +325,26 @@ def test_get_ctms_for_api_example(client, example_contact):
"source": None,
"subscribed": True,
"unsub_reason": None,
"create_timestamp": "2020-12-05T19:21:50.908000+00:00",
"update_timestamp": "2021-02-04T15:36:57.511000+00:00",
},
{
"fields": {"geo": "fr"},
"name": "relay",
"source": None,
"subscribed": True,
"unsub_reason": None,
"create_timestamp": "2020-12-05T19:21:50.908000+00:00",
"update_timestamp": "2021-02-04T15:36:57.511000+00:00",
},
{
"fields": {"geo": "fr", "platform": "ios,mac"},
"name": "vpn",
"source": None,
"subscribed": True,
"unsub_reason": None,
"create_timestamp": "2020-12-05T19:21:50.908000+00:00",
"update_timestamp": "2021-02-04T15:36:57.511000+00:00",
},
],
}
Expand Down
Loading

0 comments on commit ce19805

Please sign in to comment.