Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
172 commits
Select commit Hold shift + click to select a range
90eea2c
Add Braze class stub
jacobpenny Oct 15, 2025
cfd7efe
Update views.fxa_callback with use_braze_backend option
jacobpenny Oct 15, 2025
6107ab6
Update views.confirm with use_braze_backend option
jacobpenny Oct 15, 2025
d1a4de1
add vendor_id_to_slug function (based on existing slug_to_vendor_id)
clara-campos Oct 16, 2025
9209e61
add from_vendor to braze class
clara-campos Oct 16, 2025
2c37c84
fix comment
clara-campos Oct 16, 2025
4d58807
Update views and tasks to handle either CTMS or Braze backend
jacobpenny Oct 16, 2025
60a8f25
Improve comment about token/email pre-generation
jacobpenny Oct 16, 2025
a8d11bb
Merge branch 'use-braze-backend' of github.com:jacobpenny/basket into…
clara-campos Oct 16, 2025
97dd600
remove function
clara-campos Oct 16, 2025
e40a9d8
implement braze.get, modify from_vendor accordingly
clara-campos Oct 16, 2025
fffb45a
address comments, fix typos, remove newsletter_v1 and waitlist_v1 (de…
clara-campos Oct 17, 2025
007c628
use boolean value
clara-campos Oct 17, 2025
496f529
add fxa fields
clara-campos Oct 17, 2025
e458fee
fix newsletters field
clara-campos Oct 17, 2025
31bfbac
Improve log
clara-campos Oct 17, 2025
55647bc
fix bug
clara-campos Oct 17, 2025
4a526f5
remove unnecessary return
clara-campos Oct 17, 2025
427339f
add first draft of to_vendor
clara-campos Oct 17, 2025
352bb34
add country and language processing
clara-campos Oct 17, 2025
22df65f
Create command to push to fxa queue
bluewave41 Oct 20, 2025
1bb3ef0
refactor to_vendor, implement braze add
clara-campos Oct 20, 2025
e745374
Migration script for UUID.
stephendherrera Oct 20, 2025
955be7e
Fix some JSON parsing issues
bluewave41 Oct 20, 2025
42234e9
Merge pull request #1 from clara-campos/vendor-parsing
jacobpenny Oct 21, 2025
a13668e
Update dsar delete with use_braze_backend option
jacobpenny Oct 21, 2025
1d9aaa1
Remove unused setting
jacobpenny Oct 21, 2025
b28a3f6
handle billable attributes
clara-campos Oct 21, 2025
99f36fd
implement braze.update
clara-campos Oct 21, 2025
f2e87a2
add braze_add_or_update
clara-campos Oct 21, 2025
65aab7e
fix conditions
clara-campos Oct 21, 2025
7cc12b6
Update test_view_admin_dsar.py
jacobpenny Oct 22, 2025
afc50cb
Update test_update_user_task.py
jacobpenny Oct 22, 2025
3832c73
Update test_views and test_update_user_task
jacobpenny Oct 22, 2025
e4ad92b
Update test_update_users.py and test_upsert_user.py
jacobpenny Oct 22, 2025
96c7fa2
Update test_braze.py
jacobpenny Oct 22, 2025
87341e7
Merge pull request #2 from clara-campos/vendor-parsing
jacobpenny Oct 22, 2025
2591590
JSON load body
bluewave41 Oct 22, 2025
faa0a72
Remove google-cloud-storage, pandas, and pyarrow from dev.in
jacobpenny Oct 22, 2025
5ed64f8
Upgrade django-ninja to 1.4.5
jacobpenny Oct 22, 2025
e6e2d55
Compile requirements
jacobpenny Oct 22, 2025
a5f1c8a
Don't attempt to create new contacts on unsubscribe or set
jacobpenny Oct 23, 2025
3064dc3
Check that request token matches user's token
jacobpenny Oct 23, 2025
725092c
Make test_rq_utils work with non-docker redis
jacobpenny Oct 23, 2025
12c04c7
Update api routes to optionally use Braze as backend
jacobpenny Oct 23, 2025
ba58978
Merge pull request #3 from jacobpenny/update-api-routes
jacobpenny Oct 23, 2025
c4f1eb2
Merge pull request #11 from jacobpenny/unsubscribe-fix
clara-campos Oct 23, 2025
8bb9849
Merge remote-tracking branch 'upstream/braze-external-id-migrator' in…
jacobpenny Oct 24, 2025
8b4df2c
Merge remote-tracking branch 'silverorange/main' into dev
jacobpenny Oct 24, 2025
f3726f9
Update migrator braze interface usage
jacobpenny Oct 24, 2025
872d651
Merge remote-tracking branch 'origin/use-braze-backend' into development
jacobpenny Oct 24, 2025
dc14268
add interface method tests
clara-campos Oct 24, 2025
be6f6cb
fix broken conditional
clara-campos Oct 27, 2025
af9c96f
add tests for to_vendor and from_vendor
clara-campos Oct 27, 2025
b5aad31
add default just in case
clara-campos Oct 27, 2025
0580930
add braze get test
clara-campos Oct 27, 2025
33243a5
add request assertions to braze.get test
clara-campos Oct 27, 2025
aab1073
Update FXA functions
bluewave41 Oct 27, 2025
519fe77
Add more braze feature flags
bluewave41 Oct 27, 2025
2868082
fix broken syntax
clara-campos Oct 28, 2025
7e35252
Fix call to track_user in send_tx_message
jacobpenny Oct 28, 2025
bd0fd94
fix test params, add tests for braze add and update
clara-campos Oct 28, 2025
78c6712
return email id with braze.add
clara-campos Oct 28, 2025
89b5485
update braze.add test with missing data fields and return statement
clara-campos Oct 28, 2025
e9982d9
remove dictionary override
clara-campos Oct 28, 2025
a72d16f
edit braze.delete to avoid grabbing unnecessary data
clara-campos Oct 28, 2025
9a1d810
add test for braze.delete
clara-campos Oct 28, 2025
e9f05d7
Update tests to use braze.interface
jacobpenny Oct 29, 2025
8dcbb40
Fix closure issue in subscribe handler
jacobpenny Oct 29, 2025
7d20c9e
add todo
clara-campos Oct 29, 2025
4c29c19
fix mock
clara-campos Oct 29, 2025
0b792a7
Merge pull request #15 from clara-campos/braze-tests
jacobpenny Oct 29, 2025
97b9267
Add untested fxa alias in braze add
bluewave41 Oct 29, 2025
b4a1a61
Use none for default endpoint
bluewave41 Oct 29, 2025
0d4fdee
Merge pull request #16 from jacobpenny/fix-subscribe-handler
clara-campos Oct 29, 2025
8ce86ac
Merge pull request #10 from bluewave41/fxa_command
jacobpenny Oct 29, 2025
f614c45
Merge remote-tracking branch 'silverorange/main' into development
jacobpenny Oct 29, 2025
4bfb7a7
Merge branch 'fxa_update' of github.com:bluewave41/basket into fxa_up…
clara-campos Oct 29, 2025
5ac3a4d
default to empty string (None errors out)
clara-campos Oct 29, 2025
6c7db8f
remove email alias, add fxa_id
clara-campos Oct 29, 2025
61f3ade
remove custom attributes from to_vendor, no longer necessary
clara-campos Oct 29, 2025
556cec2
fix bug
clara-campos Oct 29, 2025
ec58f1a
update tests
clara-campos Oct 29, 2025
0f28822
Merge branch 'main' into fxa_update
bluewave41 Oct 29, 2025
1a64b09
Merge remote-tracking branch 'upstream/development' into fxa_update
bluewave41 Oct 29, 2025
32309e0
Merge branch 'fxa_update' of github.com:bluewave41/basket into fxa_up…
clara-campos Oct 30, 2025
0c84bb9
Fallback to CTMS when looking up by token and no user found
jacobpenny Oct 30, 2025
9e18c2e
Merge pull request #17 from jacobpenny/token-migration-updates
clara-campos Oct 30, 2025
9d5277e
Merge branch 'development' of github.com:silverorange/basket into fxa…
clara-campos Oct 30, 2025
a4bd01b
remove outdated comment
clara-campos Oct 30, 2025
402ee69
update external id logic, add fxa id alias call
clara-campos Oct 30, 2025
089496d
add alias step to braze.update
clara-campos Oct 30, 2025
a991121
add get_fxa_id_from_aliases method, return fxa_id with braze.delete, …
clara-campos Oct 30, 2025
a1bd545
fix has_fxa for braze users
clara-campos Oct 30, 2025
7d4ef23
handle empty strings
clara-campos Oct 30, 2025
cec8515
remove unnecessary flag
clara-campos Oct 30, 2025
90b562d
fix has_fxa based on fxa_id update
clara-campos Oct 30, 2025
18dd116
fix typo
clara-campos Oct 30, 2025
ddaac4e
add fxa_id to braze get and export_users
clara-campos Oct 30, 2025
64d9661
remove braze.update_by_token
clara-campos Oct 30, 2025
166a536
remove pre_generated_email_id, that settings flag will only be true p…
clara-campos Oct 30, 2025
3718b14
add update_by_fxa_id method, delete braze.update_by_alt_id
clara-campos Oct 30, 2025
a87be70
don't call add_fxa_id_alias if there's no external id
clara-campos Oct 30, 2025
cebd9ff
fix external id
clara-campos Oct 30, 2025
0e5625f
fix language comparison
clara-campos Oct 30, 2025
fe80c65
fix export users and fxa_id lookup
clara-campos Oct 30, 2025
7265e93
add conditional
clara-campos Oct 30, 2025
e624454
Pre-generate tokens/email_ids for fxa tasks
jacobpenny Oct 31, 2025
2af9512
Fix test_tasks and test_upsert_user tests
jacobpenny Oct 31, 2025
d18c88d
Merge pull request #1 from jacobpenny/fxa-update-jp-1
clara-campos Oct 31, 2025
e772ca0
Fix braze tests
jacobpenny Oct 31, 2025
f10ccce
Migrate email_id to token after user creation when in parallel mode
jacobpenny Nov 3, 2025
c42681c
Merge branch 'fxa_update' of github.com:clara-campos/basket into fxa_…
clara-campos Nov 3, 2025
b5c5c45
handle missing external id in to_vendor
clara-campos Nov 3, 2025
0db5ec2
Remove uuid generation in braze.add
jacobpenny Nov 3, 2025
c7336a3
Merge branch 'fxa-update-jp-2' of github.com:jacobpenny/basket into f…
clara-campos Nov 3, 2025
8966b40
throw error in to_vendor if external_id is missing
clara-campos Nov 3, 2025
e683eed
Remove print
jacobpenny Nov 3, 2025
8e1da97
change error type
clara-campos Nov 3, 2025
dabc9c0
update failing tests, add external id to_vendor tests
clara-campos Nov 3, 2025
4ebae40
add fxa_deleted
clara-campos Nov 3, 2025
cdd6a9f
Merge pull request #4 from clara-campos/fxa_update
jacobpenny Nov 4, 2025
25e196a
add test for fxa id alias
clara-campos Nov 4, 2025
ec69d56
add missing time wrapper for fxa_created_at, remove incorrectly mocke…
clara-campos Nov 5, 2025
cd53521
add tests for update_by_fxa_id
clara-campos Nov 5, 2025
ff2b29e
add fxa_deleted to a to_vendor test
clara-campos Nov 5, 2025
680a303
add tests for followup alias calls in braze add and update
clara-campos Nov 5, 2025
39b6503
return updated external_id if it's been migrated
clara-campos Nov 5, 2025
836f640
fix incorrect urls, add test for braze add with id migration
clara-campos Nov 5, 2025
bf5849e
Merge pull request #5 from clara-campos/fxa_update
jacobpenny Nov 5, 2025
80d25b8
Remove email alias from export call
jacobpenny Nov 5, 2025
9749243
Merge pull request #19 from jacobpenny/fxa-update-jp-2
jacobpenny Nov 5, 2025
2d5b43d
implement braze dsar unsubscribe
clara-campos Nov 5, 2025
6228de8
add settings overrides to existing CTMS tests
clara-campos Nov 5, 2025
b1cb0f1
Merge branch 'development' of github.com:silverorange/basket into dsa…
clara-campos Nov 5, 2025
4a883f6
add missing setting overrides
clara-campos Nov 5, 2025
d9db421
Remove unnecessary overrides from test_braze
jacobpenny Nov 6, 2025
2b73136
Merge pull request #21 from jacobpenny/remove-unnecessary-overrides
clara-campos Nov 6, 2025
feedf64
Merge branch 'development' of github.com:silverorange/basket into dsa…
clara-campos Nov 6, 2025
bd69bf9
remove false settings overrides (no longer necessary)
clara-campos Nov 6, 2025
cf3fe41
add delete tests for braze
clara-campos Nov 6, 2025
e2b553b
Add fxa_id alias to migration command
jacobpenny Nov 6, 2025
74bb4ce
Halve sleep time in migration script to reflect new 2000/min limit
jacobpenny Nov 6, 2025
9716fb1
Remove unnecessary TODO
jacobpenny Nov 6, 2025
b333442
add DSAR unsub braze tests
clara-campos Nov 6, 2025
45fcb22
remove title reference to ctms
clara-campos Nov 6, 2025
4fa000a
modify DSAR get info to handle both braze and ctms formats
clara-campos Nov 6, 2025
4d25b02
Update unsub command
bluewave41 Nov 7, 2025
b30b362
Add to from_vendor
bluewave41 Nov 7, 2025
b749e6d
include vendor information
clara-campos Nov 7, 2025
2d3324a
add braze tests for dsar info view
clara-campos Nov 7, 2025
521db95
Merge pull request #22 from jacobpenny/add-fxa-to-migration-command
bluewave41 Nov 7, 2025
a86e534
add ctms fallback on user not found, update tests
clara-campos Nov 7, 2025
2bb65b5
Fix small logic issues
bluewave41 Nov 8, 2025
f416b81
Merge pull request #20 from clara-campos/dsar-admin-braze
jacobpenny Nov 10, 2025
729bf45
Fixtests
bluewave41 Nov 10, 2025
6e6ee9b
Merge pull request #23 from bluewave41/update_unsub_command
jacobpenny Nov 10, 2025
2ce89df
Add Braze-CTMS shim to support token/fxa_id lookups prior to migrations
jacobpenny Nov 12, 2025
6670d0c
Remove unnecessary fallbacks
jacobpenny Nov 12, 2025
f7f0c87
Merge pull request #24 from jacobpenny/braze-ctms-shim
clara-campos Nov 12, 2025
24f7d34
Create a second braze instance to be used for tx emails only
jacobpenny Nov 13, 2025
99c68a8
Merge pull request #26 from jacobpenny/two-api-keys
clara-campos Nov 13, 2025
23bc15d
Rename braze api key settings
jacobpenny Nov 14, 2025
37308a2
Tweak user not found text in admin
jacobpenny Nov 14, 2025
9ca0f03
Add docstrings to Braze methods
jacobpenny Nov 14, 2025
96c7954
Merge branch 'main' into development
jacobpenny Nov 14, 2025
cc34154
Update ctms specific comment
jacobpenny Nov 14, 2025
9e51e71
Remove cTms references in docs
jacobpenny Nov 14, 2025
921ace7
Adjust comment
clara-campos Nov 14, 2025
421523f
Merge pull request #27 from clara-campos/minor-get-doc-fix
jacobpenny Nov 14, 2025
a52a55e
Add missing sentry error parameters
bluewave41 Nov 14, 2025
adb0ead
Merge pull request #28 from bluewave41/fix_sentry_handlers
clara-campos Nov 14, 2025
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
198 changes: 121 additions & 77 deletions basket/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,22 @@
import sentry_sdk

from basket.base.forms import EmailForm, EmailListForm
from basket.news.backends.braze import braze
from basket.news.backends.ctms import (
CTMSNotFoundByEmailError,
CTMSNotFoundByEmailIDError,
ctms,
)
from basket.news.newsletters import newsletter_obj
from basket.news.backends.braze import BrazeUserNotFoundByEmailError, braze
from basket.news.backends.ctms import CTMSNotFoundByEmailError, CTMSNotFoundByEmailIDError, ctms, from_vendor
from basket.news.newsletters import slug_to_vendor_id

log = logging.getLogger(__name__)


def get_newsletter_names(ctms_contact):
def get_newsletter_names(contact):
names = []
newsletters = ctms_contact["newsletters"]
for nl in newsletters:
if not nl["subscribed"]:
continue

nl_slug = nl["name"]
nl_obj = newsletter_obj(nl_slug)
if nl_obj:
nl_name = nl_obj.title
else:
nl_name = ""
names.append(f"{nl_name} (id: {nl_slug})")

newsletters = contact["newsletters"]
for newsletter_slug in newsletters:
try:
newsletter_id = slug_to_vendor_id(newsletter_slug)
names.append(f"{newsletter_slug} (id: {newsletter_id})")
except KeyError:
pass
return names


Expand Down Expand Up @@ -104,27 +94,55 @@ def get_app_list(self, request, app_label=None):
def dsar_info_view(self, request):
form = EmailForm()
context = {
"title": "DSAR: Fetch CTMS User Info by Email Address",
"title": "DSAR: Fetch User Info by Email Address",
}
if request.method == "POST":
form = EmailForm(request.POST)
if form.is_valid():
email = form.cleaned_data["email"]
try:
contact = ctms.interface.get_by_alternate_id(primary_email=email)
except CTMSNotFoundByEmailError:
contact = None
else:
# response could be 200 with an empty list
if contact:
contact = contact[0]
context["dsar_contact_pretty"] = json.dumps(contact, indent=2, sort_keys=True)
context["newsletter_names"] = get_newsletter_names(contact)
else:

def handler(email, use_braze_backend=False, fallback_to_ctms=False):
context["vendor"] = "Braze" if use_braze_backend else "CTMS"
try:
if use_braze_backend:
contact = braze.get(email=email)
if not contact and fallback_to_ctms:
context["vendor"] = "CTMS"
contact = ctms.interface.get_by_alternate_id(primary_email=email)
else:
contact = ctms.interface.get_by_alternate_id(primary_email=email)
except CTMSNotFoundByEmailError:
contact = None
else:
# response could be 200 with an empty list
if contact:
if context["vendor"] == "Braze":
context["dsar_contact_pretty"] = json.dumps(contact, indent=2, sort_keys=True)
else:
raw_contact = contact[0]
contact = from_vendor(raw_contact)
context["dsar_contact_pretty"] = json.dumps(raw_contact, indent=2, sort_keys=True)

context["dsar_contact"] = contact
context["dsar_submitted"] = True
context["newsletter_names"] = get_newsletter_names(contact)
else:
contact = None

if not contact and fallback_to_ctms:
context["vendor"] = "CTMS or Braze"

context["dsar_contact"] = contact
context["dsar_submitted"] = True

if settings.BRAZE_READ_WITH_FALLBACK_ENABLE:
try:
handler(email, use_braze_backend=True, fallback_to_ctms=True)
except Exception as e:
sentry_sdk.capture_exception(e)
handler(email, use_braze_backend=False)
elif settings.BRAZE_ONLY_READ_ENABLE:
handler(email, use_braze_backend=True)
else:
handler(email, use_braze_backend=False)

context["dsar_form"] = form
# adds default django admin context so sidebar shows etc.
Expand Down Expand Up @@ -152,28 +170,47 @@ def dsar_unsub_view(self, request):
"waitlists": "UNSUBSCRIBE",
}

