From 15e3a715df2dffb343b88b794634e701eeba8047 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 26 Mar 2014 15:56:04 +0000 Subject: Add test for sections with type fields --- lorrycontroller/readconf.py | 2 ++ yarns.webapp/060-validation.yarn | 9 +++++++++ 2 files changed, 11 insertions(+) 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 -- cgit v1.2.1