def test_delete_a_product(self): """ Delete a Product """ product = Product(name="iPhone X", description="Black iPhone", category="Technology", price=999.99) product.create() self.assertEqual(len(Product.all()), 1) # delete the product and make sure it isn't in the database product.delete() self.assertEqual(len(Product.all()), 0)
def test_delete_a_product_commit_error(self): """ Delete a Product """ product = Product(name="iPhone X", description="Black iPhone", category="Technology", price=999.99) product.create() self.assertEqual(len(Product.all()), 1) # delete the product and make sure it isn't in the database with patch('service.models.db.session.commit') as commit: commit.side_effect = InvalidRequestError product.delete() self.assertEqual(len(Product.all()), 1)