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
131 lines
3.7 KiB
Markdown
131 lines
3.7 KiB
Markdown
# 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 products
|
|
- `test_nodes_query_basic` - List hubs/nodes without filters
|
|
- `test_nodes_query_with_filters` - Filter nodes by transport type and country
|
|
- `test_nodes_query_with_bounds` - Filter nodes by geographic bounds
|
|
- `test_clustered_nodes_query` - Map clustering for visualization
|
|
|
|
### Nearest Endpoints (6 tests)
|
|
- `test_nearest_hubs` - Find hubs near coordinates
|
|
- `test_nearest_hubs_with_product_filter` - Find hubs with specific product
|
|
- `test_nearest_offers` - Find offers near coordinates
|
|
- `test_nearest_offers_with_product_filter` - Find offers for specific product
|
|
- `test_nearest_suppliers` - Find suppliers near coordinates
|
|
- `test_nearest_suppliers_with_product_filter` - Find suppliers with product
|
|
|
|
### Routing Endpoints (3 tests)
|
|
- `test_route_to_coordinate` - Multi-hop route from offer to destination
|
|
- `test_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 radius
|
|
- `test_invalid_coordinates` - Invalid lat/lon values
|
|
- `test_nonexistent_uuid` - Non-existent offer UUID
|
|
|
|
**Total: 16 tests covering 8 main endpoints**
|
|
|
|
## Running Tests
|
|
|
|
### Local Testing (against production)
|
|
|
|
```bash
|
|
cd backends/geo
|
|
poetry install
|
|
poetry run pytest tests/test_graphql_endpoints.py -v
|
|
```
|
|
|
|
### Testing against different endpoint
|
|
|
|
```bash
|
|
export TEST_GEO_URL=https://geo-staging.example.com/graphql/public/
|
|
poetry run pytest tests/test_graphql_endpoints.py -v
|
|
```
|
|
|
|
### Run specific test class
|
|
|
|
```bash
|
|
poetry run pytest tests/test_graphql_endpoints.py::TestNearestEndpoints -v
|
|
```
|
|
|
|
### Run single test
|
|
|
|
```bash
|
|
poetry run pytest tests/test_graphql_endpoints.py::TestNearestEndpoints::test_nearest_offers -v
|
|
```
|
|
|
|
### Show print output
|
|
|
|
```bash
|
|
poetry run pytest tests/test_graphql_endpoints.py -v -s
|
|
```
|
|
|
|
## CI Integration
|
|
|
|
Tests should be run on each deployment:
|
|
|
|
```yaml
|
|
# .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 `products` collection
|
|
- 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 `latitude` and `longitude` fields (not null)
|
|
- Correct `node_type` field (`'hub'`, `'offer'`, `'supplier'`)
|
|
|
|
Query ArangoDB directly:
|
|
|
|
```javascript
|
|
// 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/`
|