Skip to content

Commit

Permalink
Fix #802: clarify sync behaviour in test (#805)
Browse files Browse the repository at this point in the history
In #804 we fixed the way boolean fields are synced on the main table. This PR is a complementary specification about the way boolean related to FxA and AMO are synced.
  • Loading branch information
leplatrem authored Sep 1, 2023
1 parent b2a5e32 commit b089a61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
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.
# 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

0 comments on commit b089a61

Please sign in to comment.