-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathtest_preview.py
More file actions
55 lines (38 loc) · 1.34 KB
/
test_preview.py
File metadata and controls
55 lines (38 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pytest
from httpdbg.preview import generate_preview
@pytest.mark.preview
def test_preview_unknown_type_text():
body = generate_preview("a text", "unknown/type", "")
assert body == {"text": "a text", "content_type": "unknown/type"}
@pytest.mark.preview
def test_preview_unknown_type_bytes():
body = generate_preview(b"a text", "unknown/type", "")
assert body == {"text": "a text", "content_type": "unknown/type"}
@pytest.mark.preview
@pytest.mark.parametrize("content_type", ["text/json", "application/json", "text", ""])
def test_preview_text(content_type):
raw_data = '{"a": "1", "b": {"c": 2} }'
body = generate_preview(raw_data, content_type, "")
assert body == {
"text": raw_data,
"content_type": content_type,
}
@pytest.mark.preview
def test_preview_image():
body = generate_preview(None, "image/png", "")
assert body == {
"image": True,
"content_type": "image/png",
}
def test_preview_application_no_content_type_text():
body = generate_preview("just text", "", "")
assert body == {
"text": "just text",
"content_type": "",
}
def test_preview_application_no_content_type_bytes():
body = generate_preview("just éà bytes".encode("utf-8"), "", "")
assert body == {
"text": "just éà bytes",
"content_type": "",
}