diff --git a/google_sheets/app.py b/google_sheets/app.py index 85e3c54..e48ed88 100644 --- a/google_sheets/app.py +++ b/google_sheets/app.py @@ -362,14 +362,6 @@ async def get_all_sheet_titles( ] -def _validate_target_resource(target_resource: Optional[str]) -> None: - if target_resource not in ["ad", "keyword"]: - raise HTTPException( - status_code=status.HTTP_400_BAD_REQUEST, - detail="The target resource should be either 'ad' or 'keyword'.", - ) - - async def process_campaign_data( template_sheet_values: GoogleSheetValues, new_campaign_sheet_values: GoogleSheetValues, diff --git a/google_sheets/data_processing/processing.py b/google_sheets/data_processing/processing.py index 1e16ff7..e878fc5 100644 --- a/google_sheets/data_processing/processing.py +++ b/google_sheets/data_processing/processing.py @@ -162,7 +162,7 @@ def _use_template_row(category: Any, template_row: pd.Series) -> bool: if not template_row["Category"]: return True - return template_row["Category"] == category # type: ignore[no-any-return] + return template_row["Category"].lower() == str(category).lower() # type: ignore[no-any-return] def _process_row( @@ -219,6 +219,7 @@ def _process_row( final_df = pd.concat([final_df, pd.DataFrame([new_row])], ignore_index=True) + final_df = final_df.drop_duplicates(ignore_index=True) return final_df diff --git a/pyproject.toml b/pyproject.toml index 707a414..fe2ac47 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,7 +47,7 @@ dependencies = [ "pydantic>=2.3,<3", "fastapi>=0.110.2", "prisma==0.13.1", - "google-api-python-client==2.142.0", + "google-api-python-client==2.143.0", "asyncify==0.10.0", "pandas==2.2.2" ] @@ -66,8 +66,8 @@ lint = [ "types-ujson", "types-Pygments", "types-docutils", - "mypy==1.11.0", - "ruff==0.6.2", + "mypy==1.11.2", + "ruff==0.6.3", "pyupgrade-directories==0.3.0", "bandit==1.7.9", "semgrep==1.85.0", diff --git a/tests/data_processing/test_processing.py b/tests/data_processing/test_processing.py index 32a56cd..65f3796 100644 --- a/tests/data_processing/test_processing.py +++ b/tests/data_processing/test_processing.py @@ -6,6 +6,7 @@ from google_sheets.data_processing.processing import ( _copy_all_with_prefixes, _get_target_location, + _process_row, _update_campaign_name, _use_template_row, _validate_language_codes, @@ -62,7 +63,7 @@ def test_validate_input_data(df: pd.DataFrame, expected: str) -> None: ( pd.Series( { - "Category": "Bus", + "Category": "bus", } ), True, @@ -78,7 +79,7 @@ def test_validate_input_data(df: pd.DataFrame, expected: str) -> None: ( pd.Series( { - "Category": "Ferry", + "Category": "ferry", } ), False, @@ -97,6 +98,53 @@ def test_use_template_row(template_row: pd.Series, expected: bool) -> None: assert _use_template_row("Bus", template_row) == expected +@pytest.mark.parametrize( + ("category", "expected_length"), + [ + ( + "Bus", + 1, + ), + ( + "Ferry", + 0, + ), + ], +) +def test_process_row( + category: str, + expected_length: int, +) -> None: + template_row = pd.Series( + { + "Campaign Name": "USA - A - B - EN", + "Ad Group Name": "A - B", + "Keyword": "k1", + "Max CPC": "", + "Language Code": "EN", + "Negative": "FALSE", + "Level": "", + "Keyword Match Type": "Exact", + "Match Type": "Exact", + "Category": "Bus", + } + ) + new_campaign_row = pd.Series( + { + "Campaign Name": "USA - A - B - EN", + "Country": "USA", + "Station From": "A", + "Station To": "B", + "Language Code": "EN", + "Category": category, + } + ) + final_df = pd.DataFrame(columns=template_row.index) + final_df = _process_row(new_campaign_row, template_row, final_df, "keyword") + + assert len(final_df) == expected_length + + @pytest.mark.parametrize( ("merged_campaigns_ad_groups_df", "template_df", "new_campaign_df", "expected"), [