Skip to content

Commit 26c4368

Browse files
authored
improve allure attachment type detection (#18)
1 parent b306b32 commit 26c4368

File tree

6 files changed

+30
-9
lines changed

6 files changed

+30
-9
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,6 @@ cython_debug/
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161161

162-
demo
162+
demo
163+
allure-reports
164+
allure-results

pytest_httpdbg/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
from pytest_httpdbg.plugin import httpdbg_record_filename # noqa F401
32

4-
__version__ = "0.9.0"
3+
__version__ = "0.9.1"

pytest_httpdbg/plugin.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import glob
32
import os
43
import time
@@ -188,8 +187,10 @@ def get_allure_attachment_type_from_content_type(content_type: str):
188187
try:
189188
import allure
190189

190+
content_type = content_type.split(";", 1)[0].strip()
191+
191192
for attachment_type in allure.attachment_type:
192-
if attachment_type.mime_type == content_type:
193+
if attachment_type.mime_type.lower() == content_type.lower():
193194
return attachment_type
194195
except ImportError:
195196
pass
@@ -219,7 +220,7 @@ def req_resp_steps(label, req, save_headers, save_binary_payload):
219220
)
220221
if payload:
221222
attachment_type = get_allure_attachment_type_from_content_type(
222-
content.get("content_type")
223+
content.get("content_type", "")
223224
)
224225
allure.attach(
225226
payload, name="payload", attachment_type=attachment_type

tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# -*- coding: utf-8 -*-
21
pytest_plugins = ["pytester"]

tests/test_allure.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# -*- coding: utf-8 -*-
21
import json
32

3+
import allure
44
import pytest
55

6+
from pytest_httpdbg.plugin import get_allure_attachment_type_from_content_type
7+
68
confest_py = """
79
import pytest
810
import requests
@@ -431,3 +433,22 @@ def test_binary(httpbin):
431433
sub_steps = step["steps"][0].get("steps")
432434

433435
assert sub_steps is None
436+
437+
438+
@pytest.mark.parametrize(
439+
"content_type, attachment_type",
440+
[
441+
["application/json", allure.attachment_type.JSON],
442+
["application/JSON", allure.attachment_type.JSON],
443+
["application/json;charset=utf-8", allure.attachment_type.JSON],
444+
["application/json ; charset=utf-8", allure.attachment_type.JSON],
445+
[
446+
"application/json;charset=utf-8,application/json;charset=utf-8",
447+
allure.attachment_type.JSON,
448+
],
449+
["image/svg+xml", allure.attachment_type.SVG],
450+
["text/plain", allure.attachment_type.TEXT],
451+
],
452+
)
453+
def test_get_allure_attachment_type_from_content_type(content_type, attachment_type):
454+
assert get_allure_attachment_type_from_content_type(content_type) == attachment_type

tests/test_plugin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import glob
32
import os
43

0 commit comments

Comments
 (0)