All checks were successful
Build Docker Image / build (push) Successful in 1m22s
Created test suite covering all 8 main geo service endpoints: - Basic: products, nodes (with filters/bounds), clusteredNodes - Nearest: nearestHubs, nearestOffers, nearestSuppliers (with product filters) - Routing: routeToCoordinate, autoRoute, railRoute - Edge cases: invalid coordinates, zero radius, nonexistent UUIDs Test suite uses real API calls to production GraphQL endpoint. 16 tests total across 4 test classes. Files: - tests/test_graphql_endpoints.py: Main test suite (600+ lines) - tests/README.md: Documentation and usage guide - pytest.ini: Pytest configuration - run_tests.sh: Convenience script to run tests - pyproject.toml: Added pytest and requests as dev dependencies
3.7 KiB
3.7 KiB
Geo Service Tests
Comprehensive test suite for all GraphQL endpoints in the geo service.
Test Coverage
Basic Endpoints (4 tests)
test_products_query- List all unique productstest_nodes_query_basic- List hubs/nodes without filterstest_nodes_query_with_filters- Filter nodes by transport type and countrytest_nodes_query_with_bounds- Filter nodes by geographic boundstest_clustered_nodes_query- Map clustering for visualization
Nearest Endpoints (6 tests)
test_nearest_hubs- Find hubs near coordinatestest_nearest_hubs_with_product_filter- Find hubs with specific producttest_nearest_offers- Find offers near coordinatestest_nearest_offers_with_product_filter- Find offers for specific producttest_nearest_suppliers- Find suppliers near coordinatestest_nearest_suppliers_with_product_filter- Find suppliers with product
Routing Endpoints (3 tests)
test_route_to_coordinate- Multi-hop route from offer to destinationtest_auto_route- Road route between coordinates (requires OSRM)test_rail_route- Rail route between coordinates
Edge Cases (3 tests)
test_nearest_with_zero_radius- Very small search radiustest_invalid_coordinates- Invalid lat/lon valuestest_nonexistent_uuid- Non-existent offer UUID
Total: 16 tests covering 8 main endpoints
Running Tests
Local Testing (against production)
cd backends/geo
poetry install
poetry run pytest tests/test_graphql_endpoints.py -v
Testing against different endpoint
export TEST_GEO_URL=https://geo-staging.example.com/graphql/public/
poetry run pytest tests/test_graphql_endpoints.py -v
Run specific test class
poetry run pytest tests/test_graphql_endpoints.py::TestNearestEndpoints -v
Run single test
poetry run pytest tests/test_graphql_endpoints.py::TestNearestEndpoints::test_nearest_offers -v
Show print output
poetry run pytest tests/test_graphql_endpoints.py -v -s
CI Integration
Tests should be run on each deployment:
# .gitea/workflows/test.yml
- name: Run geo endpoint tests
run: |
cd backends/geo
poetry install
export TEST_GEO_URL=https://geo.optovia.ru/graphql/public/
poetry run pytest tests/test_graphql_endpoints.py -v
Test Data Requirements
Tests use real data from the production/staging database. Required data:
- At least one product in
productscollection - At least one hub node with coordinates
- At least one offer with coordinates
- Graph edges for routing tests
Expected Test Results
All tests should pass on production environment. Some tests may be skipped if:
- No products exist:
test_nearest_hubs_with_product_filter,test_nearest_offers_with_product_filter - No offers exist:
test_route_to_coordinate - OSRM not configured:
test_auto_route,test_rail_route(warnings, not failures)
Troubleshooting
All nearest* tests return 0 results
Check that nodes collection has documents with:
- Valid
latitudeandlongitudefields (not null) - Correct
node_typefield ('hub','offer','supplier')
Query ArangoDB directly:
// Count offers with coordinates
db._query(`
FOR node IN nodes
FILTER node.node_type == 'offer'
FILTER node.latitude != null AND node.longitude != null
RETURN node
`).toArray().length
Test failures with 400 errors
Check GraphQL schema matches test queries. GraphQL validation errors indicate:
- Missing required arguments
- Wrong argument types
- Invalid field names
Connection errors
Verify:
- TEST_GEO_URL points to correct endpoint
- Endpoint is accessible (not behind VPN/firewall)
- GraphQL endpoint is
/graphql/public/not/graphql/