# Process the emails.
for email in emails:
contact = ctms.get(email=email)
if contact:
email_id = contact["email_id"]
try:
ctms.interface.patch_by_email_id(email_id, update_data)
except CTMSNotFoundByEmailIDError:
# should never reach here, but best to catch it anyway
output.append(f"{email} not found in CTMS")
def handler(emails, use_braze_backend=False):
# Process the emails.
for email in emails:
if use_braze_backend:
contact = braze.get(email=email)
else:
output.append(f"UNSUBSCRIBED {email} (ctms id: {email_id}).")
else:
output.append(f"{email} not found in CTMS")
contact = ctms.get(email=email)
if contact:
email_id = contact["email_id"]
try:
if use_braze_backend:
braze.update(contact, {"optout": True})
else:
ctms.interface.patch_by_email_id(email_id, update_data)
except CTMSNotFoundByEmailIDError:
# should never reach here, but best to catch it anyway
output.append(f"{email} not found in CTMS")
else:
output.append(f"UNSUBSCRIBED {email} ({'Braze external id:' if use_braze_backend else 'ctms id:'} {email_id}).")
else:
output.append(f"{email} not found in {'Braze' if use_braze_backend else 'CTMS'}")

if settings.BRAZE_PARALLEL_WRITE_ENABLE:
try:
handler(emails, use_braze_backend=True)
except Exception as e:
sentry_sdk.capture_exception(e)

