plan: allow plan with empty dict parameters

Validation on parameters counted on the condition:
  "parameters is None"
which is also True when parameters is an empty dict.
This patch fixes that and allows an empty dict as plan parameters

Change-Id: I10ea8dd19ce443ca717903e1e5faf34309d30ecf
This commit is contained in:
Yuval Brik 2016-06-19 09:24:47 +03:00
parent 8439e4bdea
commit 1799cda772
2 changed files with 9 additions and 2 deletions

View File

@ -246,12 +246,13 @@ class PlansController(wsgi.Controller):
"a plan.")
raise exception.InvalidInput(reason=msg)
if not plan.get("parameters"):
parameters = plan.get("parameters", None)
if parameters is None:
msg = _("parameters must be provided when creating "
"a plan.")
raise exception.InvalidInput(reason=msg)
parameters = plan.get("parameters")
if not isinstance(parameters, dict):
msg = _("parameters must be a dict when creating a plan.")
raise exception.InvalidInput(reason=msg)

View File

@ -124,6 +124,12 @@ class PlanApiTest(base.TestCase):
self.controller.index(req)
self.assertTrue(moak_get_all.called)
def test_plan_create_empty_dict(self):
plan = self._plan_in_request_body(parameters={})
body = {"plan": plan}
req = fakes.HTTPRequest.blank('/v1/plans')
self.controller.create(req, body)
@mock.patch(
'smaug.api.v1.plans.PlansController._plan_get')
def test_plan_show(self, moak_plan_get):