Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rjambrecic committed Nov 20, 2024
1 parent f0fbe6f commit 3ff40cc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 9 additions & 3 deletions mailchimp_api/processing/update_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _add_and_remove_tags(
mailchimp_service: MailchimpService,
list_id: str,
members_with_tags_df: pd.DataFrame,
) -> None:
) -> tuple[dict[str, list[str]], dict[str, list[str]]]:
add_tag_members, remove_tag_members = _create_add_and_remove_tags_dicts(
members_with_tags_df=members_with_tags_df,
)
Expand All @@ -86,8 +86,12 @@ def _add_and_remove_tags(
status="inactive",
)

return add_tag_members, remove_tag_members


def update_tags(crm_df: pd.DataFrame, config: Config, list_name: str) -> None:
def update_tags(
crm_df: pd.DataFrame, config: Config, list_name: str
) -> tuple[dict[str, list[str]], dict[str, list[str]]]:
"""Update tags for members in the CRM."""
# Create a Mailchimp service
mailchimp_service = MailchimpService(config)
Expand All @@ -114,8 +118,10 @@ def update_tags(crm_df: pd.DataFrame, config: Config, list_name: str) -> None:
members_with_tags_df["email"].isin(crm_emails)
]

_add_and_remove_tags(
add_tag_members, remove_tag_members = _add_and_remove_tags(
mailchimp_service=mailchimp_service,
list_id=list_id,
members_with_tags_df=members_with_tags_df,
)

return add_tag_members, remove_tag_members
10 changes: 9 additions & 1 deletion tests/processing/test_update_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ def test_update_tags(
mock_post.return_value.status_code = 200
mock_post.return_value.json.return_value = {"id": "batch_id"}
mock_datetime.now.return_value = datetime(2024, 11, 15, 10, 44, 16, 794923)
update_tags(crm_df=crm_df, config=self.config, list_name="airt")
add_tag_members, remove_tag_members = update_tags(
crm_df=crm_df, config=self.config, list_name="airt"
)

assert mock_get.call_count == 2
for url in [
Expand Down Expand Up @@ -193,6 +195,12 @@ def test_update_tags(
},
timeout=10,
)
assert add_tag_members == {
"M3": ["third_member_id"],
}
assert remove_tag_members == {
"M2": ["third_member_id"],
}

@pytest.mark.skip(reason="real api call")
def test_real_update_tags(self) -> None:
Expand Down

0 comments on commit 3ff40cc

Please sign in to comment.