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)
def test_update_a_shopcart_item_without_id(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() # Change it an update it shopcart_item.id = None self.assertRaises(DataValidationError, shopcart_item.update)
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)
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")