Skip to content

test: Added missing unit and integration tests#32

Open
usanvict wants to merge 1 commit into
apify:feat/modernize-langchain-integration-testingfrom
usanvict:feat/unit-and-integration-tests-improvement
Open

test: Added missing unit and integration tests#32
usanvict wants to merge 1 commit into
apify:feat/modernize-langchain-integration-testingfrom
usanvict:feat/unit-and-integration-tests-improvement

Conversation

@usanvict
Copy link
Copy Markdown

Summary

Adds comprehensive unit and end-to-end test coverage for the Apify LangChain tools, targeting gaps not covered by the existing test_tools.py and test_client.py suites.

New unit tests

  • test_clamping.py -- Tests _clamp_depth (previously untested), exact at-boundary values for all clamp functions (_clamp_timeout, _clamp_memory, _clamp_items, _clamp_depth), and relaxed custom limit pass-through.
  • test_input_validation.py -- Exhaustive Pydantic input schema validation: missing required fields, wrong types, offset boundaries, empty/long string IDs, unicode/special characters, dict structure edge cases (deeply nested, None values, large dicts), URL format boundaries, ApifyDatasetLoader constructor validation, and confirmation that schemas intentionally defer range-checking to clamping.
  • test_integration_mock.py -- Tests the LangChain .invoke() error-handling path (handle_tool_error=True converts ToolException to a string instead of raising) and verifies output key sets match the documented API contract for RunActor, RunActorAndGetDataset, and GetDatasetItems.
  • test_run_meta.py -- Edge cases for the _run_meta() utility: empty dict returns all Nones, extra API keys are filtered out, and non-SUCCEEDED statuses (FAILED, TIMED-OUT, RUNNING, ABORTING) are preserved.
  • test_two_step_orchestration.py -- Tests the RunActor -> GetDatasetItems two-step orchestration pattern: dataset_id flows correctly between steps, failed Step 1 produces non-JSON error output, and each run produces a unique dataset ID.

New E2E integration tests

All E2E tests require APIFY_API_TOKEN and are automatically skipped when the token is not set.

  • test_e2e_auth.py -- Missing token raises ValueError; invalid token returns a non-JSON error string.
  • test_e2e_happy.py -- Happy-path coverage for all 6 core tools (RunActor, GetDatasetItems, RunActorAndGetDataset, ScrapeUrl, RunTask, RunTaskAndGetDataset) against the live Apify API using apify/python-example.
  • test_e2e_negative.py -- Parametrized test verifying that invalid actor/dataset/task IDs return graceful error strings (no exception propagation).
  • test_e2e_stability.py -- Repeated invocations produce structurally consistent output shapes and unique dataset IDs; fetching the same dataset multiple times returns identical items.
  • test_e2e_timeout.py -- Boundary conditions against the live API: offset beyond dataset returns empty, limit larger than dataset returns available items, and explicit memory_mbytes=128 is accepted.

@usanvict usanvict changed the title Added missing unit and integration tests Test: Added missing unit and integration tests May 15, 2026
@usanvict usanvict changed the title Test: Added missing unit and integration tests test: Added missing unit and integration tests May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants