diff --git a/.gitignore b/.gitignore index 56dee3c..7608e00 100644 --- a/.gitignore +++ b/.gitignore @@ -159,4 +159,6 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ -demo \ No newline at end of file +demo +allure-reports +allure-results \ No newline at end of file diff --git a/pytest_httpdbg/__init__.py b/pytest_httpdbg/__init__.py index a03ee97..85bde42 100644 --- a/pytest_httpdbg/__init__.py +++ b/pytest_httpdbg/__init__.py @@ -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" diff --git a/pytest_httpdbg/plugin.py b/pytest_httpdbg/plugin.py index c5ed55a..77da088 100644 --- a/pytest_httpdbg/plugin.py +++ b/pytest_httpdbg/plugin.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import glob import os import time @@ -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 @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index d7afc77..c6481d5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,2 +1 @@ -# -*- coding: utf-8 -*- pytest_plugins = ["pytester"] diff --git a/tests/test_allure.py b/tests/test_allure.py index 34beef0..2d9342a 100644 --- a/tests/test_allure.py +++ b/tests/test_allure.py @@ -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 @@ -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 diff --git a/tests/test_plugin.py b/tests/test_plugin.py index bac60dc..0aaf97d 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import glob import os