-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
167 add geo targeting criteria country city (#334)
* Implement add_geo_targeting_to_campaign endpoint * Integrate create_geo_targeting_for_campaign to the Google ads team * Update tests for geo targeting * Fix execute_query exception message when gads authentication error happens * Update prompts for gads geo targeting
- Loading branch information
1 parent
36c24c9
commit aa7155a
Showing
8 changed files
with
278 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import unittest | ||
|
||
import pytest | ||
from fastapi import HTTPException | ||
|
||
from google_ads.application import create_geo_targeting_for_campaign | ||
from google_ads.model import GeoTargetCriterion | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_add_geo_targeting_to_campaign_raises_exception_if_location_names_and_location_ids_are_none() -> None: | ||
geo_target = GeoTargetCriterion(customer_id="123", campaign_id="456") | ||
|
||
with pytest.raises(HTTPException): | ||
await create_geo_targeting_for_campaign(user_id=-1, model=geo_target) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_add_geo_targeting_to_campaign_raises_exception_if_location_ids_are_none() -> None: | ||
geo_target = GeoTargetCriterion( | ||
customer_id="123", | ||
campaign_id="456", | ||
location_names=["New York"], | ||
location_ids=None, | ||
) | ||
|
||
with unittest.mock.patch( | ||
"google_ads.application._get_geo_target_constant_by_names", | ||
) as mock_get_geo_target_constant_by_names: | ||
with unittest.mock.patch( | ||
"google_ads.application._get_client", | ||
) as mock_get_client: | ||
mock_get_geo_target_constant_by_names.return_value = None | ||
mock_get_client.return_value = None | ||
|
||
await create_geo_targeting_for_campaign(user_id=-1, model=geo_target) | ||
mock_get_geo_target_constant_by_names.assert_called_once_with( | ||
client=None, location_names=["New York"] | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_add_geo_targeting_to_campaign_raises_exception_if_location_ids_are_not_none() -> None: | ||
geo_target = GeoTargetCriterion( | ||
customer_id="123", | ||
campaign_id="456", | ||
location_names=None, | ||
location_ids=["7", "8"], | ||
) | ||
|
||
with unittest.mock.patch( | ||
"google_ads.application._create_locations_by_ids_to_campaign", | ||
) as mock_create_locations_by_ids_to_campaign: | ||
with unittest.mock.patch( | ||
"google_ads.application._get_client", | ||
) as mock_get_client: | ||
mock_create_locations_by_ids_to_campaign.return_value = None | ||
mock_get_client.return_value = None | ||
|
||
await create_geo_targeting_for_campaign(user_id=-1, model=geo_target) | ||
mock_create_locations_by_ids_to_campaign.assert_called_once_with( | ||
client=None, | ||
location_ids=["7", "8"], | ||
campaign_id="456", | ||
customer_id="123", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import unittest | ||
|
||
import pytest | ||
from requests.models import Response | ||
|
||
from captn.google_ads.client import ( | ||
ALREADY_AUTHENTICATED, | ||
AUTHENTICATION_ERROR, | ||
execute_query, | ||
) | ||
|
||
|
||
def test_execute_query_when_authentication_error_occurs_raises_value_error() -> None: | ||
with unittest.mock.patch( | ||
"captn.google_ads.client.get_login_url", | ||
) as mock_get_login_url: | ||
with unittest.mock.patch( | ||
"requests.get", | ||
) as mock_requests_get: | ||
mock_get_login_url.return_value = {"login_url": ALREADY_AUTHENTICATED} | ||
|
||
response = Response() | ||
response.status_code = 500 | ||
response._content = b'{"detail":"Please try to execute the command again."}' | ||
mock_requests_get.return_value = response | ||
|
||
with pytest.raises(ValueError) as exc_info: | ||
execute_query(user_id=-1, conv_id=-1) | ||
|
||
assert exc_info.value.args[0] == AUTHENTICATION_ERROR |