Skip to content

Commit

Permalink
Add test case for get vulnerability when no record is found, resultin…
Browse files Browse the repository at this point in the history
…g in a 404.
  • Loading branch information
JCantu248 committed Nov 15, 2024
1 parent 32400cd commit c4b30d4
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions backend/src/xfd_django/xfd_api/tests/test_vulnerabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
client = TestClient(app)

test_id = "c0effe93-3647-475a-a0c5-0b629c348588"
bad_id = "c0effe93-3647-475a-a0c5-0b629c348590"
filters = {
"id": "d39a8536-0b64-45b6-b621-5d954329221c",
"title": "DNS Twist Domains",
Expand Down Expand Up @@ -53,6 +54,27 @@ def test_get_vulnerability_by_id():
assert data["id"] == test_id


@pytest.mark.django_db(transaction=True)
def test_get_vulnerability_by_id_not_found():
# Get error 404 if vulnerability does not exist

user = User.objects.create(
firstName="",
lastName="",
email=f"{secrets.token_hex(4)}@example.com",
userType=UserType.GLOBAL_ADMIN,
createdAt=datetime.now(),
updatedAt=datetime.now(),
)

response = client.get(
f"/vulnerabilities/{bad_id}",
headers={"Authorization": "Bearer " + create_jwt_token(user)},
)

assert response.status_code == 404


@pytest.mark.django_db(transaction=True)
def test_search_vulnerabilities_id():
# Search vulnerabilities by ip.
Expand Down

0 comments on commit c4b30d4

Please sign in to comment.