-
Notifications
You must be signed in to change notification settings - Fork 509
Gold tests for audience insights #965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This commit introduces type hints for function arguments, return values, and local variables in `examples/audience_insights/generate_audience_insights.py`. Key changes include: - Added type hints to all function signatures and return types. - Added inline type hints for variables within functions. - Imported necessary types from `typing`, Google Ads client libraries, services, enums, and types modules. - Ensured proper organization and removal of unused or duplicate imports. - Updated some variable assignments to use specific Enum members for clarity (e.g., `AudienceInsightsDimensionEnum`). - Replaced some string formatting with f-strings in exception handling. These changes improve code readability, maintainability, and help with static analysis, making your example code more robust and easier to understand.
…sights.py` script. The tests are located in the `examples/audience_insights/test` directory. Key features of the test suite: - Mocks the Google Ads API client (v19) and its services (AudienceInsightsService, GoogleAdsService). - Includes tests for the three main functions: - `audience_composition_insights`: Verifies correct API call parameters (customer_id, audience definition, dimensions) and response handling. - `generate_suggested_targeting_insights`: Verifies correct API call parameters and response handling. - `list_audience_insights_attributes`: Verifies correct API call parameters, dimension usage, and processing of results. - Includes a test for the `main()` function's logic to ensure it correctly orchestrates calls to the helper functions with appropriate arguments. - Includes a test for the script's command-line entry point (`if __name__ == "__main__":`) to verify argument parsing and client initialization. - All tests are designed to use and verify Google Ads API v19 objects and enums. - The test suite can be run using standard Python unittest mechanisms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just double-checking if it's expected to add this empty file or not.
from google.ads.googleads.v19.enums.types import ( | ||
AudienceInsightsDimensionEnum, | ||
) | ||
# from google.ads.googleads.v19.types.audience_insights_service import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's commented out, can we delete it?
# The generic mock.Mock() from client.get_type should allow arbitrary attribute access | ||
# and list appends if the attribute is treated as a list. | ||
|
||
# To ensure the .append works as in the script, we can pre-set these attributes on the mock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this block of comments if needed anymore.
# Mock attribute that will be printed | ||
mock_kg_attribute = mock.Mock() | ||
mock_kg_attribute.dimension = self.mock_ads_client.enums.AudienceInsightsDimensionEnum.KNOWLEDGE_GRAPH | ||
# To make the nested attribute access work in the SUT: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this block of comments needed anymore?
Add test suite for examples/audience_insights This commit introduces a new test suite for the Google Ads API Python examples related to audience insights, specifically for `generate_audience_insights.py`. The test suite is located in `examples/audience_insights/tests/` and uses the `unittest` framework. Key features of the test suite: - Mocks the GoogleAdsClient and its services (AudienceInsightsService, GoogleAdsService) to prevent actual API calls. - Verifies correct request construction for: - `audience_composition_insights` - `generate_suggested_targeting_insights` - `list_audience_insights_attributes` - Tests the `main` function for both successful execution paths and exception handling (specifically `GoogleAdsException`). - Ensures that client enum values and service paths are correctly used. - Includes checks for console output where appropriate (e.g., for `list_audience_insights_attributes`). The tests ensure that the example script's logic is sound and that it interacts with the (mocked) client library as expected for Google Ads API v19.
Gold tests for audience insights