Skip to content

feat(app-business-reviews): upgrade SDK to 2.0.0, add pytest unit tests#285

Merged
Shubhank-Jonnada merged 11 commits into
masterfrom
fix/app-business-reviews-sdk-v2
May 11, 2026
Merged

feat(app-business-reviews): upgrade SDK to 2.0.0, add pytest unit tests#285
Shubhank-Jonnada merged 11 commits into
masterfrom
fix/app-business-reviews-sdk-v2

Conversation

@Shubhank-Jonnada
Copy link
Copy Markdown
Contributor

@Shubhank-Jonnada Shubhank-Jonnada commented Apr 28, 2026

Summary

  • Upgraded autohive-integrations-sdk from ~=1.0.2 to ~=2.0.0
  • Migrated all action handlers to SDK 2.0 patterns: FetchResponse object (response.data, response.status), ActionResult, and ActionError
  • Fixed auth pattern: context.auth.get("credentials", {}).get("api_key", "")
  • Fixed optional vs required param access: required params use inputs["param"], optional use inputs.get("param")
  • Bumped integration version to 2.0.0
  • Added comprehensive unit and integration test suites covering all 6 actions

Test Results

Unit Tests (mocked, CI-safe)

Test Class Tests Status
TestSearchAppsIOS 6 ✅ PASSED
TestGetReviewsAppStore 7 ✅ PASSED
TestSearchAppsAndroid 4 ✅ PASSED
TestGetReviewsGooglePlay 7 ✅ PASSED
TestSearchPlacesGoogleMaps 6 ✅ PASSED
TestGetReviewsGoogleMaps 8 ✅ PASSED
Total 40 ALL PASSED

Integration Tests (live SerpApi)

Test Class Action Status
TestSearchAppsIos search_apps_ios ✅ PASSED
TestSearchAppsAndroid search_apps_android ✅ PASSED
TestSearchPlacesGoogleMaps search_places_google_maps ✅ PASSED
TestGetReviewsAppStore get_reviews_app_store ✅ PASSED
TestGetReviewsGooglePlay get_reviews_google_play ✅ PASSED
TestGetReviewsGoogleMaps get_reviews_google_maps ✅ PASSED
Total 12 ALL PASSED

Validation

Check Result
validate_integration.py ✅ PASSED (0 errors, 0 warnings)
check_code.py ✅ PASSED (0 warnings)
ruff check ✅ clean

How to run

# Unit tests
python -m pytest app-business-reviews/tests/test_app_business_reviews_unit.py -m unit -v

# Integration tests (requires API key)
APP_BUSINESS_REVIEWS_API_KEY=<your-key> python -m pytest app-business-reviews/tests/test_app_business_reviews_integration.py -m integration -v

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 28, 2026

🔍 Integration Validation Results

Commit: 2becd0493fbad4fadeeac48e48bb6f70f8900d72 · refactor(app-business-reviews): restore post-loop app/place_info extraction
Updated: 2026-05-05T22:34:42Z

Changed directories: app-business-reviews

Check Result
Structure ✅ Passed
Code ✅ Passed
Tests ✅ Passed
README ✅ Passed
Version ✅ Passed
✅ Structure Check output
Validating 1 integration(s)...

============================================================
Integration: app-business-reviews
============================================================
✅ All checks passed!

============================================================
SUMMARY
============================================================
Integrations validated: 1
Total errors: 0
Total warnings: 0

✅ All validations passed!
✅ Code Check output

[notice] A new release of pip is available: 26.0.1 -> 26.1.1
[notice] To update, run: pip install --upgrade pip
----------------------------------------
Checking: app-business-reviews
----------------------------------------

📦 Installing dependencies...

🐍 Checking Python syntax...
   ✅ Syntax OK

📥 Checking imports...
   ✅ Imports OK

📄 Checking JSON files...
   ✅ JSON files OK

🔍 Linting with ruff...
   ✅ Lint OK

🎨 Checking formatting with ruff...
   ✅ Formatting OK

🔒 Scanning for security issues with bandit...
   ✅ Security OK

