Integrate pycodestyle
This commit is contained in:
@@ -7,6 +7,7 @@ install:
|
||||
- make dependencies
|
||||
|
||||
script:
|
||||
- make lint
|
||||
- make test
|
||||
- make coverage_publish
|
||||
- make coverage_report
|
||||
|
||||
@@ -22,8 +22,11 @@ coverage_publish:
|
||||
coverage_report:
|
||||
pipenv run python -m coverage report --fail-under 90
|
||||
|
||||
lint:
|
||||
pipenv run pycodestyle stw_potsdam tests
|
||||
|
||||
clean:
|
||||
pipenv run python -m coverage erase
|
||||
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
|
||||
|
||||
@@ -8,3 +8,5 @@ pytest = "*"
|
||||
coveralls = "*"
|
||||
pytest-cov = "*"
|
||||
httpretty = "*"
|
||||
pycodestyle = "*"
|
||||
|
||||
|
||||
Generated
+9
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "7ba9cecb08807ab00a9a85ce40a9f66e5088b1f51b683c09b7be92ca55792ab3"
|
||||
"sha256": "7d175b6dd121a91ba3e19ab1d19cf724275d1de5bb682dba5ea0d337fc011ba4"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {},
|
||||
@@ -345,6 +345,14 @@
|
||||
],
|
||||
"version": "==1.7.0"
|
||||
},
|
||||
"pycodestyle": {
|
||||
"hashes": [
|
||||
"sha256:cbc619d09254895b0d12c2c691e237b2e91e9b2ecf5e84c26b35400f93dcfb83",
|
||||
"sha256:cbfca99bd594a10f674d0cd97a3d802a1fdef635d4361e1a2658de47ed261e3a"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==2.4.0"
|
||||
},
|
||||
"pycparser": {
|
||||
"hashes": [
|
||||
"sha256:a988718abfad80b6b157acce7bf130a30876d27603738ac39f140993246b25b3"
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
Canteen = namedtuple('Canteen', ('key', 'name', 'street', 'city', 'id', 'chash'))
|
||||
Canteen = namedtuple('Canteen',
|
||||
('key', 'name', 'street', 'city', 'id', 'chash'))
|
||||
|
||||
@@ -6,7 +6,8 @@ from collections import namedtuple
|
||||
|
||||
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):
|
||||
|
||||
+13
-3
@@ -33,8 +33,10 @@ def _prices(offer):
|
||||
|
||||
price = offer[api_role]
|
||||
# When no price is set, this can be empty dict
|
||||
if (isinstance(price, unicode) or isinstance(price, str)) and price.strip():
|
||||
result[role] = str(price) # Convert unicode to str for PyOpenMensa -> misses type check
|
||||
if (isinstance(price, unicode) or isinstance(price, str)) \
|
||||
and price.strip():
|
||||
# Convert unicode to str for PyOpenMensa -> misses type check
|
||||
result[role] = str(price)
|
||||
|
||||
return result
|
||||
|
||||
@@ -65,6 +67,14 @@ def render_meta(canteen, menu_feed_url):
|
||||
builder.address = canteen.street
|
||||
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()
|
||||
|
||||
@@ -30,8 +30,8 @@ cache = SimpleCache()
|
||||
def canteen_not_found(config, canteen_name):
|
||||
app.logger.warn('Canteen %s not found', canteen_name)
|
||||
configured = ', '.join("'{}'".format(c) for c in config.keys())
|
||||
message = "Canteen '{canteen}' not found, available: {configured}".format(canteen=canteen_name,
|
||||
configured=configured)
|
||||
message = "Canteen '{0}' not found, available: {1}".format(canteen_name,
|
||||
configured)
|
||||
return make_response(message, 404)
|
||||
|
||||
|
||||
@@ -62,7 +62,9 @@ def canteen_menu_feed_xml(menu):
|
||||
|
||||
|
||||
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)
|
||||
return _canteen_feed_xml(xml)
|
||||
|
||||
@@ -95,7 +97,10 @@ def canteen_menu_feed(canteen_name):
|
||||
@app.route('/canteens')
|
||||
def canteen_index():
|
||||
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')
|
||||
|
||||
@@ -5,9 +5,11 @@ from xml.etree import ElementTree
|
||||
def meal_names(response):
|
||||
"""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
|
||||
instead of arbitrary responses."""
|
||||
By no means below parsing is robust or complete. Below just helps ensuring
|
||||
that the parser indeed returns proper XML instead of arbitrary responses.
|
||||
"""
|
||||
root = ElementTree.fromstring(response)
|
||||
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]
|
||||
|
||||
+6
-2
@@ -21,7 +21,8 @@ def api_online_one_shot():
|
||||
Subsequent API invocations will return with HTTP status code 500."""
|
||||
|
||||
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:
|
||||
return 200, response_headers, f.read()
|
||||
|
||||
@@ -30,7 +31,10 @@ def api_online_one_shot():
|
||||
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)
|
||||
yield httpretty
|
||||
httpretty.disable()
|
||||
|
||||
@@ -26,12 +26,14 @@ def is_enabled():
|
||||
|
||||
requires_online_api = pytest.mark.skipif(
|
||||
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
|
||||
def test_retrieval(canteen):
|
||||
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)
|
||||
|
||||
+6
-3
@@ -24,7 +24,10 @@ def test_index(client):
|
||||
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):
|
||||
response = client.get(url)
|
||||
assert response.status_code == 404
|
||||
@@ -56,8 +59,8 @@ def _request_check_meals(client):
|
||||
response = client.get('/canteens/griebnitzsee/menu')
|
||||
|
||||
assert response.status_code == 200
|
||||
meals = meal_names(response.data)
|
||||
assert meals[0] == u"Gefüllter Germknödel \nmit Vanillesauce und Mohnzucker"
|
||||
meal = meal_names(response.data)[0]
|
||||
assert meal == u"Gefüllter Germknödel \nmit Vanillesauce und Mohnzucker"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
Reference in New Issue
Block a user