Skip to content

Commit

Permalink
Merge pull request #103 from airtai/dev
Browse files Browse the repository at this point in the history
Update validation (#102)
  • Loading branch information
kumaranvpl committed Sep 4, 2024
2 parents 1fd9f81 + db50210 commit 8f44374
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 14 deletions.
8 changes: 0 additions & 8 deletions google_sheets/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion google_sheets/data_processing/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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


Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand All @@ -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",
Expand Down
52 changes: 50 additions & 2 deletions tests/data_processing/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -62,7 +63,7 @@ def test_validate_input_data(df: pd.DataFrame, expected: str) -> None:
(
pd.Series(
{
"Category": "Bus",
"Category": "bus",
}
),
True,
Expand All @@ -78,7 +79,7 @@ def test_validate_input_data(df: pd.DataFrame, expected: str) -> None:
(
pd.Series(
{
"Category": "Ferry",
"Category": "ferry",
}
),
False,
Expand All @@ -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"),
[
Expand Down

0 comments on commit 8f44374

Please sign in to comment.