-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_headers.py
73 lines (52 loc) · 1.54 KB
/
test_headers.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
import pytest
from headers import Header
from settings import Sets
sets = Sets()
head = Header(sets.parent_folder, sets.addr)
# set varibles
@pytest.mark.parametrize('filename,cont_type', [
('/_tests/index.html', 'text/html; charset=ascii'),
('/_tests/index.css', 'text/css'),
('/_tests/main.js', 'application/javascript'),
('/_tests/', 'text/html; charset=ascii')])
def test_computeResponse(filename, cont_type):
head.requested_file = filename
resp = head.computeResponse()
str_resp = str(resp, 'UTF-8')
splitted = str_resp.split('\r\n\r\n')
body_str = splitted[-1]
body_bytes = bytes(body_str, 'UTF-8')
header_str = splitted[0]
header_pair = {}
# see headers
lines = header_str.split('\r\n')
for pair in lines:
# for now we are breaking with ': ' to escpace
# the port no. eg. localhost':'9999
splits = pair.split(": ")
# if it was a key-value pair
if len(splits) > 1:
# make it a part of the header pair dict
header_pair[splits[0]] = splits[1]
assert type(resp) == bytes
assert int(header_pair['Content-Length']) == len(body_bytes)
assert header_pair['Content-Type'] == cont_type
def test__getHost():
pass
# head._getHost()
def test__getFile():
pass
# head._getFile()
def test__getCookies():
pass
# head.__getCookies()
def test__status():
pass
# head.__status()
def test__date():
pass
# head.__date()
def test__cookie():
pass
# head