-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add pytest and build details unit tests
- Added pytest - Added pytest-django (not being used for now) - Run tests before pushing - Updated the existing unit tests to use pytest instead of unittest - Added utilities to perform django 'external' unit tests - Added tests for BuildDetailsView as an example for the other django tests to be performed Part of #943
- Loading branch information
Showing
9 changed files
with
164 additions
and
50 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
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,21 @@ | ||
from kernelCI_app.utils import string_to_json | ||
from kernelCI_app.unitTests.utils.utils import online | ||
from kernelCI_app.unitTests.utils.kernelCIClient import KernelCIClient | ||
import pytest | ||
|
||
|
||
@online | ||
@pytest.mark.parametrize( | ||
"build_id, status_code, has_error_body", | ||
[ | ||
("maestro:67b62592f7707533c0ff7a95", 200, False), | ||
("invalid_id", 200, True), | ||
], | ||
) | ||
def test_get(build_id, status_code, has_error_body): | ||
client = KernelCIClient() | ||
response = client.get_build_details(build_id) | ||
content = string_to_json(response.content.decode()) | ||
assert response.status_code == status_code | ||
if has_error_body: | ||
assert "error" in content |
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,31 @@ | ||
from kernelCI_app.helpers.filters import should_filter_test_issue | ||
from kernelCI_app.constants.general import UNCATEGORIZED_STRING | ||
|
||
|
||
class TestShouldFilterTestIssue: | ||
def test_no_issue_filters(self): | ||
assert not should_filter_test_issue( | ||
issue_filters=set(), | ||
issue_id=UNCATEGORIZED_STRING, | ||
issue_version=None, | ||
incident_test_id="incident_test_1", | ||
test_status="FAIL", | ||
) | ||
|
||
def test_unknown_filter_with_exclusively_build_issue(self): | ||
assert should_filter_test_issue( | ||
issue_filters={UNCATEGORIZED_STRING}, | ||
issue_id="issue1", | ||
issue_version=1, | ||
incident_test_id="incident_test_1", | ||
test_status="PASS", | ||
) | ||
|
||
def test_unknown_issue_but_not_from_test(self): | ||
assert not should_filter_test_issue( | ||
issue_filters={UNCATEGORIZED_STRING}, | ||
issue_id="maestro:72697a4efbbd0eff7080781839b405bbf0902f79", | ||
issue_version=0, | ||
incident_test_id=None, | ||
test_status="FAIL", | ||
) |
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
import requests | ||
import urllib.parse | ||
|
||
from django.urls import reverse | ||
|
||
|
||
class KernelCIClient: | ||
base = "http://localhost:8000/" | ||
|
||
def get_endpoint(self, path) -> str: | ||
return urllib.parse.urljoin(self.base, path) | ||
|
||
def get_build_details(self, build_id: str) -> requests.Response: | ||
path = reverse("buildDetails", kwargs={"build_id": build_id}) | ||
url = self.get_endpoint(path) | ||
return requests.get(url) |
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,15 @@ | ||
import subprocess | ||
import pytest | ||
|
||
|
||
def ping(host: str) -> bool: | ||
""" | ||
Checks if a host is online using the Linux 'ping' command. | ||
Note: This function does not currently support Windows. | ||
""" | ||
param = "-c" | ||
command = ["ping", param, "1", host] | ||
return subprocess.call(command) == 0 | ||
|
||
|
||
online = pytest.mark.skipif(not ping("localhost"), reason="Server is not online") |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#!/usr/bin/env sh | ||
|
||
#TODO: pre-pushes python test | ||
poetry run pytest | ||
TEST_STATUS=$? | ||
exit $TEST_STATUS |
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