🛡️ Checking dependencies for vulnerabilities with pip-audit...
   ✅ Dependencies OK

🔗 Checking config-code sync...
   ✅ Config-code sync OK

🔄 Checking fetch patterns...
   ✅ Fetch patterns OK

========================================
✅ CODE CHECK PASSED
========================================
✅ Tests Check output

Integration              Tests  Coverage        Status
------------------------------------------------------
app-business-reviews     40/40       95%      ✅ Passed
------------------------------------------------------
Total                    40/40            ✅ All passed

✅ Tests passed: app-business-reviews
✅ README Check output
========================================
✅ README CHECK PASSED
========================================
✅ Version Check output
✅ app-business-reviews: 1.0.0 → 2.0.0 (major bump)

========================================
✅ VERSION CHECK PASSED
========================================

Copy link
Copy Markdown
Collaborator

@TheRealAgentK TheRealAgentK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SDK 2.0.0 migration looks clean and the 40 unit tests cover the 6 actions across App Store, Google Play, and Google Maps. Local CI verified: validate_integration ✅, check_code ✅, ruff ✅, pytest ✅.

Blocking on one thing: no tests/test_app_business_reviews_integration.py. This integration uses custom API-key auth across three providers, so adding e2e coverage is straightforward — env vars per provider key and the live_context fixture per the writing-integration-tests skill. Please add at minimum a read-only happy-path test per provider before merge.

Also: branch name doesn't follow <type>/<issue#>/<desc> per AGENTS.md, and no linked issue.

- Pin autohive-integrations-sdk~=2.0.0 in requirements.txt
- Add .data to all context.fetch() return accesses
- Convert raise ValueError to return ActionError(message=...)
- Return ActionResult(data=..., cost_usd=0.0) from all action handlers
- Bump config.json version to 2.0.0
- Add tests/conftest.py and 40-test unit suite covering all 6 actions
… and integration tests

- Fix api_key default from {} to "" in all action handlers
- Delete old manual asyncio test file
- Add test_app_business_reviews_integration.py with pytest.mark.integration, APP_BUSINESS_REVIEWS_API_KEY env var
- Add APP_BUSINESS_REVIEWS_API_KEY to .env.example
@Shubhank-Jonnada Shubhank-Jonnada force-pushed the fix/app-business-reviews-sdk-v2 branch from 56288d2 to ea19ffb Compare May 4, 2026 02:17
@Shubhank-Jonnada
Copy link
Copy Markdown
Contributor Author

@TheRealAgentK unit and live integration tests are done and all passing. Here are the results:

Unit tests: 40/40 passed covering all 6 actions with happy path, error handling, param validation, and response shape tests.

Live integration tests: 12/12 passed against the real SerpApi, covering all 6 actions:

  • search_apps_ios
  • search_apps_android
  • search_places_google_maps
  • get_reviews_app_store (chained from iOS search to get a real product ID)
  • get_reviews_google_play
  • get_reviews_google_maps (chained from Maps search to get a real place ID)

All read-only, nothing destructive. PR description updated with full results.

Copy link
Copy Markdown
Collaborator

@TheRealAgentK TheRealAgentK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1. mock_context.auth shape doesn't match source — tests/test_app_business_reviews_unit.py:104

ctx.auth = {"api_key": "test_serpapi_key"}

Source reads context.auth.get("credentials", {}).get("api_key", "") — so every action receives api_key="" in unit tests. No test asserts on params["api_key"], so the mismatch is silent. Fix:

ctx.auth = {"credentials": {"api_key": "test_serpapi_key"}}

2. Stale tests/context.py — delete

Pre-SDK-2.0 testbed shim (still inserts dependencies/ on sys.path). Unused once conftest is fixed.

3. tests/conftest.py is a no-op

sys.path.insert(0, os.path.dirname(__file__)) puts tests/ on path, not the integration root. The actual import wiring is the importlib block duplicated in both test files. Replacement:

# tests/conftest.py
import os, sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

