From 469423cab3d8b45f72e487815653506a4e25a377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Wed, 18 Sep 2024 16:08:50 -0500 Subject: [PATCH] AAP-31447: Marketing report (#1313) Move the "Organization name" column and remove the "Trial expired_at" column. --- ansible_ai_connect/test_utils.py | 10 ++++------ .../tests/test_generate_users_trials_reports.py | 7 +++++-- ansible_ai_connect/users/reports/generators.py | 8 ++++---- .../users/reports/tests/test_generators.py | 7 ++----- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/ansible_ai_connect/test_utils.py b/ansible_ai_connect/test_utils.py index 0159302e8..95af16491 100644 --- a/ansible_ai_connect/test_utils.py +++ b/ansible_ai_connect/test_utils.py @@ -78,11 +78,9 @@ def create_user_with_provider(**kwargs): class WisdomLogAwareMixin: @staticmethod - def searchInLogOutput(s, logs): - for log in logs.output: - if s in log: - return True - return False + def searchInLogOutput(s, logs, cpt=None): + found_cpt = sum(o.count(s) for o in logs.output) + return found_cpt == cpt if cpt else bool(found_cpt) @staticmethod def extractSegmentEventsFromLog(logs): @@ -114,7 +112,7 @@ def assert_error_detail(self, r, code: str, message: str = None): class WisdomServiceLogAwareTestCase(WisdomTestCase, WisdomLogAwareMixin): - def assertInLog(self, s, logs): + def assertInLog(self, s, logs, cpt=None): self.assertTrue(self.searchInLogOutput(s, logs), logs) def assertNotInLog(self, s, logs): diff --git a/ansible_ai_connect/users/management/commands/tests/test_generate_users_trials_reports.py b/ansible_ai_connect/users/management/commands/tests/test_generate_users_trials_reports.py index e21176d73..de0a47dcd 100644 --- a/ansible_ai_connect/users/management/commands/tests/test_generate_users_trials_reports.py +++ b/ansible_ai_connect/users/management/commands/tests/test_generate_users_trials_reports.py @@ -87,9 +87,12 @@ def call_command_with_argv(argv): def test_dry_run(self): with self.assertLogs(logger="root", level="INFO") as log: out = TestGenerateUsersTrialsReports.call_command("--dry-run") - self.assertInLog("First name,Last name,Organization name,Plan name,Trial started", log) + self.assertInLog("First name,Last name,Organization name,Email,Plan name", log, cpt=3) self.assertInLog( - "First name,Last name,Email,Organization name,Plan name,Trial started", log + "First name,Last name,Organization name,Email,Plan name," + "Trial started,Trial expired_at", + log, + cpt=2, ) self.assertIn("Reports not sent", out) diff --git a/ansible_ai_connect/users/reports/generators.py b/ansible_ai_connect/users/reports/generators.py index dd92ee3b2..0a69a34a8 100644 --- a/ansible_ai_connect/users/reports/generators.py +++ b/ansible_ai_connect/users/reports/generators.py @@ -78,6 +78,7 @@ def generate( "First name", "Last name", "Organization name", + "Email", "Plan name", "Trial started", "Trial expired_at", @@ -93,6 +94,7 @@ def generate( user["given_name"], user["family_name"], organization["name"], + user["email"], plan["plan"]["name"], plan["created_at"], plan["expired_at"], @@ -124,11 +126,10 @@ def generate( "UUID", "First name", "Last name", - "Email", "Organization name", + "Email", "Plan name", "Trial started", - "Trial expired_at", ] ) for user in users: @@ -140,11 +141,10 @@ def generate( user["uuid"], user["given_name"], user["family_name"], - user["email"], organization["name"], + user["email"], plan["plan"]["name"], plan["created_at"], - plan["expired_at"], ] writer.writerow(row_data) diff --git a/ansible_ai_connect/users/reports/tests/test_generators.py b/ansible_ai_connect/users/reports/tests/test_generators.py index 63dacbc54..75592c0ee 100644 --- a/ansible_ai_connect/users/reports/tests/test_generators.py +++ b/ansible_ai_connect/users/reports/tests/test_generators.py @@ -155,7 +155,7 @@ def tearDown(self): def get_report_header(self) -> str: return ( - "OrgId,UUID,First name,Last name,Organization name," + "OrgId,UUID,First name,Last name,Organization name,Email," "Plan name,Trial started,Trial expired_at,Org has_api_key" ) @@ -209,10 +209,7 @@ def tearDown(self): super().cleanup() def get_report_header(self) -> str: - return ( - "OrgId,UUID,First name,Last name,Email,Organization name," - "Plan name,Trial started,Trial expired_at" - ) + return "OrgId,UUID,First name,Last name,Organization name,Email," "Plan name,Trial started" def get_report_generator(self) -> BaseGenerator: return UserMarketingReportGenerator()