Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,6 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

demo
demo
allure-reports
allure-results
3 changes: 1 addition & 2 deletions pytest_httpdbg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from pytest_httpdbg.plugin import httpdbg_record_filename # noqa F401

__version__ = "0.9.0"
__version__ = "0.9.1"
7 changes: 4 additions & 3 deletions pytest_httpdbg/plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import glob
import os
import time
Expand Down Expand Up @@ -188,8 +187,10 @@ def get_allure_attachment_type_from_content_type(content_type: str):
try:
import allure

content_type = content_type.split(";", 1)[0].strip()

for attachment_type in allure.attachment_type:
if attachment_type.mime_type == content_type:
if attachment_type.mime_type.lower() == content_type.lower():
return attachment_type
except ImportError:
pass
Expand Down Expand Up @@ -219,7 +220,7 @@ def req_resp_steps(label, req, save_headers, save_binary_payload):
)
if payload:
attachment_type = get_allure_attachment_type_from_content_type(
content.get("content_type")
content.get("content_type", "")
)
allure.attach(
payload, name="payload", attachment_type=attachment_type
Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
pytest_plugins = ["pytester"]
23 changes: 22 additions & 1 deletion tests/test_allure.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
import json

import allure
import pytest

from pytest_httpdbg.plugin import get_allure_attachment_type_from_content_type

confest_py = """
import pytest
import requests
Expand Down Expand Up @@ -431,3 +433,22 @@ def test_binary(httpbin):
sub_steps = step["steps"][0].get("steps")

assert sub_steps is None


@pytest.mark.parametrize(
"content_type, attachment_type",
[
["application/json", allure.attachment_type.JSON],
["application/JSON", allure.attachment_type.JSON],
["application/json;charset=utf-8", allure.attachment_type.JSON],
["application/json ; charset=utf-8", allure.attachment_type.JSON],
[
"application/json;charset=utf-8,application/json;charset=utf-8",
allure.attachment_type.JSON,
],
["image/svg+xml", allure.attachment_type.SVG],
["text/plain", allure.attachment_type.TEXT],
],
)
def test_get_allure_attachment_type_from_content_type(content_type, attachment_type):
assert get_allure_attachment_type_from_content_type(content_type) == attachment_type
1 change: 0 additions & 1 deletion tests/test_plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import glob
import os

Expand Down