def delete_product(): if request.method == 'POST': name = request.form['product-name'] product_instance = Products() product_instance.delete_product(name) return redirect('/products') else: return render_template('delete_product.html')
def test_delete_product(self): """test delete product method for products""" product_key_to_delete = 'cucumber' product_instance = Products() # method should return object added if successful test = product_instance.delete_product(product_key_to_delete) self.assertEqual(test, {'name': product_key_to_delete}) # method should return 0 if the key does not exist product_key_to_delete_2 = 'apple pie' test2 = product_instance.delete_product(product_key_to_delete_2) self.assertEqual(test2, 0)