diff --git a/app.py b/app.py index cbe40e23..c2bcca52 100644 --- a/app.py +++ b/app.py @@ -6,7 +6,7 @@ from flask_sslify import SSLify DIR = os.path.dirname(os.path.realpath(__file__)) -ROOT = os.path.join(DIR, 'docs', '_build', 'html') +ROOT = os.path.join(DIR, "docs", "_build", "html") def find_key(token): @@ -21,20 +21,20 @@ def find_key(token): app = Flask(__name__) -if 'DYNO' in os.environ: - sslify = SSLify(app, skips=['.well-known']) +if "DYNO" in os.environ: + sslify = SSLify(app, skips=[".well-known"]) -@app.route('/') +@app.route("/") def static_proxy(path): """Find static files.""" return send_from_directory(ROOT, path) -@app.route('/') +@app.route("/") def index_redirection(): """Redirecting index file.""" - return send_from_directory(ROOT, 'index.html') + return send_from_directory(ROOT, "index.html") @app.route("/.well-known/acme-challenge/") diff --git a/app_test.py b/app_test.py index f8a81328..53d3f0ee 100644 --- a/app_test.py +++ b/app_test.py @@ -7,12 +7,7 @@ from werkzeug.exceptions import NotFound from flask_testing import LiveServerTestCase -from app import ( - acme, - find_key, - static_proxy, - index_redirection -) +from app import acme, find_key, static_proxy, index_redirection from app import ROOT from app import app @@ -29,14 +24,14 @@ def create_app(self): continue del os.environ[k] - self.token = 'token' + self.token = "token" self.key = "key" - os.environ['ACME_TOKEN'] = self.token - os.environ['ACME_KEY'] = self.key - os.environ['FLASK_ENV'] = 'development' - os.environ['FLASK_DEBUG'] = "1" - app.config['TESTING'] = True - app.config['LIVESERVER_PORT'] = 0 + os.environ["ACME_TOKEN"] = self.token + os.environ["ACME_KEY"] = self.key + os.environ["FLASK_ENV"] = "development" + os.environ["FLASK_DEBUG"] = "1" + app.config["TESTING"] = True + app.config["LIVESERVER_PORT"] = 0 return app def test_index_redirection_req(self): @@ -47,21 +42,21 @@ def test_index_redirection_req(self): def test_static_proxy_req(self): """Test that send a request for notes.""" - htmls = os.listdir(os.path.join(ROOT, 'notes')) + htmls = os.listdir(os.path.join(ROOT, "notes")) url = self.get_server_url() for h in htmls: - u = url + '/notes/' + h + u = url + "/notes/" + h resp = requests.get(u) self.assertEqual(resp.status_code, 200) def test_acme_req(self): """Test that send a request for a acme key.""" url = self.get_server_url() - u = url + '/.well-known/acme-challenge/token' + u = url + "/.well-known/acme-challenge/token" resp = requests.get(u) self.assertEqual(resp.status_code, 200) - u = url + '/.well-known/acme-challenge/foo' + u = url + "/.well-known/acme-challenge/foo" resp = requests.get(u) self.assertEqual(resp.status_code, 404) @@ -71,15 +66,15 @@ def test_find_key(self): key = self.key self.assertEqual(find_key(token), key) - del os.environ['ACME_TOKEN'] - del os.environ['ACME_KEY'] + del os.environ["ACME_TOKEN"] + del os.environ["ACME_KEY"] - os.environ['ACME_TOKEN_ENV'] = token - os.environ['ACME_KEY_ENV'] = key + os.environ["ACME_TOKEN_ENV"] = token + os.environ["ACME_KEY_ENV"] = key self.assertEqual(find_key(token), key) - del os.environ['ACME_TOKEN_ENV'] - del os.environ['ACME_KEY_ENV'] + del os.environ["ACME_TOKEN_ENV"] + del os.environ["ACME_KEY_ENV"] def test_acme(self): """Test that send a request for a acme key.""" @@ -89,12 +84,12 @@ def test_acme(self): token = token + "_env" key = key + "_env" - os.environ['ACME_TOKEN_ENV'] = token - os.environ['ACME_KEY_ENV'] = key + os.environ["ACME_TOKEN_ENV"] = token + os.environ["ACME_KEY_ENV"] = key self.assertEqual(find_key(token), key) - del os.environ['ACME_TOKEN_ENV'] - del os.environ['ACME_KEY_ENV'] + del os.environ["ACME_TOKEN_ENV"] + del os.environ["ACME_KEY_ENV"] self.assertRaises(NotFound, acme, token) @@ -106,10 +101,10 @@ def test_index_redirection(self): def test_static_proxy(self): """Test that request static pages.""" - htmls = os.listdir(os.path.join(ROOT, 'notes')) + htmls = os.listdir(os.path.join(ROOT, "notes")) for h in htmls: - u = 'notes/' + h + u = "notes/" + h resp = static_proxy(u) self.assertEqual(resp.status_code, 200) resp.close()