Example #1
0
File: api.py Project: zzsun777/ddme
 def post(self, **kwargs):
     order = None
     resp = None
     body = json.loads(self.request.body)
     if self.request.uri == "{}".format(constants.URL_PATH_BUY):
         order = Buy(**body)
     if self.request.uri == "{}".format(constants.URL_PATH_SELL):
         order = Sell(**body)
     if not order.is_valid():
         resp = {"message": responses[constants.HTTP_400_BAD_REQUEST]}
         self.set_status(constants.HTTP_400_BAD_REQUEST)
         self.write(resp)
         return
     try:
         resp = Book().match(order)
         http_status_code = constants.HTTP_201_CREATED
     except Exception as e:
         resp = {"message": e.message}
         http_status_code = constants.HTTP_500_INTERNAL_SERVER_ERROR
     self.set_header(
         "location", "{}://{}{}".format(
             self.request.protocol, self.request.host,
             self.reverse_url("{}".format(constants.URL_NAME_BOOK))))
     self.set_status(http_status_code)
     self.write(resp)
Example #2
0
 def test_is_valid_with_valid_order(self):
     """
     Test is_valid method with valid order object.
     """
     buy = Buy(qty=1, prc=1)
     flag = buy.is_valid()
     assert flag == True
Example #3
0
 def test_is_valid_with_valid_order(self):
     """
     Test is_valid method with valid order object.
     """
     buy = Buy(qty=1, prc=1)
     flag = buy.is_valid()
     assert flag == True
Example #4
0
 def post(self, **kwargs):
     order = None
     resp = None
     body = json.loads(self.request.body)
     if self.request.uri == "{}".format(constants.URL_PATH_BUY):
         order = Buy(**body)
     if self.request.uri == "{}".format(constants.URL_PATH_SELL):
         order = Sell(**body)
     if not order.is_valid():
         resp = {"message": responses[constants.HTTP_400_BAD_REQUEST]}
         self.set_status(constants.HTTP_400_BAD_REQUEST)
         self.write(resp)
         return
     try:
         resp = Book().match(order)
         http_status_code = constants.HTTP_201_CREATED
     except Exception as e:
         resp = {"message": e.message}
         http_status_code = constants.HTTP_500_INTERNAL_SERVER_ERROR
     self.set_header("location", "{}://{}{}".format(self.request.protocol,
         self.request.host, self.reverse_url("{}".format(constants.URL_NAME_BOOK))))
     self.set_status(http_status_code)
     self.write(resp)