Beispiel #1
0
    def test_delete_a_shopcart(self):
        """Delete a shopcart and everything in it"""
        self.assertEqual(len(Shopcart.all()), 0)

        shopcart = Shopcart(user_id=12345)
        shopcart.create()

        self.assertEqual(shopcart.id, 1)
        self.assertEqual(len(Shopcart.all()), 1)

        self.assertEqual(len(ShopcartItem.all()), 0)

        shopcart_item = ShopcartItem(sid=1, sku=5000, name="soap", price=2.23, amount=3)
        shopcart_item.create()
        self.assertEqual(shopcart_item.id, 1)

        shopcart_item = ShopcartItem(sid=1, sku=5001, name="shampoo", price=3.77, amount=1)
        shopcart_item.create()
        self.assertEqual(shopcart_item.id, 2)

        self.assertEqual(len(ShopcartItem.all()), 2)

        shopcart.delete()
        self.assertEqual(len(ShopcartItem.all()), 0)
        self.assertEqual(len(Shopcart.all()), 0)
Beispiel #2
0
    def test_delete_a_shopcart_item(self):
        """Delete a shopcart item"""
        shopcart = Shopcart(user_id=12345)
        shopcart.create()
        self.assertEqual(shopcart.id, 1)

        self.assertEqual(len(ShopcartItem.all()), 0)
        shopcart_item = ShopcartItem(sid=1, sku=5000, name="soap", price=2.23, amount=3)
        shopcart_item.create()
        self.assertEqual(shopcart_item.id, 1)
        self.assertEqual(len(ShopcartItem.all()), 1)

        shopcart_item.delete()
        self.assertEqual(len(ShopcartItem.all()), 0)
Beispiel #3
0
    def test_delete_shopcart_items(self):
        """Delete a Shopcart Item"""
        shopcart = self._create_shopcarts(1)[0]
        shopcart_id = shopcart.id

        self.assertEqual(len(ShopcartItem.all()), 0)
        shopcart_item = self._create_shopcart_items(1, shopcart_id)[0]
        self.assertEqual(len(ShopcartItem.all()), 1)

        resp = self.app.delete("/api/shopcarts/{}/items/{}".format(
            shopcart_id, shopcart_item.id),
                               content_type="application/json")
        self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
        self.assertEqual(len(resp.data), 0)

        self.assertEqual(len(ShopcartItem.all()), 0)
Beispiel #4
0
    def test_place_order(self):
        """ Test sending shopcart order """
        test_shopcart = ShopcartFactory()
        resp = self.app.post("/api/shopcarts",
                             json={"user_id": test_shopcart.user_id},
                             content_type="application/json")
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)
        shopcart_id = resp.json["id"]
        shopcart_items = self._create_shopcart_items(10, shopcart_id)
        test_sku = shopcart_items[0].sku
        sku_shopcart_items = [
            shopcart_item for shopcart_item in shopcart_items
            if shopcart_item.sku == test_sku
        ]
        resp = self.app.get("/api/shopcarts/items",
                            query_string="sku={}".format(test_sku))
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        data = resp.get_json()
        self.assertEqual(len(data), len(sku_shopcart_items))

        resp = self.app.put(
            "/api/shopcarts/{}/place-order".format(shopcart_id),
            content_type="application/json",
        )
        self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
        self.assertEqual(len(resp.data), 0)
        self.assertEqual(len(Shopcart.all()), 0)
        self.assertEqual(len(ShopcartItem.all()), 0)
Beispiel #5
0
    def get(self):
        """ Returns all of the ShopcartItems """
        logger.info('Request to list ShopcartItems...')

        args = shopcart_item_args.parse_args()

        if args['sku']:
            logger.info('Find by sku')
            shopcart_items = ShopcartItem.find_by_sku(args['sku'])
        elif args['name']:
            logger.info('Find by name')
            shopcart_items = ShopcartItem.find_by_name(args['name'])
        elif args['price']:
            logger.info('Find by price')
            shopcart_items = ShopcartItem.find_by_price(args['price'])
        elif args['amount']:
            logger.info('Find by amount')
            shopcart_items = ShopcartItem.find_by_amount(args['amount'])
        else:
            logger.info('Find all')
            shopcart_items = ShopcartItem.all()

        results = [shopcart_item.serialize() for shopcart_item in shopcart_items]
        logger.info('[%s] Shopcart Items returned', len(results))
        return results, status.HTTP_200_OK
Beispiel #6
0
    def test_delete_shopcart(self):
        """Delete a Shopcart and everything in it"""
        self.assertEqual(len(Shopcart.all()), 0)

        shopcart = self._create_shopcarts(1)[0]

        self.assertEqual(len(Shopcart.all()), 1)
        self.assertEqual(len(ShopcartItem.all()), 0)

        self._create_shopcart_items(5, shopcart.id)

        self.assertEqual(len(ShopcartItem.all()), 5)

        resp = self.app.delete("/shopcarts/{}".format(shopcart.id),
                               content_type="application/json")
        self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
        self.assertEqual(len(resp.data), 0)

        self.assertEqual(len(Shopcart.all()), 0)
        self.assertEqual(len(ShopcartItem.all()), 0)
Beispiel #7
0
    def test_update_a_shopcart_item(self):
        """ Update a shopcart item """
        shopcart = Shopcart(user_id=12345)
        shopcart.create()

        shopcart_item = ShopcartItem(sid=shopcart.id, sku=5000, name="soap", price=2.23,
                                     amount=3)
        shopcart_item.create()
        self.assertEqual(shopcart_item.id, 1)
        # Change it an update it
        shopcart_item.name = "soap"
        shopcart_item.update()
        self.assertEqual(shopcart_item.id, 1)
        # Fetch it back and make sure the id hasn't changed
        # but the data did change
        shopcart_item = ShopcartItem.all()
        self.assertEqual(len(shopcart_item), 1)
        self.assertEqual(shopcart_item[0].name, "soap")