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

Fix #802: clarify sync behaviour of boolean fields for relations #805

Merged
merged 1 commit into from
Sep 1, 2023
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
6 changes: 4 additions & 2 deletions ctms/acoustic_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,10 @@ def _main_table_converter(self, contact, main_fields):
)
# TODO: These are boolean values on our models, but in Acoustic
# they are configured as text values where we record `True`
# and `False` as `1` and `0` respectively. We should
# configure Acoustic to use a boolean column for this data.
# and `False` as `1` and `0` respectively.
# Note that `amo_*` and `fxa_*` fields are omitted when contact does not
# have these relations.
leplatrem marked this conversation as resolved.
Show resolved Hide resolved
# We should configure Acoustic to use a boolean column for this data.
# This is being tracked in https://github.com/mozilla-it/ctms-api/issues/803
if acoustic_field_name in (
"double_opt_in",
Expand Down
23 changes: 16 additions & 7 deletions tests/unit/test_acoustic_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ def test_ctms_to_acoustic_no_product(
assert len(products) == 0, f"{i + 1}/3: no products in contact."


@pytest.mark.parametrize("model_value,acoustic_value", [(False, "0"), (True, "1")])
@pytest.mark.parametrize(
"model_value,acoustic_value,with_relations",
[(False, "0", True), (True, "1", True), (False, "0", False), (True, "1", False)],
)
def test_ctms_to_acoustic_special_booleans(
dbsession,
base_ctms_acoustic_service,
Expand All @@ -91,15 +94,17 @@ def test_ctms_to_acoustic_special_booleans(
acoustic_newsletters_mapping,
model_value,
acoustic_value,
with_relations,
):
email = email_factory(
double_opt_in=model_value,
has_opted_out_of_email=model_value,
fxa=True,
amo=True,
amo__email_opt_in=model_value,
fxa__account_deleted=model_value,
fxa=with_relations,
amo=with_relations,
)
if with_relations:
email.amo.email_opt_in = model_value
email.fxa.account_deleted = model_value
dbsession.commit()

contact = ContactSchema.from_email(email)
Expand All @@ -113,8 +118,12 @@ def test_ctms_to_acoustic_special_booleans(

assert main["double_opt_in"] == acoustic_value
assert main["has_opted_out_of_email"] == acoustic_value
assert main["fxa_account_deleted"] == acoustic_value
assert main["amo_email_opt_in"] == acoustic_value
if with_relations:
assert main["fxa_account_deleted"] == acoustic_value
assert main["amo_email_opt_in"] == acoustic_value
else:
assert "fxa_account_deleted" not in main
assert "amo_email_opt_in" not in main


def test_ctms_to_acoustic_newsletters(
Expand Down