Test files then drop the importlib block and use from app_business_reviews import app_business_reviews. Single-file integration with no actions/ subdir — straightforward.

4. response = None then post-loop if response is not Noneapp_business_reviews.py:283, 461

Guards the unbound case when max_pages=0. Minor: either initialize app_info = {} / place_info = {} directly, or keep the guard with a comment.


#1 is the real bug. #2–4 also don't match the pattern expected (similar to the issues raised in #284 / #306).

The source code reads context.auth.get("credentials", {}).get("api_key", ""),
but the test fixture set ctx.auth = {"api_key": "..."}. As a result every
action received api_key="" in unit tests. The mismatch was silent because
no test asserted on params["api_key"].

Adds a regression assertion in TestSearchAppsIOS::test_request_params_include_term
that verifies api_key is forwarded from the credentials block, so any future
auth-shape drift will fail the suite immediately.
The previous conftest inserted the tests directory itself onto sys.path,
which is a no-op for the intended purpose of making the integration's
modules importable from test files. Insert the parent (integration root)
instead, matching the pattern from PRs #280, #289, #306, and #307.
With tests/conftest.py putting the integration root on sys.path and
the workspace conftest.py patching Integration.load to find config.json,
test files can now import the integration with a plain
'from app_business_reviews import app_business_reviews'.

Removes the importlib.util.spec_from_file_location dance from both
test files and the now-unused dependencies/ sys.path entry. Also
deletes the legacy tests/context.py shim from the pre-SDK-2.0 testbed.

Matches the simpler pattern used in PRs #280, #289, #306, #307.
…' guards

Both get_reviews_google_play and get_reviews_google_maps tracked the
last response object across the pagination loop just so the post-loop
code could call response.data.get(...) for product/place info, with a
defensive 'if response is not None' guard for the max_pages=0 case.

Capture app_info / place_info inside the loop instead, initialized to
an empty dict before the loop. Same behavior, no defensive guard, no
loop-leaked variable.
…action

Reverts the in-loop assignment introduced in c1455c7. The original code
extracted product_info / place_info from the response variable once
after the pagination loop, which is the more idiomatic shape (one
read, one write).

Keeps the sentinel-and-guard pattern that c1455c7 was meant to clean
up, but adds a comment explaining why the guard is there (max_pages=0
edge case where the loop never executes).
Copy link
Copy Markdown
Collaborator

@TheRealAgentK TheRealAgentK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-approved to change status. Needs 3rd person review and e2e testing post-review.

@Shubhank-Jonnada
Copy link
Copy Markdown
Contributor Author

Shubhank-Jonnada commented May 11, 2026

Live Integration Test Results

All 12 tests passing against the real SerpApi.

Full results (12 passed, 0 failed)
Action Test Result
search_apps_ios test_returns_apps PASSED
search_apps_ios test_num_limit_respected PASSED
search_apps_android test_returns_apps PASSED
search_apps_android test_limit_respected PASSED
search_places_google_maps test_returns_places PASSED
search_places_google_maps test_location_filters_results PASSED
get_reviews_app_store test_returns_reviews_for_whatsapp PASSED
get_reviews_app_store test_auto_resolve_by_app_name PASSED
get_reviews_google_play test_returns_reviews_for_whatsapp PASSED
get_reviews_google_play test_auto_resolve_by_app_name PASSED
get_reviews_google_maps test_returns_reviews_chained_from_search PASSED
get_reviews_google_maps test_response_structure PASSED

Notes:

  • All 6 actions covered across App Store, Google Play, and Google Maps
  • Google Maps review tests chain from a real search result to get a valid place ID
  • Run with: APP_BUSINESS_REVIEWS_API_KEY=<key> pytest app-business-reviews/tests/test_app_business_reviews_integration.py -m integration -o "addopts=--import-mode=importlib --tb=short"
image

@Shubhank-Jonnada Shubhank-Jonnada merged commit fc5e1a8 into master May 11, 2026
3 checks passed
@Shubhank-Jonnada Shubhank-Jonnada deleted the fix/app-business-reviews-sdk-v2 branch May 11, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants