11from functools import partial
22from hamcrest import assert_that , contains_string
33from hamcrest import not_
4+ from hamcrest import equal_to
5+ from allure_commons .types import AttachmentType
46from allure_commons_test .report import has_test_case
57from allure_commons_test .result import with_status
68from allure_commons_test .result import has_step
79from allure_commons_test .result import has_attachment
10+ from allure_commons_test .result import has_attachment_with_content
811from allure_commons_test .result import has_parameter
912from allure_commons_test .result import has_status_details
1013from allure_commons_test .result import with_message_contains
1114from allure_commons_test .result import has_link
1215from allure_commons_test .result import has_description
1316from allure_commons_test .container import has_container
1417from allure_commons_test .container import has_before , has_after
18+ from allure_commons_test .content import csv_equivalent
1519from allure_commons_test .label import has_severity
1620from allure_commons_test .label import has_tag
1721from allure_commons_test .label import has_label
@@ -152,8 +156,38 @@ def step_attachment(context, item):
152156 assert_that (context .allure_report , matcher ())
153157
154158
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+
155176@then ('scenario has description "{description}"' )
156177def step_description (context , description ):
157178 context_matcher = context .scenario
158179 matcher = partial (context_matcher , has_description , contains_string (description ))
159180 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