fix sales order code to pass the tests again

This commit is contained in:
Chris Forbes 2014-03-03 11:30:54 +13:00
parent 68fc1e8418
commit cea0e75b70
2 changed files with 10 additions and 10 deletions

View File

@ -244,15 +244,13 @@ def run_sales_order_generation():
tenants = flask.request.json.get("tenants", None)
tenant_query = session.query(Tenant)
if tenants is not None:
try:
tenant_query = tenant_query.filter(Tenant.id.in_(tenants))
if tenant_query.count() == 0:
return 400, {"errors": ["No tenants found from given list."]}
except TypeError:
# TODO: make an invalid parameters helper function
return 400, {"invalid parameters": {"tenants": "Must be a list."}}
else:
if isinstance(tenants, list):
tenant_query = tenant_query.filter(Tenant.id.in_(tenants))
if tenant_query.count() == 0:
# if an explicit list of tenants is passed, and none of them
# exist in the db, then we consider that an error.
return 400, {"errors": ["No tenants found from given list."]}
elif tenants is not None:
return 400, {"missing parameters": {"tenants": "A list of tenant ids."}}
# Handled like this for a later move to Celery distributed workers

View File

@ -60,7 +60,9 @@ class TestApi(test_interface.TestInterface):
now = datetime.now().\
replace(hour=0, minute=0, second=0, microsecond=0)
helpers.fill_db(self.session, 7, 5, now)
resp = self.app.post("/sales_order")
resp = self.app.post("/sales_order",
params=json.dumps({}),
content_type='application/json')
resp_json = json.loads(resp.body)
self.assertEquals(resp.status_int, 200)