-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_testcase_exporter.py
127 lines (111 loc) · 4.87 KB
/
test_testcase_exporter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# pylint: disable=missing-docstring,redefined-outer-name,no-self-use,protected-access
import copy
import os
from collections import OrderedDict
import pytest
from dump2polarion.exceptions import Dump2PolarionException, NothingToDoException
from dump2polarion.exporters.testcases_exporter import TestcaseExport
from tests import conf
REQ_DATA = [
OrderedDict(
(
("id", "ITEM01"),
("title", "test_manual"),
("description", "Manual tests with many supported fields."),
("approver-ids", "mkourim:approved"),
("assignee-id", "mkourim"),
("due-date", "2018-09-30"),
("initial-estimate", "1/4h"),
("caseautomation", "manualonly"),
("caseimportance", "high"),
("caselevel", 2),
("caseposneg", "positive"),
("testtype", "functional"),
("subtype1", "-"),
("subtype2", "-"),
("upstream", "yes"),
("tags", "tag1, tag2"),
("setup", "Do this first"),
("teardown", "Clean up"),
("automation_script", "file#L83"),
("testSteps", ["step1", "step2"]),
("expectedResults", ["result1", "result2"]),
("linked-items", "ITEM01"),
("unknown", "non-included"),
)
),
OrderedDict(
(
("title", "test_minimal_param"),
("params", ["param1", "param2"]),
("linked-items-lookup-method", "name"),
("linked-items", [{"id": "ITEM01", "role": "derived_from"}]),
("automation_script", "https://github.com/somerepo/blob/somebranch/file#L83"),
)
),
]
@pytest.fixture(scope="module")
def config_cloudtp(config_prop):
cloudtp = copy.deepcopy(config_prop)
cloudtp["polarion-project-id"] = "CLOUDTP"
cloudtp["testcase_import_properties"] = {"prop1": "val1", "prop2": "val2"}
return cloudtp
@pytest.fixture(scope="module")
def config_with_fields(config_prop):
config_fields = copy.deepcopy(config_prop)
config_fields["default_fields"] = {"caseimportance": "medium", "startsin": "5.10"}
config_fields["custom_fields"] = ["caseimportance", "startsin", "testtype"]
return config_fields
class TestTestcase:
def test_export_cloudtp(self, config_cloudtp):
testcase_exp = TestcaseExport(REQ_DATA, config_cloudtp)
complete = testcase_exp.export()
fname = "testcase_complete_cloudtp.xml"
with open(os.path.join(conf.DATA_PATH, fname), encoding="utf-8") as input_xml:
parsed = input_xml.read()
assert complete == parsed
def test_export_cfme(self, config_prop):
testcase_exp = TestcaseExport(REQ_DATA, config_prop)
complete = testcase_exp.export()
fname = "testcase_complete_cfme.xml"
with open(os.path.join(conf.DATA_PATH, fname), encoding="utf-8") as input_xml:
parsed = input_xml.read()
assert complete == parsed
def test_export_fields_cfme(self, config_with_fields):
testcase_exp = TestcaseExport(REQ_DATA, config_with_fields)
complete = testcase_exp.export()
fname = "testcase_fields_cfme.xml"
with open(os.path.join(conf.DATA_PATH, fname), encoding="utf-8") as input_xml:
parsed = input_xml.read()
assert complete == parsed
def test_export_cfme_params(self, config_prop):
new_config = copy.deepcopy(config_prop)
new_config["cfme_parametrize"] = True
testcase_exp = TestcaseExport(REQ_DATA, new_config)
complete = testcase_exp.export()
fname = "testcase_complete_cfme_param.xml"
with open(os.path.join(conf.DATA_PATH, fname), encoding="utf-8") as input_xml:
parsed = input_xml.read()
assert complete == parsed
def test_invalid_lookup(self, config_cloudtp):
new_config = copy.deepcopy(config_cloudtp)
new_config["testcase_import_properties"] = {"lookup-method": "inv"}
testcase_exp = TestcaseExport(REQ_DATA, new_config)
with pytest.raises(Dump2PolarionException) as excinfo:
testcase_exp.export()
assert "Invalid value 'inv' for the 'lookup-method' property" in str(excinfo.value)
def test_no_requirements(self, config_cloudtp):
testcase_exp = TestcaseExport([], config_cloudtp)
with pytest.raises(NothingToDoException) as excinfo:
testcase_exp.export()
assert "Nothing to export" in str(excinfo.value)
def test_all_ignored(self, config_cloudtp, captured_log):
testcase_exp = TestcaseExport(
[{"id": "foo", "title": "foo", "ignored": True}],
config_cloudtp,
transform_func=lambda arg: arg,
)
with pytest.raises(NothingToDoException) as excinfo:
testcase_exp.export()
assert "Nothing to export" in str(excinfo.value)
assert "Skipping ignored node:" in captured_log.getvalue()