Skip to content

Gold tests for travel #1005

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Gold tests for travel #1005

wants to merge 3 commits into from

Conversation

bobhancockg
Copy link
Contributor

No description provided.

This commit introduces a new test suite for the Python scripts located in the examples/travel/ directory.

Key changes:
- Created a new subdirectory examples/travel/tests/.
- Added an __init__.py file to examples/travel/tests/ to make it a Python package.
- For each script in examples/travel/ (add_hotel_ad.py, add_hotel_ad_group_bid_modifiers.py, add_hotel_listing_group_tree.py, add_performance_max_for_travel_goals_campaign.py, add_things_to_do_ad.py):
    - A corresponding test file (e.g., test_add_hotel_ad.py) was created in examples/travel/tests/.
    - Each test file includes unittest.TestCase classes with methods to test the main functionality of the script.
    - Tests utilize unittest.mock to mock the GoogleAdsClient, its services, and API responses, ensuring that no actual API calls are made.
    - Assertions are in place to verify that:
        - GoogleAdsClient is loaded with version "v19".
        - Service methods are called with the expected parameters.
        - Helper functions within the scripts behave as intended.
        - Command-line arguments are parsed correctly.
        - The script produces the expected print outputs.
- The tests are structured to be discoverable and runnable from the root directory of the repository (e.g., using `python -m unittest discover ./examples/travel/tests`).

This test suite improves the robustness and maintainability of the example scripts by providing automated checks for their core logic.
… done so far and provide feedback for Jules to continue.
This commit completes the creation and debugging of a test suite for Python scripts in the examples/travel/ directory.

Summary of steps and changes:

1.  **Initial Test Creation**:
    *   I created the `examples/travel/tests/` directory and `__init__.py`.
    *   I generated initial test files for all 5 scripts:
        *   `test_add_hotel_ad.py`
        *   `test_add_hotel_ad_group_bid_modifiers.py`
        *   `test_add_hotel_listing_group_tree.py`
        *   `test_add_performance_max_for_travel_goals_campaign.py`
        *   `test_add_things_to_do_ad.py`

2.  **Debugging and Refinement**:
    *   **Common Test Structure**: I refactored the tests to remove `test_script_runner` methods, which unreliably tested `if __name__ == "__main__":` blocks. Instead, I focused `test_main` methods on the core script logic, directly passing a mocked `GoogleAdsClient` instance.
    *   **Script Correction**: I identified and fixed f-string errors in print statements within `examples/travel/add_hotel_ad.py`.
    *   **Enum Mocking**: I resolved an `AttributeError` in `test_add_performance_max_for_travel_goals_campaign.py` by ensuring mocked enum objects correctly provided a `.name` string attribute.
    *   **Mocking Complexities (`test_add_hotel_listing_group_tree.py`)**:
        *   I encountered significant difficulties mocking protobuf `Message.CopyFrom()` calls and reliably asserting direct attribute assignments on nested `MagicMock` objects.
        *   **Resolution**: I simplified assertions for this test to focus on reliably verifiable aspects: service call invocation, correct `customer_id`, expected number of operations, calls to `client.get_type` for key messages, calls to `client.copy_from` (the client utility, not the protobuf method), and print statements. This acknowledges the mocking limitations while still providing value.
    *   **Dynamic Type Mocking**: For `test_add_things_to_do_ad.py` and `test_add_performance_max_for_travel_goals_campaign.py`, I implemented a dynamic side effect for `client.get_type` to ensure that mocked types had necessary child attributes (as `MagicMock` instances) pre-configured. This prevented `AttributeError`s when the script accessed nested attributes on these mocked types.

3.  **Final Verification**:
    *   I confirmed that all individual test files passed.
    *   I ran `python -m unittest discover ./examples/travel/tests`, and all 5 tests passed successfully.

All planned work for this issue is now complete and included in this commit.
@bobhancockg bobhancockg requested a review from a team as a code owner June 2, 2025 10:58
@BenRKarl BenRKarl added the kokoro:run This label is required to run a kokoro presubmit if an external contributor sends a PR. label Jun 5, 2025
@kokoro-team kokoro-team removed the kokoro:run This label is required to run a kokoro presubmit if an external contributor sends a PR. label Jun 5, 2025
@BenRKarl BenRKarl added the kokoro:force-run This label is required to run a kokoro presubmit if an external contributor sends a PR. label Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kokoro:force-run This label is required to run a kokoro presubmit if an external contributor sends a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy