def test_response_path_file(self): """test response_path_file""" path = "/a_web_page.html" content, mime_type = http_server.response_path(path) self.assertEqual(b"text/html", mime_type) with open(os.path.join("webroot", "a_web_page.html"), "rb") as f: self.assertEqual(f.read(), content)
def test_response_path_dir(self): path = "/" content, mime_type = http_server.response_path(path) self.assertIn(b"favicon.ico", content) self.assertIn(b"make_time.py", content) self.assertIn(b"sample.txt", content) self.assertIn(b"a_web_page.html", content)
def test_response_path_image(self): file = 'images/Sample_Scene_Balls.jpg' web_path = '/' + file content, mime_type = http_server.response_path(web_path) self.assertEqual(b"image/jpeg", mime_type) with open(os.path.join("webroot", file), "rb") as f: self.assertEqual(f.read(), content)
def test_images_index(self): """ A call to /images/ yields a list of files in the images directory """ path = "/images" content, mime_type = http_server.response_path(path) self.assertIn(b"JPEG_example.jpg", content) self.assertIn(b"sample_1.png", content) self.assertIn(b"Sample_Scene_Balls.jpg", content)
def test_response_path_file(self): path = "/a_web_page.html" content, mime_type = http_server.response_path(path) sr = content.decode('utf8') sr = sr.rstrip("\n") self.assertEqual(b"text/html", mime_type) with open(os.path.join("webroot", "a_web_page.html"), "r") as f: ss = f.read() ss = ss.rstrip("\n") #print(f" xxxxxx -{sr}-") #print(f" yyyyyy -{ss}-") self.assertEqual(sr, ss)
def test_response_path_not_found(self): path = "/foo/bar/baz/doesnt/exist" with self.assertRaises(NameError): http_server.response_path(path)