Skip to content

Commit 08e903d

Browse files
committed
added new fixture to have less code in individual tests
1 parent f52a70e commit 08e903d

File tree

2 files changed

+69
-62
lines changed

2 files changed

+69
-62
lines changed

tests/conftest.py

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pytest
22

3+
from jira_dump import Dumper
4+
35

46
@pytest.fixture
57
def patch_jira(monkeypatch):
@@ -12,27 +14,39 @@ def __init__(self, *args, **kwargs):
1214
pass
1315

1416
def _get_json(self, path, params, base):
15-
with open('./test_data/sample_sla.json', mode='r', encoding='utf-8') as file:
17+
with open(
18+
"./test_data/sample_sla.json", mode="r", encoding="utf-8"
19+
) as file:
1620
test_sla = json.loads(file.read())
1721

1822
return test_sla
1923

2024
def worklogs(self, issue):
21-
with open('./test_data/sample_worklog.json', mode='r', encoding='utf-8') as file:
25+
with open(
26+
"./test_data/sample_worklog.json", mode="r", encoding="utf-8"
27+
) as file:
2228
raw_worklog = json.loads(file.read())
2329
test_worklog = Worklog(options=None, session=None, raw=raw_worklog)
2430

2531
return [test_worklog] * 10
2632

2733
def search_issues(self, *args, **kwargs):
2834
_ = args, self
29-
if kwargs['startAt'] > 0:
35+
if kwargs["startAt"] > 0:
3036
return []
3137

32-
with open('./test_data/sample_issue.json', mode='r', encoding='utf-8') as file:
38+
with open(
39+
"./test_data/sample_issue.json", mode="r", encoding="utf-8"
40+
) as file:
3341
raw_issue = json.loads(file.read())
3442
test_issue = Issue(options=None, session=None, raw=raw_issue)
3543

3644
return [test_issue]
3745

38-
monkeypatch.setattr(jira, 'JIRA', MockJIRA)
46+
monkeypatch.setattr(jira, "JIRA", MockJIRA)
47+
48+
49+
@pytest.fixture
50+
def dumper(patch_jira):
51+
with Dumper(server="https://jira.server.com") as _dumper:
52+
yield _dumper

tests/test_base.py

+50-57
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
from jira_dump.base import dict_value, get_fields, extract_dict
77

88

9-
def test_dumper_basic(patch_jira):
10-
with Dumper(server="https://jira.server.com") as dumper:
11-
issues = list(dumper.issues)
12-
assert len(issues) == 1
9+
def test_dumper_basic(dumper):
10+
issues = list(dumper.issues)
11+
assert len(issues) == 1
1312

14-
issue = issues[0]
15-
assert issue["status"] == "Running automatic tests"
16-
assert issue["issue"] == "TEST-42"
13+
issue = issues[0]
14+
assert issue["status"] == "Running automatic tests"
15+
assert issue["issue"] == "TEST-42"
1716

1817

1918
def test_subclassing(patch_jira):
@@ -56,72 +55,66 @@ def test_extract_dict():
5655
assert parsed_issue["c"] == "b"
5756

5857

59-
def test_worklogs(patch_jira):
60-
with Dumper(server="https://jira.server.com") as dumper:
61-
worklogs = list(dumper.worklogs)
58+
def test_worklogs(dumper):
59+
worklogs = list(dumper.worklogs)
6260

63-
assert len(worklogs) == 10
64-
assert worklogs[0]["author"] == "john.doe"
65-
assert sorted(worklogs[0].keys()) == [
66-
"author",
67-
"comment",
68-
"issue",
69-
"started",
70-
"time_spent",
71-
]
61+
assert len(worklogs) == 10
62+
assert worklogs[0]["author"] == "john.doe"
63+
assert sorted(worklogs[0].keys()) == [
64+
"author",
65+
"comment",
66+
"issue",
67+
"started",
68+
"time_spent",
69+
]
7270

7371

74-
def test_transitions(patch_jira):
75-
with Dumper(server="https://jira.server.com") as dumper:
76-
transitions = list(dumper.transitions)
72+
def test_transitions(dumper):
73+
transitions = list(dumper.transitions)
7774

78-
assert len(transitions) == 3
75+
assert len(transitions) == 3
7976

80-
transition = transitions[0]
81-
assert transition["author"] == "[email protected]"
82-
assert list(transition.keys()) == ["author", "created", "from", "to", "issue"]
77+
transition = transitions[0]
78+
assert transition["author"] == "[email protected]"
79+
assert list(transition.keys()) == ["author", "created", "from", "to", "issue"]
8380

8481

85-
def test_comments(patch_jira):
86-
with Dumper(server="https://jira.server.com") as dumper:
87-
comments = list(dumper.comments)
82+
def test_comments(dumper):
83+
comments = list(dumper.comments)
8884

89-
assert len(comments) == 1
85+
assert len(comments) == 1
9086

91-
comment = comments[0]
92-
assert comment["author"] == "[email protected]"
93-
assert sorted(list(comment.keys())) == sorted(
94-
["author", "created", "body", "issue"]
95-
)
87+
comment = comments[0]
88+
assert comment["author"] == "[email protected]"
89+
assert sorted(list(comment.keys())) == sorted(
90+
["author", "created", "body", "issue"]
91+
)
9692

9793

98-
def test_fix_versions(patch_jira):
99-
with Dumper(server="https://jira.server.com") as dumper:
100-
fix_versions = list(dumper.fix_versions)
94+
def test_fix_versions(dumper):
95+
fix_versions = list(dumper.fix_versions)
10196

102-
assert len(fix_versions) == 1
97+
assert len(fix_versions) == 1
10398

104-
fix_version = fix_versions[0]
105-
assert fix_version["name"] == "RELEASE_05"
106-
assert sorted(list(fix_version.keys())) == sorted(
107-
["description", "name", "release_date", "issue"]
108-
)
99+
fix_version = fix_versions[0]
100+
assert fix_version["name"] == "RELEASE_05"
101+
assert sorted(list(fix_version.keys())) == sorted(
102+
["description", "name", "release_date", "issue"]
103+
)
109104

110105

111-
def test_sla_overview(patch_jira):
112-
with Dumper(server="https://jira.server.com") as dumper:
113-
sla_overview = list(dumper.sla_overview)
106+
def test_sla_overview(dumper):
107+
sla_overview = list(dumper.sla_overview)
114108

115-
assert len(sla_overview) == 2
109+
assert len(sla_overview) == 2
116110

117-
sla = sla_overview[0]
118-
assert sla["status"] == "SUCCESS"
111+
sla = sla_overview[0]
112+
assert sla["status"] == "SUCCESS"
119113

120114

121-
def test_dataframes(patch_jira):
122-
with Dumper(server="https://jira.server.com") as dumper:
123-
for name, object_ in inspect.getmembers(Dumper):
124-
if "__" not in name and inspect.isdatadescriptor(object_):
125-
df = pd.DataFrame(getattr(dumper, name))
126-
assert "issue" in df.columns
127-
assert len(df) > 0
115+
def test_dataframes(dumper):
116+
for name, object_ in inspect.getmembers(Dumper):
117+
if "__" not in name and inspect.isdatadescriptor(object_):
118+
df = pd.DataFrame(getattr(dumper, name))
119+
assert "issue" in df.columns
120+
assert len(df) > 0

0 commit comments

Comments
 (0)