Example #1
0
 def test_delete_a_product(self):
     """ Delete a Product """
     product = Product(
         name="Wagyu Tenderloin Steak",
         category="food",
         stock=11,
         price=20.56,
         description="The most decadent, succulent cut of beef, ever.")
     product.save()
     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)
Example #2
0
 def post(self):
     """
     Creates a Product
     This endpoint will create a Product based the data in the body that is posted
     """
     app.logger.info('Request to create a product')
     check_content_type('application/json')
     product = Product()
     app.logger.debug('Payload = %s', api.payload)
     product.deserialize(api.payload)
     product.save()
     location_url = api.url_for(ProductResource,
                                product_id=product.id,
                                _external=True)
     return product.serialize(), status.HTTP_201_CREATED, {
         'Location': location_url
     }
Example #3
0
 def test_find_product(self):
     """ Find a Product by ID """
     Product(name="Wagyu Tenderloin Steak",
             category="food",
             stock=11,
             price=20.56,
             description="The most decadent, succulent cut of beef, ever."
             ).save()
     shampo = Product(name="shampos",
                      category="Health Care",
                      stock=48,
                      price=12.34)
     shampo.save()
     product = Product.find(shampo.id)
     self.assertIsNot(product, None)
     self.assertEqual(product.id, shampo.id)
     self.assertEqual(product.name, "shampos")
     self.assertEqual(product.category, "Health Care")
Example #4
0
 def test_update_a_product(self):
     """ Update a Product """
     product = Product(
         name="Wagyu Tenderloin Steak",
         category="food",
         stock=11,
         price=20.56,
         description="The most decadent, succulent cut of beef, ever.")
     product.save()
     self.assertEqual(product.id, 1)
     # Change it an save it
     product.category = "beverage"
     product.save()
     self.assertEqual(product.id, 1)
     # Fetch it back and make sure the id hasn't changed
     # but the data did change
     products = Product.all()
     self.assertEqual(len(products), 1)
     self.assertEqual(products[0].category, "beverage")
Example #5
0
 def test_add_a_product(self):
     """ Create a product and add it to the database """
     products = Product.all()
     self.assertEqual(products, [])
     product = Product(
         name="Wagyu Tenderloin Steak",
         category="food",
         stock=11,
         price=20.56,
         description="The most decadent, succulent cut of beef, ever.")
     self.assertTrue(product != None)
     self.assertEqual(product.id, None)
     self.assertEqual(product.name, "Wagyu Tenderloin Steak")
     self.assertEqual(product.category, "food")
     self.assertAlmostEqual(product.price, Decimal(20.56))
     self.assertEqual(product.stock, 11)
     product.save()
     # Asert that it was assigned an id and shows up in the database
     self.assertEqual(product.id, 1)
     products = Product.all()
     self.assertEqual(len(products), 1)