def test_invalid_file(self): # If the file does not exist, /index.html is returned. req = FakeRequest('/missingfile.html') handler = RewritingHTTPRequestHandler(req, self.addr, None) handler.path = req.path resp = handler.do_GET() self.assertEqual('/index.html', resp)
def test_valid_file(self): # Can serve up an existing file. with open('somefile.html', 'w'): req = FakeRequest('/somefile.html') handler = RewritingHTTPRequestHandler(req, self.addr, None) handler.path = req.path resp = handler.do_GET() self.assertEqual('/somefile.html', resp)
def test_invalid_path(self): # If the path does not exist, /index.html is returned. subdir = tempfile.mkdtemp(dir=self.tempdir) dirname = os.path.split(subdir)[-1] fn = os.path.join(dirname, 'missingfile.html') path = '/' + fn req = FakeRequest(path) handler = RewritingHTTPRequestHandler(req, self.addr, None) handler.path = req.path resp = handler.do_GET() self.assertEqual('/index.html', resp)
def test_valid_path(self): # Can serve up an existing path. subdir = tempfile.mkdtemp(dir=self.tempdir) dirname = os.path.split(subdir)[-1] fn = os.path.join(dirname, 'somefile.html') with open(fn, 'w'): path = '/' + fn req = FakeRequest(path) handler = RewritingHTTPRequestHandler(req, self.addr, None) handler.path = req.path resp = handler.do_GET() self.assertEqual(path, resp)