Skip to content

Commit 52fde1d

Browse files
Added unit tests for JiraConfluenceUtil
1 parent 32abd17 commit 52fde1d

File tree

7 files changed

+104
-1
lines changed

7 files changed

+104
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
header,value
2+
"test","this is a test file"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<title>Test</title>
6+
</head>
7+
8+
<body>This is a test file.</body>
9+
10+
</html>
423 Bytes
Loading
286 Bytes
Binary file not shown.
423 Bytes
Loading
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import pytest
2+
import os
3+
from pathlib import Path
4+
from utils.jira_confluence_util import JiraConfluenceUtil
5+
6+
7+
pytestmark = [pytest.mark.utils]
8+
9+
TEST_RESULTS_DIR = (
10+
Path(__file__).parent.joinpath("resources").joinpath("jira-util-test-dir")
11+
)
12+
13+
14+
@pytest.fixture(autouse=True)
15+
def set_env_vars(monkeypatch) -> None:
16+
monkeypatch.setattr("dotenv.load_dotenv", lambda *a, **kw: None)
17+
applicable_vars = [
18+
"JIRA_URL",
19+
"JIRA_PROJECT_KEY",
20+
"JIRA_API_KEY",
21+
"CONFLUENCE_URL",
22+
"CONFLUENCE_API_KEY",
23+
]
24+
for var in applicable_vars:
25+
os.environ[var] = "test"
26+
27+
28+
def test_check_init() -> None:
29+
"""Check initialization works as intended"""
30+
test_init = JiraConfluenceUtil(TEST_RESULTS_DIR)
31+
assert isinstance(test_init, JiraConfluenceUtil)
32+
33+
with pytest.raises(ValueError):
34+
JiraConfluenceUtil("a/fake/directory")
35+
36+
37+
def test_can_complete_jira_actions_check(monkeypatch: object) -> None:
38+
"""Test that errors occur when env values not set for Jira"""
39+
applicable_vars = ["JIRA_URL", "JIRA_PROJECT_KEY", "JIRA_API_KEY"]
40+
# monkeypatch.setattr("dotenv.load_dotenv", lambda *a, **kw: None)
41+
42+
for expected_var in applicable_vars:
43+
test_util = JiraConfluenceUtil(TEST_RESULTS_DIR)
44+
for var in applicable_vars:
45+
os.environ[var] = "test"
46+
os.environ.pop(expected_var, None)
47+
with pytest.raises(ValueError) as e:
48+
test_util._can_complete_jira_actions_check()
49+
assert (
50+
str(e.value)
51+
== f"The [{expected_var}] os environment variable is required to complete any Jira actions"
52+
)
53+
54+
55+
def test_can_complete_confluence_actions_check(monkeypatch: object) -> None:
56+
"""Test that errors occur when env values not set for Confluence"""
57+
applicable_vars = ["CONFLUENCE_URL", "CONFLUENCE_API_KEY"]
58+
# monkeypatch.setattr("dotenv.load_dotenv", lambda *a, **kw: None)
59+
60+
for expected_var in applicable_vars:
61+
test_util = JiraConfluenceUtil(TEST_RESULTS_DIR)
62+
for var in applicable_vars:
63+
os.environ[var] = "test"
64+
os.environ.pop(expected_var, None)
65+
with pytest.raises(ValueError) as e:
66+
test_util._can_complete_confluence_actions_check()
67+
assert (
68+
str(e.value)
69+
== f"The [{expected_var}] os environment variable is required to complete any Confluence actions"
70+
)
71+
72+
73+
def test_get_files_to_upload_to_jira() -> None:
74+
"""Test that valid Jira reference checks work"""
75+
test_util = JiraConfluenceUtil(TEST_RESULTS_DIR)
76+
results_list = test_util._get_files_to_upload_to_jira(True, True, True, True)
77+
# Get all paths
78+
path_list = []
79+
for item in results_list:
80+
path_list.append(item["path"])
81+
# Get all test files
82+
test_files = [
83+
TEST_RESULTS_DIR.joinpath("report.html"),
84+
TEST_RESULTS_DIR.joinpath("test_image.png"),
85+
TEST_RESULTS_DIR.joinpath("csv_test.csv"),
86+
TEST_RESULTS_DIR.joinpath("screenshot/test_image_b.png"),
87+
TEST_RESULTS_DIR.joinpath("test-sub-dir/trace.zip"),
88+
]
89+
assert len(path_list) == len(test_files)
90+
for test_file in test_files:
91+
assert test_file in path_list

utils/axe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
logger = logging.getLogger(__name__)
9-
PATH_FOR_REPORT = Path(os.getcwd()) / "axe-reports"
9+
PATH_FOR_REPORT = str(Path(os.getcwd()) / "axe-reports")
1010

1111

1212
class Axe():

0 commit comments

Comments
 (0)