Support empty menu response

In recent weeks many API calls return "null".
Instead of letting the request fail, the parser
now treats "null" as empty menu.
This commit is contained in:
f4lco
2020-03-28 21:12:17 +01:00
parent 0208bffb73
commit e0079a537f
4 changed files with 24 additions and 14 deletions
+1
View File
@@ -0,0 +1 @@
null
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<openmensa version="2.1" xmlns="http://openmensa.org/open-mensa-v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://openmensa.org/open-mensa-v2 http://openmensa.org/open-mensa-v2.xsd">
<canteen/>
</openmensa>
+16 -12
View File
@@ -16,18 +16,13 @@ def _canteen():
return read_canteen_config()['griebnitzsee']
def _menu():
with open(_resource_path('input.json')) as menu_file:
def _read_menu(resource_name):
with open(_resource_path(resource_name)) as menu_file:
return json.load(menu_file)
def _expected_meta_feed():
with io.open(_resource_path('meta_output.xml'), encoding='utf-8') as xml:
return xml.read()
def _expected_menu_feed():
with io.open(_resource_path('menu_output.xml'), encoding='utf-8') as xml:
def _read_feed(resource_name):
with io.open(_resource_path(resource_name), encoding='utf-8') as xml:
return xml.read()
@@ -37,14 +32,23 @@ def test_meta_consistency():
actual = feed.render_meta(canteen, menu_feed_url)
expected = _expected_meta_feed()
expected = _read_feed('meta_output.xml')
assert expected == actual
def test_menu_consistency():
menu = _menu()
menu = _read_menu('input.json')
actual = feed.render_menu(menu)
expected = _expected_menu_feed()
expected = _read_feed('menu_output.xml')
assert expected == actual
def test_empty_menu():
menu = _read_menu('empty.json')
actual = feed.render_menu(menu)
expected = _read_feed('empty_menu_output.xml')
assert expected == actual