From 321aadf3d40e555a4b465cd22b5e1fe93cd45337 Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Tue, 25 Jul 2023 17:47:29 +0200 Subject: [PATCH] Fix #778: switch newsletters timestamps columns to date and time --- ctms/acoustic_service.py | 25 ++++++++++++++----------- tests/unit/test_acoustic_service.py | 4 ++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/ctms/acoustic_service.py b/ctms/acoustic_service.py index 0d6043ba..c960433b 100644 --- a/ctms/acoustic_service.py +++ b/ctms/acoustic_service.py @@ -298,17 +298,20 @@ def _newsletter_converter(self, acoustic_main_table, contact, newsletters_mappin acoustic_main_table[sub_flag] = "0" for newsletter in contact_newsletters: - newsletter_row = { - "email_id": contact_email_id, - "newsletter_name": newsletter.name, - "newsletter_source": newsletter.source and str(newsletter.source), - "create_timestamp": newsletter.create_timestamp.date().isoformat(), - "update_timestamp": newsletter.update_timestamp.date().isoformat(), - "newsletter_format": newsletter.format, - "newsletter_lang": newsletter.lang, - "subscribed": transform_field_for_acoustic(newsletter.subscribed), - "newsletter_unsub_reason": newsletter.unsub_reason, - } + newsletter_row = {} + for column, field in ( + ("email_id", "email_id"), + ("newsletter_name", "name"), + ("newsletter_source", "source"), + ("newsletter_format", "format"), + ("newsletter_lang", "lang"), + ("subscribed", "subscribed"), + ("newsletter_unsub_reason", "unsub_reason"), + ("create_timestamp", "create_timestamp"), + ("update_timestamp", "update_timestamp"), + ): + value = getattr(newsletter, field) + newsletter_row[column] = transform_field_for_acoustic(value) newsletter_rows.append(newsletter_row) if newsletter.name in newsletters_mapping: diff --git a/tests/unit/test_acoustic_service.py b/tests/unit/test_acoustic_service.py index f5417888..ee4590f4 100644 --- a/tests/unit/test_acoustic_service.py +++ b/tests/unit/test_acoustic_service.py @@ -163,8 +163,8 @@ def test_ctms_to_acoustic_newsletter_timestamps( ) app_dev_row = [r for r in newsletters_rows if r["newsletter_name"] == "app-dev"][0] - assert app_dev_row["create_timestamp"] == "1982-05-08" - assert app_dev_row["update_timestamp"] == "2023-06-19" + assert app_dev_row["create_timestamp"] == "05/08/1982 13:20:00" + assert app_dev_row["update_timestamp"] == "06/19/2023 12:17:00" def test_ctms_to_acoustic_waitlists_minimal(