|
| 1 | +# Entity-API Test Suite |
| 2 | + |
| 3 | +This directory contains all tests for the entity-api service, organized by test type and deployment environment. |
| 4 | + |
| 5 | +## Directory Structure |
| 6 | + |
| 7 | +``` |
| 8 | +test/ |
| 9 | +├── README.md # This file - test suite overview |
| 10 | +├── localhost/ # Tests for localhost Docker deployment |
| 11 | +│ ├── integration/ # Integration tests with hubmap-auth |
| 12 | +│ └── performance/ # Performance benchmarks (future) |
| 13 | +└── [existing test files] # Other test types |
| 14 | +``` |
| 15 | + |
| 16 | +## Test Categories |
| 17 | + |
| 18 | +### Localhost Tests (`localhost/`) |
| 19 | + |
| 20 | +Tests for entity-api running in Docker Desktop for local development and proof-of-concept deployments. |
| 21 | + |
| 22 | +**When to run:** Before pushing changes that affect localhost deployment, Docker configuration, or hubmap-auth integration. |
| 23 | + |
| 24 | +**See:** [localhost/README.md](localhost/README.md) |
| 25 | + |
| 26 | +### Integration Tests (`localhost/integration/`) |
| 27 | + |
| 28 | +End-to-end tests verifying entity-api integrates correctly with hubmap-auth for authorization over the `gateway_hubmap` Docker network. |
| 29 | + |
| 30 | +**See:** [localhost/integration/README.md](localhost/integration/README.md) |
| 31 | + |
| 32 | +### Performance Tests (`localhost/performance/`) - Future |
| 33 | + |
| 34 | +Load testing and performance benchmarks for localhost deployment. |
| 35 | + |
| 36 | +## Quick Start |
| 37 | + |
| 38 | +### Run All Tests |
| 39 | + |
| 40 | +```bash |
| 41 | +# Activate virtual environment |
| 42 | +source .venv/bin/activate |
| 43 | + |
| 44 | +# Run all tests |
| 45 | +python -m unittest discover -s test -v |
| 46 | +``` |
| 47 | + |
| 48 | +### Run Localhost Integration Tests Only |
| 49 | + |
| 50 | +```bash |
| 51 | +source .venv/bin/activate |
| 52 | +python -m unittest discover -s test/localhost/integration -v |
| 53 | +``` |
| 54 | + |
| 55 | +### Prerequisites |
| 56 | + |
| 57 | +1. **Docker containers running:** |
| 58 | + ```bash |
| 59 | + # Start hubmap-auth first |
| 60 | + cd gateway |
| 61 | + ./docker-localhost.sh start |
| 62 | + |
| 63 | + # Then start entity-api |
| 64 | + cd entity-api/docker |
| 65 | + ./docker-localhost.sh start |
| 66 | + |
| 67 | + # Verify both are healthy |
| 68 | + docker ps | grep -E "hubmap-auth|entity-api" |
| 69 | + ``` |
| 70 | + |
| 71 | +2. **Python virtual environment:** |
| 72 | + |
| 73 | + Tests use the same dependencies as the main application: |
| 74 | + |
| 75 | + ```bash |
| 76 | + # Create virtual environment (first time only) |
| 77 | + python3 -m venv .venv |
| 78 | + |
| 79 | + # Activate virtual environment |
| 80 | + source .venv/bin/activate |
| 81 | + |
| 82 | + # Install application dependencies (includes requests) |
| 83 | + pip install -r src/requirements.txt |
| 84 | + ``` |
| 85 | + |
| 86 | +## CI/CD Integration |
| 87 | + |
| 88 | +These tests are designed to run in GitHub Actions or similar CI/CD systems. Example workflow: |
| 89 | + |
| 90 | +```yaml |
| 91 | +name: Entity-API Localhost Integration Tests |
| 92 | + |
| 93 | +on: [push, pull_request] |
| 94 | + |
| 95 | +jobs: |
| 96 | + test: |
| 97 | + runs-on: ubuntu-latest |
| 98 | + steps: |
| 99 | + - uses: actions/checkout@v3 |
| 100 | + |
| 101 | + - name: Checkout gateway repo |
| 102 | + uses: actions/checkout@v3 |
| 103 | + with: |
| 104 | + repository: hubmapconsortium/gateway |
| 105 | + path: gateway |
| 106 | + |
| 107 | + - name: Set up Python |
| 108 | + uses: actions/setup-python@v4 |
| 109 | + with: |
| 110 | + python-version: '3.13' |
| 111 | + |
| 112 | + - name: Create Docker network |
| 113 | + run: docker network create gateway_hubmap |
| 114 | + |
| 115 | + - name: Start hubmap-auth |
| 116 | + run: | |
| 117 | + cd gateway |
| 118 | + ./docker-localhost.sh build |
| 119 | + ./docker-localhost.sh start |
| 120 | + |
| 121 | + - name: Wait for hubmap-auth healthy |
| 122 | + run: timeout 60 bash -c 'until docker ps | grep hubmap-auth | grep healthy; do sleep 2; done' |
| 123 | + |
| 124 | + - name: Start entity-api |
| 125 | + run: | |
| 126 | + cd docker |
| 127 | + ./docker-localhost.sh build |
| 128 | + ./docker-localhost.sh start |
| 129 | + |
| 130 | + - name: Wait for entity-api healthy |
| 131 | + run: timeout 60 bash -c 'until docker ps | grep entity-api | grep healthy; do sleep 2; done' |
| 132 | + |
| 133 | + - name: Install test dependencies |
| 134 | + run: | |
| 135 | + python -m venv .venv |
| 136 | + source .venv/bin/activate |
| 137 | + pip install -r src/requirements.txt |
| 138 | + |
| 139 | + - name: Run integration tests |
| 140 | + run: | |
| 141 | + source .venv/bin/activate |
| 142 | + python -m unittest discover -s test/localhost/integration -v |
| 143 | +``` |
| 144 | +
|
| 145 | +## Contributing |
| 146 | +
|
| 147 | +When adding new tests: |
| 148 | +
|
| 149 | +1. **Choose the right directory** - Place tests in the appropriate subdirectory based on type |
| 150 | +2. **Follow existing patterns** - Match the style and structure of existing tests |
| 151 | +3. **Add documentation** - Update relevant README files |
| 152 | +4. **Keep tests independent** - Each test should run in isolation |
| 153 | +5. **Use descriptive names** - Test names should clearly indicate what they verify |
| 154 | +6. **Handle errors gracefully** - Provide actionable error messages |
| 155 | +
|
| 156 | +## Test Execution Order |
| 157 | +
|
| 158 | +Tests are discovered and run alphabetically by default. If execution order matters: |
| 159 | +
|
| 160 | +1. Use `setUpClass` and `tearDownClass` for class-level setup |
| 161 | +2. Use `setUp` and `tearDown` for test-level setup |
| 162 | +3. Name test files to control discovery order if needed |
| 163 | + |
| 164 | +## Getting Help |
| 165 | + |
| 166 | +- **Test failures:** Check container logs with `docker logs entity-api` |
| 167 | +- **Connection errors:** Verify containers are running with `docker ps` |
| 168 | +- **Import errors:** Ensure virtual environment is activated |
| 169 | +- **Docker issues:** Check Docker Desktop is running |
| 170 | +- **Auth failures:** Verify hubmap-auth is running and healthy |
| 171 | + |
| 172 | +## Related Documentation |
| 173 | + |
| 174 | +- [Entity-API Deployment Guide](../README.md) |
| 175 | +- [Gateway API Endpoints Configuration](../../gateway/api_endpoints.localhost.json) |
| 176 | +- [Docker Compose Configuration](../docker/docker-compose.localhost.yml) |
| 177 | +- [Gateway Test Suite](../../gateway/test/README.md) |
0 commit comments