From fc9a9c47ad3536b58eff5f0a1a8ab7d3d1d44fd8 Mon Sep 17 00:00:00 2001 From: Robert Jambrecic Date: Thu, 25 Jul 2024 08:42:50 +0000 Subject: [PATCH] Update response message if dataframe contains Issues column --- google_sheets/app.py | 6 ++- google_sheets/model.py | 5 ++ tests/app/test_app.py | 112 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 121 insertions(+), 2 deletions(-) diff --git a/google_sheets/app.py b/google_sheets/app.py index 134d843..bc8d894 100644 --- a/google_sheets/app.py +++ b/google_sheets/app.py @@ -392,9 +392,10 @@ async def process_data( target_resource, # type: ignore ) + issues_present = "Issues" in validated_df.columns values = [validated_df.columns.tolist(), *validated_df.values.tolist()] - return GoogleSheetValues(values=values) + return GoogleSheetValues(values=values, issues_present=issues_present) async def process_campaigns_and_ad_groups( @@ -544,5 +545,8 @@ async def process_spreadsheet( sheet_values=processed_values, ) response += f"Sheet with the name '{title}' has been created successfully.\n" + if processed_values.issues_present: + response += """But there are issues present in the data. +Please check the 'Issues' column and correct the data accordingly.\n\n""" return response diff --git a/google_sheets/model.py b/google_sheets/model.py index e38fcd1..6109a9a 100644 --- a/google_sheets/model.py +++ b/google_sheets/model.py @@ -7,3 +7,8 @@ class GoogleSheetValues(BaseModel): values: List[List[Any]] = Field( ..., title="Values", description="Values to be written to the Google Sheet." ) + issues_present: bool = Field( + default=False, + title="Issues Present", + description="Whether any issues are present.", + ) diff --git a/tests/app/test_app.py b/tests/app/test_app.py index a3401e9..65d7202 100644 --- a/tests/app/test_app.py +++ b/tests/app/test_app.py @@ -294,7 +294,7 @@ class TestProcessData: ], ) @pytest.mark.asyncio() - async def test_process_data( + async def test_process_data_keywords( self, template_sheet_values: GoogleSheetValues, new_campaign_sheet_values: GoogleSheetValues, @@ -328,6 +328,116 @@ async def test_process_data( ) assert detail in exc.value.detail + @pytest.mark.asyncio() + async def test_process_data_ads(self) -> None: + template_sheet_values = GoogleSheetValues( + values=[ + [ + "Final URL", + "Headline 1", + "Headline 2", + "Headline 3", + "Description Line 1", + "Description Line 2", + "Path 1", + "Path 2", + ], + [ + "https://www.example.com/from", + "H" * 31, + "Headline 2", + "Headline 3", + "Description Line 1", + "Description Line 2", + "Path 1", + "Path 2", + ], + ] + ) + new_campaign_sheet_values = GoogleSheetValues( + values=[ + [ + "Country", + "Station From", + "Station To", + "Final Url From", + "Final Url To", + ], + [ + "India", + "Delhi", + "Mumbai", + "https://www.example.com/from", + "https://www.example.com/to", + ], + ] + ) + merged_campaigns_ad_groups_df = pd.DataFrame( + { + "Campaign Name": [ + "INSERT_COUNTRY - INSERT_STATION_FROM - INSERT_STATION_TO" + ], + "Ad Group Name": ["INSERT_STATION_FROM - INSERT_STATION_TO"], + "Match Type": ["Exact"], + } + ) + result = await process_data( + template_sheet_values=template_sheet_values, + new_campaign_sheet_values=new_campaign_sheet_values, + merged_campaigns_ad_groups_df=merged_campaigns_ad_groups_df, + target_resource="ad", + ) + + expected = GoogleSheetValues( + values=[ + [ + "Issues", + "Campaign Name", + "Ad Group Name", + "Match Type", + "Final URL", + "Headline 1", + "Headline 2", + "Headline 3", + "Description Line 1", + "Description Line 2", + "Path 1", + "Path 2", + ], + [ + "Headline length should be less than 30 characters, found 31 in column Headline 1.\n", + "India - Delhi - Mumbai", + "Delhi - Mumbai", + "Exact", + "https://www.example.com/from", + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH", + "Headline 2", + "Headline 3", + "Description Line 1", + "Description Line 2", + "Path 1", + "Path 2", + ], + [ + "Headline length should be less than 30 characters, found 31 in column Headline 1.\n", + "India - Delhi - Mumbai", + "Mumbai - Delhi", + "Exact", + "https://www.example.com/to", + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH", + "Headline 2", + "Headline 3", + "Description Line 1", + "Description Line 2", + "Path 1", + "Path 2", + ], + ], + issues_present=True, + ) + + assert result.model_dump() == expected.model_dump() + class TestOpenAPIJSON: def test_openapi(self) -> None: