-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_xunit_exporter.py
152 lines (129 loc) · 6.21 KB
/
test_xunit_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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# pylint: disable=missing-docstring,redefined-outer-name,no-self-use,protected-access
import copy
import os
import pytest
from lxml import etree
from dump2polarion.exceptions import Dump2PolarionException, NothingToDoException
from dump2polarion.exporters.xunit_exporter import ImportedData, XunitExport
from dump2polarion.results.importer import import_results
from dump2polarion.utils import get_unicode_str
from tests import conf
@pytest.fixture(scope="module")
def records_ids():
csv_file = os.path.join(conf.DATA_PATH, "workitems_ids.csv")
return import_results(csv_file)
@pytest.fixture(scope="module")
def records_names():
csv_file = os.path.join(conf.DATA_PATH, "workitems_ids.csv")
records = import_results(csv_file)
for res in records.results:
res.pop("id")
return records
def test_top_element(config_prop, records_ids):
exporter = XunitExport("5_8_0_17", records_ids, config_prop, transform_func=lambda: None)
top_element = exporter._top_element()
parsed = "<testsuites><!--Generated for testrun 5_8_0_17--></testsuites>".strip()
top_element_str = get_unicode_str(etree.tostring(top_element, encoding="utf-8").strip())
assert top_element_str == parsed
class TestConfigPropMixin:
@pytest.fixture(autouse=True)
def base_config_prop(self, config_prop):
self.config_prop = config_prop
class TestProperties(TestConfigPropMixin):
def test_properties_element(self, records_ids):
exporter = XunitExport(
"5_8_0_17", records_ids, self.config_prop, transform_func=lambda: None
)
top_element = exporter._top_element()
properties_element = exporter._properties_element(top_element)
parsed = (
"<properties>"
'<property name="polarion-testrun-id" value="5_8_0_17"/>'
'<property name="polarion-project-id" value="RHCF3"/>'
'<property name="polarion-dry-run" value="False"/>'
'<property name="polarion-response-test" value="test"/>'
'<property name="polarion-testrun-status-id" value="inprogress"/>'
"</properties>".strip()
)
properties_str = get_unicode_str(
etree.tostring(properties_element, encoding="utf-8").strip()
)
assert properties_str == parsed
def test_properties_lookup_config(self, records_names):
new_config = copy.deepcopy(self.config_prop)
new_config["xunit_import_properties"]["polarion-lookup-method"] = "id"
exporter = XunitExport("5_8_0_17", records_names, new_config, transform_func=lambda: None)
top_element = exporter._top_element()
properties_element = exporter._properties_element(top_element)
exporter._fill_lookup_prop(properties_element)
properties_str = get_unicode_str(
etree.tostring(properties_element, encoding="utf-8").strip()
)
assert '<property name="polarion-lookup-method" value="id"/>' in properties_str
def test_properties_invalid_lookup(self, records_ids):
new_config = copy.deepcopy(self.config_prop)
new_config["xunit_import_properties"]["polarion-lookup-method"] = "invalid"
exporter = XunitExport("5_8_0_17", records_ids, new_config)
with pytest.raises(Dump2PolarionException) as excinfo:
exporter.export()
assert "Invalid value 'invalid' for the 'polarion-lookup-method'" in str(excinfo.value)
class TestE2E(TestConfigPropMixin):
def test_e2e_noresults(self, records_ids):
exporter = XunitExport(
"5_8_0_17", records_ids, self.config_prop, transform_func=lambda arg: None
)
with pytest.raises(NothingToDoException) as excinfo:
exporter.export()
assert "Nothing to export" in str(excinfo.value)
def test_e2e_missing_results(self):
new_records = ImportedData(results=[], testrun=None)
exporter = XunitExport(
"5_8_0_17", new_records, self.config_prop, transform_func=lambda arg: arg
)
with pytest.raises(NothingToDoException) as excinfo:
exporter._fill_tests_results(None)
assert "Nothing to export" in str(excinfo.value)
def test_e2e_all_ignored(self, captured_log):
new_records = ImportedData(
results=[{"title": "foo", "id": "foo", "verdict": "waiting", "ignored": True}],
testrun=None,
)
exporter = XunitExport(
"5_8_0_17", new_records, self.config_prop, transform_func=lambda arg: arg
)
with pytest.raises(NothingToDoException) as excinfo:
exporter.export()
assert "Nothing to export" in str(excinfo.value)
assert "Skipping ignored testcase" in captured_log.getvalue()
def test_e2e_ids_notransform(self, records_ids):
exporter = XunitExport(
"5_8_0_17", records_ids, self.config_prop, transform_func=lambda arg: arg
)
complete = exporter.export()
fname = "complete_notransform.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_e2e_ids_transform(self, records_ids):
exporter = XunitExport("5_8_0_17", records_ids, self.config_prop)
complete = exporter.export()
fname = "complete_transform.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_e2e_names_notransform(self, records_names):
exporter = XunitExport(
"5_8_0_17", records_names, self.config_prop, transform_func=lambda arg: arg
)
complete = exporter.export()
fname = "complete_notransform_name.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_e2e_names_transform(self, records_names):
exporter = XunitExport("5_8_0_17", records_names, self.config_prop)
complete = exporter.export()
fname = "complete_transform_name.xml"
with open(os.path.join(conf.DATA_PATH, fname), encoding="utf-8") as input_xml:
parsed = input_xml.read()
assert complete == parsed