Skip to content

Commit

Permalink
Add new integration test, integration.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
JCantu248 committed Jan 22, 2025
1 parent 749baff commit 0d15da6
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/integration.yml
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
65 changes: 65 additions & 0 deletions integration/tests/test_domains.py
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"

0 comments on commit 0d15da6

Please sign in to comment.