Skip to content

Commit

Permalink
add pydocstyle check
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyguitar committed Mar 21, 2018
1 parent 6596826 commit cba5aa4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
REQUIREMENT = requirements.txt

SRC = app.py app_test.py

.PHONY: build test
build: html

%:
cd docs && make $@

test: clean build
flake8 app.py app_test.py
coverage run app_test.py && coverage report --fail-under=90 -m app.py app_test.py
pycodestyle $(SRC)
pydocstyle $(SRC)
coverage run app_test.py && coverage report --fail-under=90 -m $(SRC)
11 changes: 6 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
This is a simple cheatsheet webapp.
"""
"""This is a simple cheatsheet webapp."""

import os

from flask import Flask, abort, send_from_directory
Expand All @@ -11,6 +10,7 @@


def find_key(token):
"""Find the key from the environment variable."""
if token == os.environ.get("ACME_TOKEN"):
return os.environ.get("ACME_KEY")
for k, v in os.environ.items():
Expand All @@ -27,18 +27,19 @@ def find_key(token):

@app.route('/<path:path>')
def static_proxy(path):
"""Static files proxy"""
"""Find static files."""
return send_from_directory(ROOT, path)


@app.route('/')
def index_redirection():
"""Redirecting index file"""
"""Redirecting index file."""
return send_from_directory(ROOT, 'index.html')


@app.route("/.well-known/acme-challenge/<token>")
def acme(token):
"""Find the acme-key from environment variable."""
key = find_key(token)
if key is None:
abort(404)
Expand Down
12 changes: 11 additions & 1 deletion app_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Test app.py."""

import unittest
import requests
import os
Expand All @@ -17,9 +19,10 @@


class PysheeetTest(LiveServerTestCase):
"""Test app."""

def create_app(self):

"""Create a app for test."""
# remove env ACME_TOKEN*
for k, v in os.environ.items():
if not k.startswith("ACME_TOKEN"):
Expand All @@ -34,11 +37,13 @@ def create_app(self):
return app

def test_index_redirection_req(self):
"""Test that send a request for the index page."""
url = self.get_server_url()
resp = requests.get(url)
self.assertEqual(resp.status_code, 200)

def test_static_proxy_req(self):
"""Test that send a request for notes."""
htmls = os.listdir(os.path.join(ROOT, 'notes'))
url = self.get_server_url()
for h in htmls:
Expand All @@ -47,6 +52,7 @@ def test_static_proxy_req(self):
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'
resp = requests.get(u)
Expand All @@ -57,6 +63,7 @@ def test_acme_req(self):
self.assertEqual(resp.status_code, 404)

def test_find_key(self):
"""Test that find a acme key from the environment."""
token = self.token
key = self.key
self.assertEqual(find_key(token), key)
Expand All @@ -72,6 +79,7 @@ def test_find_key(self):
del os.environ['ACME_KEY_ENV']

def test_acme(self):
"""Test that send a request for a acme key."""
token = self.token
key = self.key
self.assertEqual(acme(token), key)
Expand All @@ -88,11 +96,13 @@ def test_acme(self):
self.assertRaises(NotFound, acme, token)

def test_index_redirection(self):
"""Test index page redirection."""
resp = index_redirection()
self.assertEqual(resp.status_code, 200)
resp.close()

def test_static_proxy(self):
"""Test that request static pages."""
htmls = os.listdir(os.path.join(ROOT, 'notes'))

for h in htmls:
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Flask==0.12.2
Flask-SSLify==0.1.5
Flask-Testing==0.7.1
gunicorn==19.7.1
pycodestyle==2.3.1
pydocstyle==2.1.1
requests==2.18.4
Sphinx==1.7.2
flake8==3.5.0
Werkzeug==0.14.1

0 comments on commit cba5aa4

Please sign in to comment.