Integrate pycodestyle
This commit is contained in:
@@ -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