-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new integration test, integration.yml
- Loading branch information
Showing
2 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
name: Integration Testing | ||
|
||
on: | ||
deployment_status: | ||
|
||
defaults: | ||
run: | ||
working-directory: ./integration | ||
|
||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
container: | ||
image: python:3.9 | ||
|
||
strategy: | ||
matrix: | ||
environment: [integration, staging] | ||
|
||
environment: ${{ matrix.environment }} | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Set environment variables | ||
run: | | ||
touch .env | ||
echo "X_API_KEY=${{ secrets['${{ matrix.environment | upper }}\ | ||
_X_API_KEY'] }}" >> .env | ||
echo "DOMAIN_UID=${{ secrets['${{ matrix.environment | upper }}\ | ||
_DOMAIN_UID'] }}" >> .env | ||
echo "SEARCH_IP=${{ secrets['${{ matrix.environment | upper }}\ | ||
_SEARCH_IP'] }}" >> .env | ||
- name: Run integration tests | ||
run: | | ||
pytest -m integration --maxfail=1 --disable-warnings --cov=integration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"""Integration test for domain API.""" | ||
# Standard Python Libraries | ||
import os | ||
|
||
# Third-Party Libraries | ||
import pytest | ||
import requests | ||
|
||
BASE_URL = os.environ.get("BACKEND_DOMAIN") | ||
X_API_KEY = os.environ.get("X_API_KEY") | ||
DOMAIN_ID = os.environ.get("DOMAIN_UID") | ||
|
||
BAD_ID = "01234567-0123-4567-8901-12345" | ||
|
||
|
||
# mark tests with integration tag, run with pytest -m integration | ||
@pytest.mark.integration | ||
def test_get_domain_by_id(): | ||
"""Test get domain by id.""" | ||
url = "{}/domain/{}".format(BASE_URL, DOMAIN_ID) | ||
print(url) | ||
response = requests.get(url, headers={"X-API-KEY": X_API_KEY}, timeout=10) | ||
|
||
assert response.status_code == 200 | ||
data = response.json() | ||
assert data is not None, "Response is empty" | ||
assert data["id"] == DOMAIN_ID | ||
|
||
|
||
@pytest.mark.integration | ||
def test_get_domain_by_id_fails_404(): | ||
"""Test get domain by id fails with 404.""" | ||
url = "{}/domain/{}".format(BASE_URL, BAD_ID) | ||
# Get domain by Id. | ||
response = requests.get(url, headers={"X-API-KEY": X_API_KEY}, timeout=10) | ||
|
||
assert response.status_code == 404 | ||
data = response.json() | ||
assert data is not None, "Response is empty" | ||
assert response.status_code == 404 | ||
|
||
|
||
@pytest.mark.integration | ||
def test_search_domain_by_ip(): | ||
"""Test search domain by IP.""" | ||
url = "{}/domain/search".format(BASE_URL) | ||
json = { | ||
"page": 1, | ||
"filters": { | ||
"ip": os.environ.get("SEARCH_IP"), | ||
"pageSize": 10, | ||
}, | ||
} | ||
response = requests.post( | ||
url, json=json, headers={"X-API-KEY": X_API_KEY}, timeout=10 | ||
) | ||
assert response.status_code == 200 | ||
data = response.json() | ||
assert data is not None, "Response is empty" | ||
assert "result" in data, "Results not found in response" | ||
assert len(data["result"]) > 0, "No results found" | ||
|
||
# Validate result contain the correct IP | ||
for domain in data["result"]: | ||
assert domain["ip"] == os.environ.get("SEARCH_IP"), "IP does not match" |