handler(emails, use_braze_backend=False)
elif settings.BRAZE_ONLY_WRITE_ENABLE:
handler(emails, use_braze_backend=True)
else:
handler(emails, use_braze_backend=False)

output = "\n".join(output)

# Reset the form
form = EmailListForm()

context = {
"title": "DSAR: Unsubscribe CTMS Users by Email Address",
"title": "DSAR: Unsubscribe Users by Email Address",
"dsar_form": form,
"dsar_output": output,
}
Expand All @@ -192,43 +229,50 @@ def dsar_delete_view(self, request):
emails = form.cleaned_data["emails"]
output = []

# Process the emails.
for email in emails:
try:
data = ctms.delete(email)
except CTMSNotFoundByEmailError:
output.append(f"{email} not found in CTMS")
else:
for contact in data:
email_id = contact["email_id"]
msg = f"DELETED {email} (ctms id: {email_id})."
if contact["fxa_id"]:
msg += " fxa: YES."
if contact["mofo_contact_id"]:
msg += " mofo: YES."
output.append(msg)

if settings.BRAZE_DELETE_USER_ENABLE:
def handler(emails, use_braze_backend=False):
# Process the emails.
for email in emails:
try:
# Fetch braze_ids instead of external_ids so we also delete
# alias-only profiles.
response = braze.export_users(email, ["braze_id"])
if response and response.get("users"):
braze_ids = [user["braze_id"] for user in response["users"]]
braze.delete_users(braze_ids)
msg = f"DELETED {email} (braze ids: {', '.join(braze_ids)})."
if use_braze_backend:
data = braze.delete(email)
else:
data = ctms.delete(email)
except CTMSNotFoundByEmailError:
output.append(f"{email} not found in CTMS")
except BrazeUserNotFoundByEmailError:
output.append(f"{email} not found in Braze")
else:
for contact in data:
email_id = contact["email_id"]
if use_braze_backend:
msg = f"DELETED {email} from Braze (external_id: {email_id})."
else:
msg = f"DELETED {email} from CTMS (ctms id: {email_id})."
if contact.get("fxa_id"):
msg += " fxa: YES."
if contact.get("mofo_contact_id"):
msg += " mofo: YES."
output.append(msg)
except Exception as e:
sentry_sdk.capture_exception()
log.error(f"Braze user deletion error: {e}")

