def test_favicon_redirect(self): """ If `favicon_url` is provided, check requests to `/favicon.ico` receive a redirect """ external_url = "https://example.com/icos/favcon" local_url = "/static/some-image.ico" external_app = FlaskBase(__name__, "canonicalwebteam.flask-base", favicon_url=external_url) local_app = FlaskBase(__name__, "canonicalwebteam.flask-base", favicon_url=local_url) with external_app.test_client() as client: response = client.get("/favicon.ico") self.assertEqual(302, response.status_code) self.assertEqual(response.headers.get("Location"), external_url) with local_app.test_client() as client: response = client.get("/favicon.ico") self.assertEqual(302, response.status_code) self.assertEqual( response.headers.get("Location"), "http://localhost" + local_url, )
def test_adds_redirects(self): def _deleted_callback(context): return "Deleted", 410 p_deleted = prepare_deleted(path="./tests/deleted.yaml", view_callback=_deleted_callback) p_redirects = prepare_redirects(path="./tests/redirects.yaml") app = FlaskBase(__name__, "canonicalwebteam.flask-base", p_deleted, p_redirects) with app.test_client() as client: response = client.get("redirect") self.assertEqual(302, response.status_code) self.assertEqual(response.headers.get("Location"), "https://httpbin.org/") response = client.get("deleted") self.assertEqual(410, response.status_code) self.assertEqual(response.data, b"Deleted")