def test_parse_one(setup_test_resources): testdir = bytes(os.getcwd()) + b'/root/' + b'/testdir/' s = HttpServer() dirs = [] files = [] for item in os.listdir(testdir): if os.path.isdir(testdir + item): dirs.append("{}/".format(item)) else: files.append(item) dirs.sort() files.sort() resources = dirs + files expected_body = [] expected_body.append("<p>Directory Listing for /testdir/</p><ul>") for res in resources: expected_body.append('<li><a href="{}">{}</a></li>'.format(res, res)) expected_body.append("</ul>") body, content_type = s._process_request("GET /testdir/ HTTP/1.1") assert body == "".join(expected_body) assert content_type == "text/html"
def test_parse_3(): s = HttpServer() with pytest.raises(NotHTTP1_1Error): s._process_request("GET /uri/ HTTP/1.0")
def test_parse_4(): s = HttpServer() with pytest.raises(BadRequestError): s._process_request("GET/uri/HTTP/1.0")
def test_parse_2(): s = HttpServer() with pytest.raises(NotGETRequestError): s._process_request("POST /uri/ HTTP/1.1")