Skip to content

Commit

Permalink
using black format the files
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyguitar committed Aug 6, 2018
1 parent c13fe88 commit 3e34a1f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 35 deletions.
12 changes: 6 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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('/<path:path>')
@app.route("/<path:path>")
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/<token>")
Expand Down
53 changes: 24 additions & 29 deletions app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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)

Expand All @@ -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."""
Expand All @@ -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)

Expand All @@ -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()
Expand Down

0 comments on commit 3e34a1f

Please sign in to comment.