1
1
from functools import partial
2
2
from hamcrest import assert_that , contains_string
3
3
from hamcrest import not_
4
+ from hamcrest import equal_to
5
+ from allure_commons .types import AttachmentType
4
6
from allure_commons_test .report import has_test_case
5
7
from allure_commons_test .result import with_status
6
8
from allure_commons_test .result import has_step
7
9
from allure_commons_test .result import has_attachment
10
+ from allure_commons_test .result import has_attachment_with_content
8
11
from allure_commons_test .result import has_parameter
9
12
from allure_commons_test .result import has_status_details
10
13
from allure_commons_test .result import with_message_contains
11
14
from allure_commons_test .result import has_link
12
15
from allure_commons_test .result import has_description
13
16
from allure_commons_test .container import has_container
14
17
from allure_commons_test .container import has_before , has_after
18
+ from allure_commons_test .content import csv_equivalent
15
19
from allure_commons_test .label import has_severity
16
20
from allure_commons_test .label import has_tag
17
21
from allure_commons_test .label import has_label
@@ -152,8 +156,38 @@ def step_attachment(context, item):
152
156
assert_that (context .allure_report , matcher ())
153
157
154
158
159
+ @then ('this {item} has attachment "{name}" with the following data' )
160
+ def step_attachment_data (context , item , name ):
161
+ context_matcher = getattr (context , item )
162
+ attachment_type , content_matcher = _get_attachment_type_and_matcher (context )
163
+ matcher = partial (
164
+ context_matcher ,
165
+ partial (
166
+ has_attachment_with_content ,
167
+ context .allure_report .attachments ,
168
+ content_matcher ,
169
+ attachment_type .mime_type ,
170
+ name
171
+ )
172
+ )
173
+ assert_that (context .allure_report , matcher ())
174
+
175
+
155
176
@then ('scenario has description "{description}"' )
156
177
def step_description (context , description ):
157
178
context_matcher = context .scenario
158
179
matcher = partial (context_matcher , has_description , contains_string (description ))
159
180
assert_that (context .allure_report , matcher ())
181
+
182
+ def _get_attachment_type_and_matcher (context ):
183
+ return (
184
+ AttachmentType .CSV ,
185
+ csv_equivalent (
186
+ [context .table .headings ] + [
187
+ r .cells for r in context .table .rows
188
+ ]
189
+ )
190
+ ) if context .table is not None else (
191
+ AttachmentType .TEXT ,
192
+ equal_to (context .text )
193
+ )
0 commit comments