def test_resolve_uri(): uri = parse_request("GET ./ HTTP/1.1\r\nHOST: www.site.com\r\n\r\n<html>stuff</html>") assert "text/html" in resolve_uri(uri) with pytest.raises(UserWarning): resolve_uri("./../../../") with pytest.raises(IOError): resolve_uri("~") with pytest.raises(IOError): resolve_uri("./cat.gif")
def call_function_under_test(self, uri): """call the resolve_uri function""" from http_server import resolve_uri return resolve_uri(uri)
def call_function_under_test(self, uri): """call the resolve_uri function""" from http_server import resolve_uri content, mime_type = resolve_uri(uri) return content, mime_type.decode('utf8')
def test_resolve_uri_root_is_listing_of_webroot(self): result = server.resolve_uri('/') assert b'images/' in result[0] assert b'text/plain' in result[1]
def test_resolve_uri_file_not_found(self): with self.assertRaises(NameError): server.resolve_uri('/file_not_found')
def test_resolve_uri_directory(self): result = server.resolve_uri('/images') assert b'Sample_Scene_Balls.jpg' in result[0]
def test_resolve_uri_file(self): result = server.resolve_uri('/sample.txt') assert b'This is a very simple text file.\n' in result[0]