Skip to content

Commit 904a8e4

Browse files
authored
Merge pull request #351 from mozilla-it/fix-350-ingest-new-deleted-customer
Handle POST of new deleted customer
2 parents fccce97 + 88757b1 commit 904a8e4

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

ctms/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
app = FastAPI(
8888
title="ConTact Management System (CTMS)",
8989
description="CTMS API (work in progress)",
90-
version="1.1.2",
90+
version="1.1.3",
9191
)
9292
SessionLocal = None
9393
METRICS_REGISTRY = CollectorRegistry()
@@ -961,7 +961,7 @@ def _process_stripe_object(
961961
status_code=409, detail="Deadlock or other issue, try again"
962962
) from e
963963

964-
email_id = obj.get_email_id()
964+
email_id = obj.get_email_id() if obj else None
965965
if data["object"] == "customer" and re_trace_email.match(data.get("email", "")):
966966
trace_email = data["email"]
967967
else:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.masonry.api"
44

55
[tool.poetry]
66
name = "ctms"
7-
version = "1.1.2"
7+
version = "1.1.3"
88
description = "Contact Management System API"
99
authors = [
1010
"Brian Stack <bstack@mozilla.com>",

tests/unit/test_api_stripe.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from ctms.app import app, get_pubsub_claim
1313
from ctms.models import PendingAcousticRecord
14+
from tests.unit.sample_data import fake_stripe_id
1415
from tests.unit.test_ingest_stripe import (
1516
stripe_customer_data,
1617
stripe_invoice_data,
@@ -137,6 +138,21 @@ def test_api_post_conflicting_fxa_id(dbsession, client, contact_with_stripe_cust
137138
assert log["fxa_id_conflict"] == data["description"]
138139

139140

141+
def test_api_post_deleted_new_customer(dbsession, client):
142+
"""A new customer who starts out deleted is skipped."""
143+
stripe_id = fake_stripe_id("cus", "new_but_deleted")
144+
data = {"deleted": True, "id": stripe_id, "object": "customer"}
145+
with capture_logs() as caplog:
146+
resp = client.post("/stripe", json=data)
147+
assert resp.status_code == 200
148+
assert resp.json() == {"status": "OK"}
149+
assert len(caplog) == 1
150+
log = caplog[0]
151+
assert log["ingest_actions"] == {
152+
"skipped": [f"customer:{stripe_id}"],
153+
}
154+
155+
140156
def test_api_post_stripe_from_pubsub_customer(
141157
dbsession, pubsub_client, example_contact
142158
):
@@ -304,3 +320,18 @@ def test_api_post_pubsub_conflicting_fxa_id(
304320
"deleted": [f"customer:{old_id}"],
305321
}
306322
assert log["fxa_id_conflict"] == data["description"]
323+
324+
325+
def test_api_post_stripe_from_pubsub_deleted_new_customer(dbsession, pubsub_client):
326+
"""A new customer who starts out deleted is skipped."""
327+
stripe_id = fake_stripe_id("cus", "new_but_deleted")
328+
data = {"deleted": True, "id": stripe_id, "object": "customer"}
329+
with capture_logs() as caplog:
330+
resp = pubsub_client.post("/stripe_from_pubsub", json=pubsub_wrap(data))
331+
assert resp.status_code == 200
332+
assert resp.json() == {"status": "OK", "count": 1}
333+
assert len(caplog) == 1
334+
log = caplog[0]
335+
assert log["ingest_actions"] == {
336+
"skipped": [f"customer:{stripe_id}"],
337+
}

0 commit comments

Comments
 (0)