-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_csvtools.py
118 lines (102 loc) · 4.33 KB
/
test_csvtools.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
# pylint: disable=missing-docstring,redefined-outer-name,no-self-use,protected-access
import os
from io import StringIO
import pytest
from dump2polarion.exceptions import Dump2PolarionException
from dump2polarion.results import csvtools
from tests import conf
class TestCSVFileldNames:
def test_fieldnames_exported(self):
csv_file = os.path.join(conf.DATA_PATH, "workitems_ids.csv")
with open(csv_file, encoding="utf-8") as input_file:
reader = csvtools._get_csv_reader(input_file)
fieldnames = csvtools._get_csv_fieldnames(reader)
assert fieldnames == [
"id",
"title",
"testcaseid",
"caseimportance",
"verdict",
"comment",
"stdout",
"stderr",
"exported",
"time",
]
def test_fieldnames_unanotated(self):
csv_content = ",,ID,Title,Test Case I D,Caseimportance"
input_file = StringIO(csv_content)
reader = csvtools._get_csv_reader(input_file)
fieldnames = csvtools._get_csv_fieldnames(reader)
input_file.close()
assert fieldnames == ["field1", "field2", "id", "title", "testcaseid", "caseimportance"]
def test_fieldnames_trailing(self):
csv_content = "ID,Title,Test Case I D,Caseimportance,,,"
input_file = StringIO(csv_content)
reader = csvtools._get_csv_reader(input_file)
fieldnames = csvtools._get_csv_fieldnames(reader)
input_file.close()
assert fieldnames == ["id", "title", "testcaseid", "caseimportance"]
def test_fieldnames_missing_id(self):
csv_content = "Title,Test Case I D,Caseimportance,,,"
input_file = StringIO(csv_content)
reader = csvtools._get_csv_reader(input_file)
fieldnames = csvtools._get_csv_fieldnames(reader)
input_file.close()
assert fieldnames is None
class TestCSVTestrunId:
def test_testrun_id_exported(self):
csv_file = os.path.join(conf.DATA_PATH, "workitems_ids.csv")
with open(csv_file, encoding="utf-8") as input_file:
reader = csvtools._get_csv_reader(input_file)
testrun_id = csvtools._get_testrun_from_csv(input_file, reader)
assert testrun_id == "5_8_0_17"
def test_testrun_id_line(self):
csv_content = str(
'Query,"(assignee.id:$[user.id] AND NOT status:inactive AND '
'(TEST_RECORDS:(""RHCF3/5_8_0_17"", @null))) '
'AND project.id:RHCF3",,,,,,,'
)
input_file = StringIO(csv_content)
reader = csvtools._get_csv_reader(input_file)
testrun_id = csvtools._get_testrun_from_csv(input_file, reader)
assert testrun_id == "5_8_0_17"
def test_testrun_id_far(self):
csv_content = str(
"""
,ID,Title,Test Case I D,,,,
,(TEST_RECORDS:(""RHCF3/5_8_0_17"", @null)),,,,,"""
)
input_file = StringIO(csv_content)
reader = csvtools._get_csv_reader(input_file)
testrun_id = csvtools._get_testrun_from_csv(input_file, reader)
assert not testrun_id
class TestCSVImport:
def test_import_orig_data(self):
csv_file = os.path.join(conf.DATA_PATH, "workitems_ids.csv")
data = csvtools.get_imported_data(csv_file)
assert hasattr(data, "results")
assert len(data.results) == 15
assert "id" in data.results[0]
assert hasattr(data, "testrun")
assert data.testrun == "5_8_0_17"
def test_import_no_results(self, tmpdir):
csv_content = "ID,Title,Test Case I D,Caseimportance,,,"
csv_file = tmpdir.join("no_results.csv")
csv_file.write(csv_content)
csv_file_path = str(csv_file)
with pytest.raises(Dump2PolarionException) as excinfo:
csvtools.get_imported_data(csv_file_path)
assert "No results read from CSV file" in str(excinfo.value)
def test_import_and_check_verdict(self, tmpdir):
csv_content = str(
"""
,ID,Title,Test Case I D,,,,
,RH123,,,,,,"""
)
csv_file = tmpdir.join("invalid_fieldnames.csv")
csv_file.write(csv_content)
csv_file_path = str(csv_file)
with pytest.raises(Dump2PolarionException) as excinfo:
csvtools.import_csv(csv_file_path)
assert "missing following columns: Verdict" in str(excinfo.value)