if settings.BRAZE_PARALLEL_WRITE_ENABLE:
try:
handler(emails, use_braze_backend=True)
except Exception as e:
sentry_sdk.capture_exception(e)

handler(emails, use_braze_backend=False)
elif settings.BRAZE_ONLY_WRITE_ENABLE:
handler(emails, use_braze_backend=True)
else:
handler(emails, use_braze_backend=False)

output = "\n".join(output)

# Reset the form
form = EmailListForm()

context = {
"title": "DSAR: Delete CTMS Data by Email Address",
"title": "DSAR: Delete Data by Email Address",
"dsar_form": form,
"dsar_output": output,
}
Expand Down
30 changes: 15 additions & 15 deletions basket/base/templates/admin/dsar-info.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,53 +69,53 @@ <h2>{{ dsar_form.email.label_tag }}</h2>

<div class="output-container">
{% if dsar_contact %}
<h2>User Info:</h2>
<h2>User Info (from {{ vendor }}):</h2>
<table>
<tr>
<th>Primary Email</th>
<td>{{ dsar_contact.email.primary_email }}</td>
<td>{{ dsar_contact.email }}</td>
</tr>
<tr>
<th>Basket Token</th>
<td><a href="{{ settings.FXA_EMAIL_PREFS_URL }}/{{ dsar_contact.email.basket_token }}/" target="_blank" title="Open the user's Email Preferences">{{ dsar_contact.email.basket_token }}</a></td>
<td><a href="{{ settings.FXA_EMAIL_PREFS_URL }}/{{ dsar_contact.token }}/" target="_blank" title="Open the user's Email Preferences">{{ dsar_contact.token }}</a></td>
</tr>
{% if dsar_contact.email.first_name %}
{% if dsar_contact.first_name or dsar_contact.last_name %}
<tr>
<th>Name</th>
<td>{{ dsar_contact.email.first_name }} {{ dsar_contact.email.last_name }}</td>
<td>{% if dsar_contact.first_name %}{{ dsar_contact.first_name }}{% endif %}{% if dsar_contact.last_name %} {{ dsar_contact.last_name }}{% endif %}</td>
</tr>
{% endif %}
<tr>
<th>Language</th>
<td>{{ dsar_contact.email.email_lang }}</td>
<td>{{ dsar_contact.lang }}</td>
</tr>
{% if dsar_contact.email.mailing_country %}
{% if dsar_contact.country %}
<tr>
<th>Country</th>
<td>{{ dsar_contact.email.mailing_country }}</td>
<td>{{ dsar_contact.country }}</td>
</tr>
{% endif %}
<tr>
<th>FxA ID</th>
<td>{{ dsar_contact.fxa.fxa_id }}</td>
<td>{{ dsar_contact.fxa_id }}</td>
</tr>
{% if dsar_contact.fxa.primary_email %}
{% if dsar_contact.fxa_primary_email %}
<tr>
<th>FxA Primary Email</th>
<td>{{ dsar_contact.fxa.primary_email }}</td>
<td>{{ dsar_contact.fxa_primary_email }}</td>
</tr>
{% endif %}
<tr>
<th>MoFo Relevant?</th>
<td>{{ dsar_contact.mofo.mofo_relevant|yesno }}</td>
<td>{{ dsar_contact.mofo_relevant|yesno }}</td>
</tr>
<tr>
<th>Double Opt In?</th>
<td>{{ dsar_contact.email.double_opt_in|yesno }}</td>
<td>{{ dsar_contact.optin|yesno }}</td>
</tr>
<tr>
<th>Opt Out of All Email?</th>
<td>{{ dsar_contact.email.has_opted_out_of_email|yesno }}</td>
<td>{{ dsar_contact.optout|yesno }}</td>
</tr>
<tr>
<th>Subscriptions</th>
Expand All @@ -141,7 +141,7 @@ <h2>Raw Data:</h2>
<pre id="text-content" class="output-text">{{ dsar_contact_pretty }}</pre>
{% elif dsar_submitted %}
<h2>Not Found:</h2>
<pre id="text-content" class="output-text">User not found in CTMS</pre>
<pre id="text-content" class="output-text">User not found in {{ vendor }}</pre>
{% endif %}
</div>
</div>
Expand Down
14 changes: 11 additions & 3 deletions basket/base/tests/test_rq_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest.mock import patch
from urllib.parse import urlparse

