Skip to content

Commit

Permalink
[Feature #160234323] Build out code to pass tests
Browse files Browse the repository at this point in the history
Update order status
  • Loading branch information
artorious committed Sep 7, 2018
1 parent 8fc2b39 commit 18cb10a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
11 changes: 10 additions & 1 deletion app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,21 @@ def fetch_order_by_id(self, orderid):
return {
"Order fetching error message": "orderid should be integer"
}

def update_order_by_id(self, orderid, update_status):
""" (FoodOrders, int, bool) -> dict
Returns custom message to user to indicat update status
"""
return
if isinstance(orderid, int) and isinstance(update_status, bool):
if orderid in self.all_food_orders:
self.all_food_orders[orderid]['order_accept_status'] =\
update_status
return {"Order update message": "Update Successful"}
return {"Order update error message": "orderid out of range"}
return {
"Order update error message": "Invalid Input"
}


if __name__ == '__main__':
Expand Down
30 changes: 5 additions & 25 deletions app/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ def test_update_order_operation_success(self):
self.assertEqual(
test_resp.status_code, 200, msg='Expected 200'
)
self.assertIn(
b"Order update message",
test_resp.data,
msg="Does not output success msg to user"
)

def test_update_order_operation_malformed_route(self):
""" Test that path with an error (malformed syntax) returns an
Expand All @@ -165,31 +170,6 @@ def test_update_order_operation_malformed_route(self):
404,
msg='Error: The requested URL was not found on the server'
)

def test_update_order_operation_malformed_data(self):
""" Test that path with an error (malformed data) returns an
appropriate error message in JSON and HTTP response code of
409 (RESOURCE CONFLICT)
Tests payload before deploying
"""
self.app.post(
'/api/v1/orders',
data=json.dumps(self.sample_order_request_info),
headers={'content-type': 'application/json'}
)

test_resp = self.app.put(
'/api/v1/orders/1',
data=json.dumps("True"),
headers={'content-type': 'application/json'}
)
self.assertEqual(
test_resp.status_code,
409,
msg='Error: RESOURCE CONFLICT'
)
self.assertIn(b'Sorry.... Order update Failed', test_resp.data)


if __name__ == '__main__':
Expand Down
6 changes: 5 additions & 1 deletion app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ def fetch_order_by_id(orderid):
@app.route('/api/v1/orders/<int:orderid>', methods=['PUT'])
def update_order_by_id(orderid):
""" Updates a single food order matching the provided <orderid> """
return
req_data = request.get_json()

if isinstance(orderid, int) and isinstance(req_data, bool):
return jsonify(SAMPLE_FOOD_ORDERS.update_order_by_id(orderid, req_data))
return jsonify({"Order update message": "Update Failed..Invalid input"})

0 comments on commit 18cb10a

Please sign in to comment.