Integrate pycodestyle

This commit is contained in:
Falco Duersch
2018-10-23 13:11:51 +02:00
committed by f4lco
parent 523cc8ba62
commit 57c75b02e5
12 changed files with 64 additions and 22 deletions
+1
View File
@@ -7,6 +7,7 @@ install:
- make dependencies - make dependencies
script: script:
- make lint
- make test - make test
- make coverage_publish - make coverage_publish
- make coverage_report - make coverage_report
+4 -1
View File
@@ -22,8 +22,11 @@ coverage_publish:
coverage_report: coverage_report:
pipenv run python -m coverage report --fail-under 90 pipenv run python -m coverage report --fail-under 90
lint:
pipenv run pycodestyle stw_potsdam tests
clean: clean:
pipenv run python -m coverage erase pipenv run python -m coverage erase
rm -rf .pytest_cache .cache rm -rf .pytest_cache .cache
.PHONY: dependencies run debug test test_debug coverage_publish coverage_report clean .PHONY: dependencies run debug test test_debug coverage_publish coverage_report lint clean
+2
View File
@@ -8,3 +8,5 @@ pytest = "*"
coveralls = "*" coveralls = "*"
pytest-cov = "*" pytest-cov = "*"
httpretty = "*" httpretty = "*"
pycodestyle = "*"
Generated
+9 -1
View File
@@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "7ba9cecb08807ab00a9a85ce40a9f66e5088b1f51b683c09b7be92ca55792ab3" "sha256": "7d175b6dd121a91ba3e19ab1d19cf724275d1de5bb682dba5ea0d337fc011ba4"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": {}, "requires": {},
@@ -345,6 +345,14 @@
], ],
"version": "==1.7.0" "version": "==1.7.0"
}, },
"pycodestyle": {
"hashes": [
"sha256:cbc619d09254895b0d12c2c691e237b2e91e9b2ecf5e84c26b35400f93dcfb83",
"sha256:cbfca99bd594a10f674d0cd97a3d802a1fdef635d4361e1a2658de47ed261e3a"
],
"index": "pypi",
"version": "==2.4.0"
},
"pycparser": { "pycparser": {
"hashes": [ "hashes": [
"sha256:a988718abfad80b6b157acce7bf130a30876d27603738ac39f140993246b25b3" "sha256:a988718abfad80b6b157acce7bf130a30876d27603738ac39f140993246b25b3"
+2 -1
View File
@@ -2,4 +2,5 @@
from collections import namedtuple from collections import namedtuple
Canteen = namedtuple('Canteen', ('key', 'name', 'street', 'city', 'id', 'chash')) Canteen = namedtuple('Canteen',
('key', 'name', 'street', 'city', 'id', 'chash'))
+2 -1
View File
@@ -6,7 +6,8 @@ from collections import namedtuple
MenuParams = namedtuple('MenuParams', ('canteen_id', 'chash')) MenuParams = namedtuple('MenuParams', ('canteen_id', 'chash'))
URL = 'https://www.studentenwerk-potsdam.de/essen/unsere-mensen-cafeterien/detailinfos/' URL = 'https://www.studentenwerk-potsdam.de' + \
'/essen/unsere-mensen-cafeterien/detailinfos/'
def _param_json(it): def _param_json(it):
+13 -3
View File
@@ -33,8 +33,10 @@ def _prices(offer):
price = offer[api_role] price = offer[api_role]
# When no price is set, this can be empty dict # When no price is set, this can be empty dict
if (isinstance(price, unicode) or isinstance(price, str)) and price.strip(): if (isinstance(price, unicode) or isinstance(price, str)) \
result[role] = str(price) # Convert unicode to str for PyOpenMensa -> misses type check and price.strip():
# Convert unicode to str for PyOpenMensa -> misses type check
result[role] = str(price)
return result return result
@@ -65,6 +67,14 @@ def render_meta(canteen, menu_feed_url):
builder.address = canteen.street builder.address = canteen.street
builder.city = canteen.city builder.city = canteen.city
builder.define(name="full", priority="0", url=menu_feed_url, source=None, dayOfWeek="*", dayOfMonth="*", hour="8-18", minute="0", retry="30 1") builder.define(name='full',
priority='0',
url=menu_feed_url,
source=None,
dayOfWeek='*',
dayOfMonth='*',
hour='8-18',
minute='0',
retry='30 1')
return builder.toXMLFeed() return builder.toXMLFeed()
+9 -4
View File
@@ -30,8 +30,8 @@ cache = SimpleCache()
def canteen_not_found(config, canteen_name): def canteen_not_found(config, canteen_name):
app.logger.warn('Canteen %s not found', canteen_name) app.logger.warn('Canteen %s not found', canteen_name)
configured = ', '.join("'{}'".format(c) for c in config.keys()) configured = ', '.join("'{}'".format(c) for c in config.keys())
message = "Canteen '{canteen}' not found, available: {configured}".format(canteen=canteen_name, message = "Canteen '{0}' not found, available: {1}".format(canteen_name,
configured=configured) configured)
return make_response(message, 404) return make_response(message, 404)
@@ -62,7 +62,9 @@ def canteen_menu_feed_xml(menu):
def canteen_meta_feed_xml(canteen): def canteen_meta_feed_xml(canteen):
menu_feed_url = url_for('canteen_menu_feed', canteen_name=canteen.key, _external=True) menu_feed_url = url_for('canteen_menu_feed',
canteen_name=canteen.key,
_external=True)
xml = feed.render_meta(canteen, menu_feed_url) xml = feed.render_meta(canteen, menu_feed_url)
return _canteen_feed_xml(xml) return _canteen_feed_xml(xml)
@@ -95,7 +97,10 @@ def canteen_menu_feed(canteen_name):
@app.route('/canteens') @app.route('/canteens')
def canteen_index(): def canteen_index():
config = read_canteen_config() config = read_canteen_config()
return jsonify({key: url_for('canteen_meta_feed', canteen_name=key, _external=True) for key in config}) return jsonify({
key: url_for('canteen_meta_feed', canteen_name=key, _external=True)
for key in config
})
@app.route('/health_check') @app.route('/health_check')
+5 -3
View File
@@ -5,9 +5,11 @@ from xml.etree import ElementTree
def meal_names(response): def meal_names(response):
"""Extract meal names from OpenMensa XML. """Extract meal names from OpenMensa XML.
By no means below parsing is robust or complete. Below just helps ensuring that the parser indeed returns proper XML By no means below parsing is robust or complete. Below just helps ensuring
instead of arbitrary responses.""" that the parser indeed returns proper XML instead of arbitrary responses.
"""
root = ElementTree.fromstring(response) root = ElementTree.fromstring(response)
namespace = {'om': 'http://openmensa.org/open-mensa-v2'} namespace = {'om': 'http://openmensa.org/open-mensa-v2'}
nodes = root.findall('om:canteen/om:day/om:category/om:meal/om:name', namespace) nodes = root.findall('om:canteen/om:day/om:category/om:meal/om:name',
namespace)
return [node.text for node in nodes] return [node.text for node in nodes]
+6 -2
View File
@@ -21,7 +21,8 @@ def api_online_one_shot():
Subsequent API invocations will return with HTTP status code 500.""" Subsequent API invocations will return with HTTP status code 500."""
def canned_menu(request, uri, response_headers): def canned_menu(request, uri, response_headers):
path = os.path.join(os.path.dirname(__file__), 'resources', 'input.json') path = os.path.join(os.path.dirname(__file__),
'resources', 'input.json')
with open(path) as f: with open(path) as f:
return 200, response_headers, f.read() return 200, response_headers, f.read()
@@ -30,7 +31,10 @@ def api_online_one_shot():
httpretty.Response(body='invalid', status=500), httpretty.Response(body='invalid', status=500),
] ]
httpretty.register_uri(httpretty.POST, canteen_api.URL, responses=responses) httpretty.register_uri(httpretty.POST,
canteen_api.URL,
responses=responses)
httpretty.enable(allow_net_connect=False) httpretty.enable(allow_net_connect=False)
yield httpretty yield httpretty
httpretty.disable() httpretty.disable()
+4 -2
View File
@@ -26,12 +26,14 @@ def is_enabled():
requires_online_api = pytest.mark.skipif( requires_online_api = pytest.mark.skipif(
not is_enabled(), not is_enabled(),
reason='Querying the online API is disabled. Turn on by setting env variable %s.' % ENV_ENABLED reason='Querying the online API is disabled. '
'Turn on by setting env variable %s.' % ENV_ENABLED
) )
@requires_online_api @requires_online_api
def test_retrieval(canteen): def test_retrieval(canteen):
feed.render_meta(canteen, "/canteens/{}/menu".format(canteen.key)) feed.render_meta(canteen, "/canteens/{}/menu".format(canteen.key))
menu = download_menu(MenuParams(canteen_id=canteen.id, chash=canteen.chash)) params = MenuParams(canteen_id=canteen.id, chash=canteen.chash)
menu = download_menu(params)
feed.render_menu(menu) feed.render_menu(menu)
+6 -3
View File
@@ -24,7 +24,10 @@ def test_index(client):
assert canteen.status_code == 200, 'Canteen URL is reachable' assert canteen.status_code == 200, 'Canteen URL is reachable'
@pytest.mark.parametrize('url', ['/canteens/spam', '/canteens/spam/meta', '/canteens/spam/menu']) @pytest.mark.parametrize('url', [
'/canteens/spam',
'/canteens/spam/meta',
'/canteens/spam/menu'])
def test_canteen_not_found(client, url): def test_canteen_not_found(client, url):
response = client.get(url) response = client.get(url)
assert response.status_code == 404 assert response.status_code == 404
@@ -56,8 +59,8 @@ def _request_check_meals(client):
response = client.get('/canteens/griebnitzsee/menu') response = client.get('/canteens/griebnitzsee/menu')
assert response.status_code == 200 assert response.status_code == 200
meals = meal_names(response.data) meal = meal_names(response.data)[0]
assert meals[0] == u"Gefüllter Germknödel \nmit Vanillesauce und Mohnzucker" assert meal == u"Gefüllter Germknödel \nmit Vanillesauce und Mohnzucker"
@pytest.fixture @pytest.fixture