summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-03-26 15:56:04 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-03-26 15:56:04 +0000
commit15e3a715df2dffb343b88b794634e701eeba8047 (patch)
tree2e8729b3bd713210430b9ea5cabd124d716843e0
parentf808ef26b0028c3aa9c52f287eea96f62cd87bbd (diff)
downloadlorry-controller-15e3a715df2dffb343b88b794634e701eeba8047.tar.gz
Add test for sections with type fields
-rw-r--r--lorrycontroller/readconf.py2
-rw-r--r--yarns.webapp/060-validation.yarn9
2 files changed, 11 insertions, 0 deletions
diff --git a/lorrycontroller/readconf.py b/lorrycontroller/readconf.py
index a76a1ad..b0124a9 100644
--- a/lorrycontroller/readconf.py
+++ b/lorrycontroller/readconf.py
@@ -56,6 +56,8 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute):
existing_troves = set(statedb.get_troves())
for section in conf_obj:
+ if not 'type' in section:
+ return 'ERROR: no type field in section'
if section['type'] == 'lorries':
added = self.add_matching_lorries_to_statedb(
statedb, section)
diff --git a/yarns.webapp/060-validation.yarn b/yarns.webapp/060-validation.yarn
index 79fc306..508f1f2 100644
--- a/yarns.webapp/060-validation.yarn
+++ b/yarns.webapp/060-validation.yarn
@@ -66,6 +66,15 @@ Add a syntactically invalid JSON file.
THEN response matches "ERROR"
AND STATEDB is empty
+Replace the bad JSON file with one that has an unknown section (no
+`type` field). Please excuse the non-escaping of double quotes: it's
+an artifact of how yarn steps are implemented and is OK.
+
+ GIVEN a lorry-controller.conf in CONFGIT containing "[{"foo": "bar"}]"
+ WHEN admin makes request POST /1.0/read-configuration with dummy=value
+ THEN response matches "ERROR"
+ AND STATEDB is empty
+
Clean up at the end.
FINALLY WEBAPP terminates