diff --git a/captn/captn_agents/backend/tools/_gbb_google_sheets_team_tools.py b/captn/captn_agents/backend/tools/_gbb_google_sheets_team_tools.py index b787ed1f..042cc2b9 100644 --- a/captn/captn_agents/backend/tools/_gbb_google_sheets_team_tools.py +++ b/captn/captn_agents/backend/tools/_gbb_google_sheets_team_tools.py @@ -19,6 +19,7 @@ CampaignCallouts, CampaignCriterion, CampaignLanguageCriterion, + CampaignSharedSet, GeoTargetCriterion, RemoveResource, ) @@ -275,6 +276,33 @@ def _create_negative_campaign_keywords( ) +def _add_negative_campaign_keywords_lists( + customer_id: str, + login_customer_id: Optional[str], + campaign_id: str, + keywords_df: pd.DataFrame, + context: GoogleSheetsTeamContext, +) -> None: + negative_campaign_keywords_lists = keywords_df[ + (keywords_df["Level"] == "Campaign List") & (keywords_df["Negative"]) + ] + for _, row in negative_campaign_keywords_lists.iterrows(): + model = CampaignSharedSet( + login_customer_id=login_customer_id, + customer_id=customer_id, + campaign_id=campaign_id, + shared_set_name=row["Keyword"], + ) + google_ads_post( + user_id=context.user_id, + conv_id=context.conv_id, + recommended_modifications_and_answer_list=context.recommended_modifications_and_answer_list, + model=model, + endpoint="/add-shared-set-to-campaign", + already_checked_clients_approval=True, + ) + + def _create_negative_ad_group_keywords( customer_id: str, login_customer_id: Optional[str], @@ -673,6 +701,14 @@ def _setup_campaign( (keywords_df["Campaign Name"] == campaign_name) ] + _add_negative_campaign_keywords_lists( + customer_id=customer_id, + login_customer_id=login_customer_id, + campaign_id=campaign_id, + keywords_df=all_campaign_keywords, + context=context, + ) + _create_negative_campaign_keywords( customer_id=customer_id, login_customer_id=login_customer_id, diff --git a/tests/ci/captn/captn_agents/backend/tools/test_gbb_google_sheets_team_tools.py b/tests/ci/captn/captn_agents/backend/tools/test_gbb_google_sheets_team_tools.py index 3843c7ba..fc660759 100644 --- a/tests/ci/captn/captn_agents/backend/tools/test_gbb_google_sheets_team_tools.py +++ b/tests/ci/captn/captn_agents/backend/tools/test_gbb_google_sheets_team_tools.py @@ -12,6 +12,7 @@ GoogleAdsResources, GoogleSheetsTeamContext, ResourceCreationResponse, + _add_negative_campaign_keywords_lists, _check_if_both_include_and_exclude_language_values_exist, _check_mandatory_columns, _get_alredy_existing_campaigns, @@ -814,3 +815,32 @@ def test_update_callouts( mock_requests_post.assert_called_once() call = mock_requests_post.call_args_list[0] assert call[1]["json"]["callouts"] == ["Free cancellation", "Return tickets"] + + def test_add_negative_campaign_keywords_lists( + self, + mock_get_login_url: Iterator[None], + mock_requests_post: Iterator[Any], + ) -> None: + keywords_df = pd.DataFrame( + { + "Campaign Name": ["My Campaign", "My Campaign"], + "Ad Group Name": ["My Campaign Ad Group", "My Campaign Ad Group"], + "Match Type": ["Exact", "Exact"], + "Keyword": ["Svi autobusni polasci", "my-list"], + "Level": [None, "Campaign List"], + "Negative": [False, True], + } + ) + + campaign_id = "12345" + _add_negative_campaign_keywords_lists( + customer_id=self.customer_id, + login_customer_id=self.login_customer_id, + keywords_df=keywords_df, + campaign_id=campaign_id, + context=self.context, + ) + + mock_requests_post.assert_called_once() + call = mock_requests_post.call_args_list[0] + assert call[1]["json"]["shared_set_name"] == "my-list"