From 7438a8079e4070023ba6e545cad5c58f6e9582a5 Mon Sep 17 00:00:00 2001 From: Erik Harding Date: Thu, 3 Aug 2023 15:41:18 +0200 Subject: [PATCH] Add youth keywords for tracking --- .github/workflows/build.yaml | 1 + yal/main.py | 13 ++++++++++++- yal/tests/test_main.py | 26 ++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 25a47c15..94ef77ce 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -4,6 +4,7 @@ on: push: branches: - main + - youth-keyword jobs: build: diff --git a/yal/main.py b/yal/main.py index dfacde37..f9d6cc4c 100644 --- a/yal/main.py +++ b/yal/main.py @@ -59,6 +59,15 @@ "connect", "i saw this on facebook", } +TRACKING_KEYWORDS_ROUND_3 = { + "youth", + "yth", + "yuth", + "yut", + "yoth", + "yot", + "yoh" +} OPTOUT_KEYWORDS = {"stop", "opt out", "cancel", "quit"} ONBOARDING_REMINDER_KEYWORDS = { "continue", @@ -143,6 +152,7 @@ async def process_message(self, message): keyword in GREETING_KEYWORDS or keyword in TRACKING_KEYWORDS or keyword in TRACKING_KEYWORDS_ROUND_2 + or keyword in TRACKING_KEYWORDS_ROUND_3 ): self.user.session_id = None self.state_name = self.START_STATE @@ -252,7 +262,7 @@ async def state_start(self): inbound = utils.clean_inbound(self.inbound.content) # Save keywords that are used for source tracking - if inbound in TRACKING_KEYWORDS or inbound in TRACKING_KEYWORDS_ROUND_2: + if inbound in TRACKING_KEYWORDS or inbound in TRACKING_KEYWORDS_ROUND_2 or inbound in TRACKING_KEYWORDS_ROUND_3: self.save_answer("state_source_tracking", inbound) if inbound in OPTOUT_KEYWORDS: @@ -261,6 +271,7 @@ async def state_start(self): inbound in GREETING_KEYWORDS or inbound in TRACKING_KEYWORDS or inbound in TRACKING_KEYWORDS_ROUND_2 + or inbound in TRACKING_KEYWORDS_ROUND_3 ): if terms_accepted and onboarding_completed: return await self.go_to_state(MainMenuApplication.START_STATE) diff --git a/yal/tests/test_main.py b/yal/tests/test_main.py index 872065a7..00b1632d 100644 --- a/yal/tests/test_main.py +++ b/yal/tests/test_main.py @@ -468,6 +468,32 @@ async def test_tracked_keywords_saved_for_new_user_ads_round_2( tester.assert_answer("state_source_tracking", "hi") +@pytest.mark.asyncio +async def test_tracked_keywords_saved_ads_round_3( + tester: AppTester, rapidpro_mock, contentrepo_api_mock +): + rapidpro_mock.tstate.contact_fields["onboarding_completed"] = "True" + rapidpro_mock.tstate.contact_fields["terms_accepted"] = "True" + await tester.user_input("youth") + tester.assert_state("state_mainmenu") + tester.assert_num_messages(2) + + tester.assert_answer("state_source_tracking", "youth") + + +@pytest.mark.asyncio +async def test_tracked_keywords_saved_for_new_user_ads_round_3( + tester: AppTester, rapidpro_mock, contentrepo_api_mock +): + rapidpro_mock.tstate.contact_fields["onboarding_completed"] = "" + rapidpro_mock.tstate.contact_fields["terms_accepted"] = "" + await tester.user_input("yoth") + tester.assert_state("state_welcome") + tester.assert_num_messages(1) + + tester.assert_answer("state_source_tracking", "yoth") + + @pytest.mark.asyncio async def test_onboarding_reminder_response_to_reminder_handler( tester: AppTester, rapidpro_mock