Exemplo n.º 1
0
 def test_delete_a_shopcart_entry(self):
     """ Delete a shopcart entry """
     shopcart = Shopcart(user_id=999, product_id=999, quantity=999, price=999.99)
     shopcart.save()
     self.assertEqual(Shopcart.findByUserId(999).count(), 1)
     # delete item and make sure it isn't in the database
     shopcart.delete()
     self.assertEqual(Shopcart.findByUserId(999).count(), 0)
Exemplo n.º 2
0
 def test_add_a_shopcart_entry(self):
     """ Create a shopcart entry and add it to the database """
     shopcarts = Shopcart.findByUserId(999)
     before_cnt = (shopcarts.count())
     #self.assertEqual(shopcarts, [])
     shopcart = Shopcart(user_id=999, product_id=999, quantity=888, price=999.99)
     self.assertTrue(shopcarts != None)
     self.assertEqual(shopcart.user_id, 999)
     shopcart.save()
     # Asert that it was assigned an id and shows up in the database
     shopcarts2 = Shopcart.findByUserId(999)
     self.assertEqual(shopcarts2.count(), before_cnt+1)
Exemplo n.º 3
0
    def test_findByUserId(self):
        """ Find shopcart list by user_id """
        shopcart = Shopcart(user_id=999, product_id=999, quantity=999, price=999.99)
        shopcart.save()

        shopcarts = Shopcart.findByUserId(999)
        self.assertIsNot(shopcarts, None)
        self.assertEqual(shopcarts[0].user_id, shopcart.user_id)
        self.assertEqual(shopcarts[0].product_id, shopcart.product_id)
Exemplo n.º 4
0
 def test_delete_user_product(self):
     """ Delete User Products """
     shopcart = Shopcart(user_id=1, product_id=1, quantity=1, price=12.00)
     shopcart.save()
     shopcart = Shopcart(user_id=1, product_id=2, quantity=1, price=12.00)
     shopcart.save()
     shopcart = Shopcart(user_id=1, product_id=3, quantity=1, price=12.00)
     shopcart.save()
     # delete item and make sure it isn't in the database
     shopcart.delete()
     shopcarts = Shopcart.findByUserId(1)
     self.assertIsNot(shopcarts, None)
    def test_shop_cart_amount_by_user_id(self):
        """ Query the total amount of products in shopcart by user_id"""
        shopcarts = Shopcart.findByUserId(1)
        total = 0.0
        for shopcart in shopcarts:
            total = total + shopcart.price * shopcart.quantity
        total = round(total, 2)

        resp = self.app.get('/shopcarts/1/total',
                            content_type='application/json')

        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        new_json = json.loads(resp.data)
        self.assertEqual(total, new_json['total_price'])
    def test_list_shop_cart_entry_by_user_id(self):
        """ Query shopcart by user_id """
        shopcart = Shopcart.findByUserId(1)
        print(shopcart[0].user_id)
        resp = self.app.get('/shopcarts/{}'.format(shopcart[0].user_id),
                            content_type='application/json')
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        data = json.loads(resp.data)
        self.assertTrue(len(resp.data) > 0)

        resp = self.app.get('/shopcarts/999', content_type='application/json')
        #self.assertRaises(NotFound)
        self.assertEqual(resp.status_code, status.HTTP_404_NOT_FOUND)
        data = json.loads(resp.data)
        print(data)
        print(data['message'])
        self.assertIn('was not found', data['message'])