Skip to content

Commit 0d61346

Browse files
✅ Add initial unit tests for models
1 parent c47f292 commit 0d61346

3 files changed

Lines changed: 98 additions & 0 deletions

File tree

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Tests for search-ads-api."""

tests/unit/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Unit tests for search-ads-api."""

tests/unit/test_models.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
"""Tests for the Pydantic models."""
2+
3+
import pytest
4+
5+
from search_ads_api.models import (
6+
Campaign,
7+
CampaignCreate,
8+
CampaignStatus,
9+
CampaignSupplySource,
10+
Money,
11+
Selector,
12+
)
13+
14+
15+
class TestMoney:
16+
"""Tests for the Money model."""
17+
18+
def test_create_money(self) -> None:
19+
"""Test creating a Money instance."""
20+
money = Money(amount="100.50", currency="USD")
21+
assert money.amount == "100.50"
22+
assert money.currency == "USD"
23+
24+
def test_money_usd_helper(self) -> None:
25+
"""Test the USD helper method."""
26+
money = Money.usd(100)
27+
assert money.amount == "100"
28+
assert money.currency == "USD"
29+
30+
def test_money_usd_with_decimals(self) -> None:
31+
"""Test USD helper with decimal amount."""
32+
money = Money.usd(100.50)
33+
assert money.amount == "100.5"
34+
assert money.currency == "USD"
35+
36+
37+
class TestSelector:
38+
"""Tests for the Selector model."""
39+
40+
def test_empty_selector(self) -> None:
41+
"""Test creating an empty selector with defaults."""
42+
selector = Selector()
43+
data = selector.model_dump(by_alias=True, exclude_none=True)
44+
assert data["conditions"] == []
45+
assert data["orderBy"] == []
46+
assert data["pagination"]["limit"] == 1000
47+
assert data["pagination"]["offset"] == 0
48+
49+
def test_selector_with_condition(self) -> None:
50+
"""Test creating a selector with a condition."""
51+
selector = Selector().where("status", "==", "ENABLED")
52+
data = selector.model_dump(by_alias=True, exclude_none=True)
53+
assert "conditions" in data
54+
assert len(data["conditions"]) == 1
55+
assert data["conditions"][0]["field"] == "status"
56+
assert data["conditions"][0]["operator"] == "EQUALS"
57+
assert data["conditions"][0]["values"] == ["ENABLED"]
58+
59+
def test_selector_with_pagination(self) -> None:
60+
"""Test creating a selector with pagination."""
61+
selector = Selector().limit(50).offset(100)
62+
data = selector.model_dump(by_alias=True, exclude_none=True)
63+
assert "pagination" in data
64+
assert data["pagination"]["limit"] == 50
65+
assert data["pagination"]["offset"] == 100
66+
67+
68+
class TestCampaignCreate:
69+
"""Tests for campaign creation models."""
70+
71+
def test_create_campaign_model(self) -> None:
72+
"""Test creating a CampaignCreate instance."""
73+
campaign = CampaignCreate(
74+
name="Test Campaign",
75+
adam_id=123456789,
76+
countries_or_regions=["US"],
77+
supply_sources=[CampaignSupplySource.APPSTORE_SEARCH_RESULTS],
78+
daily_budget_amount=Money.usd(100),
79+
)
80+
assert campaign.name == "Test Campaign"
81+
assert campaign.adam_id == 123456789
82+
assert campaign.countries_or_regions == ["US"]
83+
assert campaign.status == CampaignStatus.ENABLED
84+
85+
def test_campaign_serialization(self) -> None:
86+
"""Test that campaign serializes with correct aliases."""
87+
campaign = CampaignCreate(
88+
name="Test Campaign",
89+
adam_id=123456789,
90+
countries_or_regions=["US"],
91+
supply_sources=[CampaignSupplySource.APPSTORE_SEARCH_RESULTS],
92+
)
93+
data = campaign.model_dump(by_alias=True, exclude_none=True)
94+
assert "adamId" in data
95+
assert "countriesOrRegions" in data
96+
assert "supplySources" in data

0 commit comments

Comments
 (0)