|
1 | 1 | import pytest
|
2 | 2 | from .get_body_data_type import get_body_data_type
|
| 3 | +from ..helpers.headers import Headers |
3 | 4 |
|
4 | 5 |
|
5 | 6 | def test_get_body_data_type():
|
6 |
| - assert get_body_data_type({"CONTENT_TYPE": "application/json"}) == "json" |
7 |
| - assert get_body_data_type({"CONTENT_TYPE": "application/vnd.api+json"}) == "json" |
8 |
| - assert get_body_data_type({"CONTENT_TYPE": "application/csp-report"}) == "json" |
9 |
| - assert get_body_data_type({"CONTENT_TYPE": "application/x-json"}) == "json" |
10 |
| - assert ( |
11 |
| - get_body_data_type({"CONTENT_TYPE": "application/x-www-form-urlencoded"}) |
12 |
| - == "form-urlencoded" |
13 |
| - ) |
14 |
| - assert get_body_data_type({"CONTENT_TYPE": "multipart/form-data"}) == "form-data" |
15 |
| - assert get_body_data_type({"CONTENT_TYPE": "text/xml"}) == "xml" |
16 |
| - assert get_body_data_type({"CONTENT_TYPE": "text/html"}) is None |
17 |
| - assert ( |
18 |
| - get_body_data_type({"CONTENT_TYPE": ["application/json", "text/html"]}) |
19 |
| - == "json" |
20 |
| - ) |
21 |
| - assert get_body_data_type({"x-test": "abc"}) is None |
22 |
| - assert get_body_data_type(None) is None # Testing invalid input |
23 |
| - assert get_body_data_type({}) is None |
| 7 | + headers = Headers() |
| 8 | + headers.store_header("CONTENT_TYPE", "application/json") |
| 9 | + assert get_body_data_type(headers) == "json" |
| 10 | + |
| 11 | + headers = Headers() |
| 12 | + headers.store_header("CONTENT_TYPE", "application/vnd.api+json") |
| 13 | + assert get_body_data_type(headers) == "json" |
| 14 | + |
| 15 | + headers = Headers() |
| 16 | + headers.store_header("CONTENT_TYPE", "application/csp-report") |
| 17 | + assert get_body_data_type(headers) == "json" |
| 18 | + |
| 19 | + headers = Headers() |
| 20 | + headers.store_header("CONTENT_TYPE", "application/x-json") |
| 21 | + assert get_body_data_type(headers) == "json" |
| 22 | + |
| 23 | + headers = Headers() |
| 24 | + headers.store_header("CONTENT_TYPE", "application/x-www-form-urlencoded") |
| 25 | + assert get_body_data_type(headers) == "form-urlencoded" |
| 26 | + |
| 27 | + headers = Headers() |
| 28 | + headers.store_header("CONTENT_TYPE", "multipart/form-data") |
| 29 | + assert get_body_data_type(headers) == "form-data" |
| 30 | + |
| 31 | + headers = Headers() |
| 32 | + headers.store_header("CONTENT_TYPE", "text/xml") |
| 33 | + assert get_body_data_type(headers) == "xml" |
| 34 | + |
| 35 | + headers = Headers() |
| 36 | + headers.store_header("CONTENT_TYPE", "text/html") |
| 37 | + assert get_body_data_type(headers) is None |
| 38 | + |
| 39 | + headers = Headers() |
| 40 | + headers.store_header("CONTENT_TYPE", "application/json, text/html") |
| 41 | + assert get_body_data_type(headers) == "json" |
| 42 | + |
| 43 | + headers = Headers() |
| 44 | + headers.store_header("x-test", "abc") |
| 45 | + assert get_body_data_type(headers) is None |
| 46 | + |
| 47 | + headers = Headers() |
| 48 | + assert get_body_data_type(headers) is None # Testing invalid input |
| 49 | + |
| 50 | + headers = Headers() |
| 51 | + assert get_body_data_type(headers) is None |
0 commit comments