from django.conf import settings
from django.test.utils import override_settings
Expand All @@ -19,6 +20,8 @@
from basket.news.models import FailedTask
from basket.news.utils import NewsletterException

default_rq_url = settings.RQ_URL


@pytest.mark.django_db
class TestRQUtils:
Expand Down Expand Up @@ -46,7 +49,7 @@ def test_rq_exponential_backoff_with_debug(self):
"""
assert rq_exponential_backoff() == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]

@override_settings(RQ_URL="redis://redis:6379/2")
@override_settings(RQ_URL=default_rq_url)
def test_get_redis_connection(self):
"""
Test that the get_redis_connection function returns a Redis connection with params we expect.
Expand All @@ -58,7 +61,12 @@ def test_get_redis_connection(self):
# Test with no URL argument, but with RQ_URL in the settings.
# Note: The RQ_URL being used also sets this back to the "default" for tests that follow.
connection = get_redis_connection(force=True)
assert connection.connection_pool.connection_kwargs == {"host": "redis", "port": 6379, "db": 2}
parsed_default_rq_url = urlparse(default_rq_url)
assert connection.connection_pool.connection_kwargs == {
"host": parsed_default_rq_url.hostname,
"port": parsed_default_rq_url.port,
"db": 2,
}

@override_settings(REDIS_URL=None, RQ_URL=None)
def test_get_redis_connection_none(self):
Expand All @@ -69,7 +77,7 @@ def test_get_redis_connection_none(self):
get_redis_connection(force=True)

# Set back to the "default" for tests that follow since the connection is cached in the module.
get_redis_connection("redis://redis:6379/2", force=True)
get_redis_connection(default_rq_url, force=True)

@override_settings(RQ_DEFAULT_QUEUE="")
def test_get_queue(self):
Expand Down
Loading