예제 #1
0
    def test_checkout_shopcart(self):
        """ Checkout a Shopcart REAL """
        shopcart = self._create_shopcarts(1)[0]
        item = ItemFactory()
        resp = self.app.post("/shopcarts/{}/items".format(shopcart.id),
                             json=item.serialize(),
                             content_type=CONTENT_TYPE_JSON)
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)

        resp2 = self.app.put("/shopcarts/{}".format(shopcart.id),
                             json=item.serialize(),
                             content_type=CONTENT_TYPE_JSON)
        self.assertEqual(resp2.status_code, status.HTTP_204_NO_CONTENT)
예제 #2
0
    def test_update_item(self):
        """ Update an item on an shopcart """
        # create a known item
        shopcart = self._create_shopcarts(1)[0]
        item = ItemFactory()
        resp = self.app.post("/shopcarts/{}/items".format(shopcart.id),
                             json=item.serialize(),
                             content_type="application/json")
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)

        data = resp.get_json()
        logging.debug(data)
        item_id = data["id"]
        data["item_name"] = "XXXX"

        # send the update back
        resp = self.app.put("/shopcarts/{}/items/{}".format(
            shopcart.id, item_id),
                            json=data,
                            content_type="application/json")
        self.assertEqual(resp.status_code, status.HTTP_200_OK)

        # retrieve it back
        resp = self.app.get("/shopcarts/{}/items/{}".format(
            shopcart.id, item_id),
                            content_type="application/json")
        self.assertEqual(resp.status_code, status.HTTP_200_OK)

        data = resp.get_json()
        logging.debug(data)
        self.assertEqual(data["id"], item_id)
        self.assertEqual(data["shopcart_id"], shopcart.id)
        self.assertEqual(data["item_name"], "XXXX")
예제 #3
0
 def test_add_item(self):
     """ Add an item to a shopcart """
     shopcart = self._create_shopcarts(1)[0]
     item = ItemFactory()
     resp = self.app.post("/shopcarts/{}/items".format(shopcart.id),
                          json=item.serialize(),
                          content_type="application/json")
     self.assertEqual(resp.status_code, status.HTTP_201_CREATED)
     data = resp.get_json()
     logging.debug(data)
     self.assertEqual(data["shopcart_id"], shopcart.id)
     self.assertIsNotNone(data["id"])
     self.assertEqual(data["item_name"], item.item_name)
     self.assertEqual(data["item_quantity"], item.item_quantity)
     self.assertEqual(data["item_price"], item.item_price)
예제 #4
0
    def test_delete_shopcart(self):
        """ Delete a shopcart """
        shopcart = self._create_shopcarts(1)[0]
        item = ItemFactory()
        resp = self.app.post("/shopcarts/{}/items".format(shopcart.id),
                             json=item.serialize(),
                             content_type="application/json")
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)
        data = resp.get_json()
        logging.debug(data)
        item_id = data["id"]

        # send delete request
        resp = self.app.delete("/shopcarts/{}".format(shopcart.id),
                               content_type="application/json")
        self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
예제 #5
0
    def test_get_item_list(self):
        """ Get an item from a shopcart """
        # create a known item
        shopcart = self._create_shopcarts(1)[0]
        item = ItemFactory()
        resp = self.app.post("/shopcarts/{}/items".format(shopcart.id),
                             json=item.serialize(),
                             content_type="application/json")
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)

        data = resp.get_json()
        logging.debug(data)
        shopcart_id = data["id"]

        # retrieve it back
        resp = self.app.get("/shopcarts/{}/items".format(shopcart.id),
                            content_type="application/json")
        self.assertEqual(resp.status_code, status.HTTP_200_OK)

        data = resp.get_json()
        logging.debug(data)