コード例 #1
0
    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)
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
0
    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)
コード例 #5
0
    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)
コード例 #6
0
    def test_response_path_not_found(self):
        path = "/foo/bar/baz/doesnt/exist"

        with self.assertRaises(NameError):
            http_server.response_path(path)