class PublicTestCase(unittest.TestCase): def setUp(self): self.client = WSGIClient(main) def tearDown(self): del self.client self.client = None def test_root(self): """ Ensure root page is rendered. """ assert 200 == self.client.get("/") assert "- Home</title>" in self.client.content def test_home(self): """ Ensure home page is rendered. """ assert 200 == self.client.get("/home") assert "- Home</title>" in self.client.content def test_static_files(self): """ Ensure static content is served. """ for static_file in ["/favicon.ico", "/static/css/site.css", "/static/js/core.js"]: assert 200 == self.client.get(static_file) def test_static_file_not_found(self): """ Ensure 404 status code for non existing static content. """ assert 302 == self.client.get("/static/css/unknown.css") assert "404" in self.client.headers["Location"][0] def test_static_file_forbidden(self): """ Ensure 403 status code for forbidden static content. """ assert 302 == self.client.get("/static/../templates/") assert "403" in self.client.headers["Location"][0] def xtest_static_file_gzip(self): """ Ensure static files are compressed. """ self.client.get( "/static/css/site.css", environ={"SERVER_PROTOCOL": "HTTP/1.1", "HTTP_ACCEPT_ENCODING": "gzip, deflate"} ) assert "gzip" in self.client.headers["Content-Encoding"] def test_static_file_if_modified_since(self): """ Request static resource with If-Modified-Since header. """ assert 200 == self.client.get("/static/css/site.css") last_modified = self.client.headers["Last-Modified"][0] assert 304 == self.client.get("/static/css/site.css", environ={"HTTP_IF_MODIFIED_SINCE": last_modified}) def test_static_file_if_none_match(self): """ Request static resource with If-None-Match header. """ assert 200 == self.client.get("/static/css/site.css") etag = self.client.headers["ETag"][0] assert 304 == self.client.get("/static/css/site.css", environ={"HTTP_IF_NONE_MATCH": etag}) def test_head_static_file(self): """ Request static resource with HTTP HEAD. """ assert 200 == self.client.head("/static/css/site.css") assert 0 == len(self.client.content)
class PublicTestCase(unittest.TestCase): def setUp(self): self.client = WSGIClient(main) def tearDown(self): del self.client self.client = None def test_root(self): """ Ensure root page is rendered. """ assert 200 == self.client.get('/') assert '- Home</title>' in self.client.content def test_home(self): """ Ensure home page is rendered. """ assert 200 == self.client.get('/en/home') assert '- Home</title>' in self.client.content def test_static_files(self): """ Ensure static content is served. """ for static_file in [ '/favicon.ico', '/static/css/site.css', '/static/js/core.js', ]: assert 200 == self.client.get(static_file) def test_static_file_not_found(self): """ Ensure 404 status code for non existing static content. """ assert 302 == self.client.get('/static/css/unknown.css') assert '404' in self.client.headers['Location'][0] def test_static_file_forbidden(self): """ Ensure 403 status code for forbidden static content. """ assert 302 == self.client.get('/static/../templates/') assert '403' in self.client.headers['Location'][0] def xtest_static_file_gzip(self): """ Ensure static files are compressed. """ self.client.get('/static/css/site.css', environ={ 'SERVER_PROTOCOL': 'HTTP/1.1', 'HTTP_ACCEPT_ENCODING': 'gzip, deflate' }) assert 'gzip' in self.client.headers['Content-Encoding'] def test_static_file_if_modified_since(self): """ Request static resource with If-Modified-Since header. """ assert 200 == self.client.get('/static/css/site.css') last_modified = self.client.headers['Last-Modified'][0] assert 304 == self.client.get('/static/css/site.css', environ={ 'HTTP_IF_MODIFIED_SINCE': last_modified }) def test_static_file_if_none_match(self): """ Request static resource with If-None-Match header. """ assert 200 == self.client.get('/static/css/site.css') etag = self.client.headers['ETag'][0] assert 304 == self.client.get('/static/css/site.css', environ={ 'HTTP_IF_NONE_MATCH': etag }) def test_head_static_file(self): """ Request static resource with HTTP HEAD. """ assert 200 == self.client.head('/static/css/site.css') assert 0 == len(self.client.content)