Skip to content
This repository was archived by the owner on Jun 2, 2026. It is now read-only.

Commit afe4034

Browse files
committed
integration test
1 parent 48fb63f commit afe4034

6 files changed

Lines changed: 48 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ jobs:
7979
pipenv requirements --dev > reqs.txt
8080
pip install -r reqs.txt
8181
82-
- name: Run unit tests
82+
- name: Run e2e tests
8383
run: |
84-
python example.py
84+
make test-e2e

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ test:
1515
python -m pytest --cov; \
1616
fi
1717

18+
test-e2e: export DD_INTEGRATION_TESTS=1
19+
test-e2e:
20+
python -m pytest tests/integration
21+
1822
testpub:
1923
rm -fr dist
2024
pyproject-build

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ line-ending = "auto"
5151

5252
[tool.pytest.ini_options]
5353
minversion = "6.0"
54-
addopts = "-ra -q --disable-socket"
54+
addopts = "-ra -q --disable-socket --allow-hosts=127.0.0.1"
5555
testpaths = [
5656
"tests",
5757
]

support/integration/run_dojo.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ echo "Waiting for service to be ready at $SERVICE_URL..."
1919

2020
SECONDS=0
2121
while (( SECONDS < TIMEOUT )); do
22-
STATUS=$(curl -s -o /dev/null -Lw "%{http_code}" "$SERVICE_URL" || true)
22+
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$SERVICE_URL/api/v2/api-token-auth/" -d username=admin -d password=admin || true)
2323
if [[ "$STATUS" == "200" ]]; then
2424
echo "Service is ready!"
2525
exit 0

tests/integration/test_e2e.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import os
2+
import subprocess
3+
import unittest
4+
import uuid
5+
from pathlib import Path
6+
7+
import defectdojo_api_generated
8+
from defectdojo_api_generated import DefectDojo
9+
from defectdojo_api_generated.models.product_request import ProductRequest
10+
from defectdojo_api_generated.models.product_type_request import ProductTypeRequest
11+
12+
DOJO_SCRIPTS = Path(__file__).parent.parent.parent / 'support' / 'integration'
13+
14+
15+
@unittest.skipUnless(os.getenv('DD_INTEGRATION_TESTS'), 'Integration tests not enabled')
16+
class Test(unittest.TestCase):
17+
@classmethod
18+
def setUpClass(cls):
19+
subprocess.check_call([DOJO_SCRIPTS / 'run_dojo.sh'])
20+
21+
@classmethod
22+
def tearDownClass(cls):
23+
subprocess.check_call([DOJO_SCRIPTS / 'stop_dojo.sh'])
24+
25+
def client(self, url='http://127.0.0.1:8080', user='admin', password='admin'):
26+
return DefectDojo(base_url=url, auth=(user, password))
27+
28+
def test_login(self):
29+
c = self.client(password='wrong')
30+
with self.assertRaises(defectdojo_api_generated.exceptions.ForbiddenException):
31+
c.user_profile_api.user_profile_retrieve()
32+
33+
def test_init(self):
34+
c = self.client()
35+
uniq = str(uuid.uuid4())
36+
pt = c.product_types_api.product_types_create(product_type_request=ProductTypeRequest(name=f'Test {uniq}'))
37+
c.products_api.products_create(
38+
product_request=ProductRequest(name=f'Product {uniq}', description='test', prod_type=pt.id)
39+
)
40+
# TODO: do e2e test for importing a report - just call reimport with a sample report and assert findings

0 commit comments

Comments
 (0)