def add_store_and_item_and_delete_again(): store = models.StoreModel("StoreToAdd") store.save_to_db() item1 = models.ItemModel('item1', 9.99, store.id) item2 = models.ItemModel('item2', 8.99, store.id) item1.save_to_db() item2.save_to_db() count_items_for_store(store.id) print("Item_Count from LogicRule: {}".format(store.item_count)) item1.delete_from_db() item2.delete_from_db() count_items_for_store(store.id) print("Item_Count from LogicRule: {}".format(store.item_count)) store.delete_from_db()
def add_item_non_existing_parent(): try: item1 = models.ItemModel('itemNoParent', 9.99, 4711) item1.save_to_db() except Exception as e: print("expected exception: {} ".format(e)) session.rollback() else: print("Missing Constraint exception: 'no parent for item'")
def post(self): new_item = models.ItemModel( name=request.form['name'], description=request.form['description'], categoryid=request.form['category_id'], createdate=datetime.datetime.now() ) new_item.save_to_db() response = jsonify({'success': 200}) return response
def test_add_store_and_item_and_delete_again(self): store = models.StoreModel("StoreToAdd") store.save_to_db() item1 = models.ItemModel('item1', 9.99, store.id) item2 = models.ItemModel('item2', 8.99, store.id) item1.save_to_db() item2.save_to_db() result = count_items_for_store(store.id) expected = 2 self.assertEqual(result, expected) self.assertEqual(store.item_count, expected) print("Item_Count from LogicRule: {}".format(store.item_count)) item1.delete_from_db() item2.delete_from_db() result = count_items_for_store(store.id) expected = 0 self.assertEqual(result, expected) self.assertEqual(store.item_count, expected) print("Item_Count from LogicRule: {}".format(store.item_count)) store.delete_from_db()
def test_add_store_and_item_and_delete_again_store_first(self): store = models.StoreModel("StoreToAddFkUnitTest") store.save_to_db() item1 = models.ItemModel('item1FkUnitTest', 9.98, store.id) item2 = models.ItemModel('item2FkUnitTest', 8.98, store.id) item1.save_to_db() item2.save_to_db() result = count_items_for_store(store.id) expected = 2 self.assertEqual(result, expected) self.assertEqual(store.item_count, expected) print("ItemCount from LogicRule: {}".format(store.item_count)) result: (Exception, None) = None try: store.delete_from_db() except ConstraintException as e: print("expected exception: {} ".format(e)) session = db.Session() session.rollback() result = e except Exception as e: print("unexcpected expected exception: {} ".format(e)) session = db.Session() session.rollback() result = e else: print( "Missing Constraint exception: 'Delete rejected - items has rows'" ) finally: count_items_for_store(store.id) item1.delete_from_db() item2.delete_from_db() count_items_for_store(store.id) store.delete_from_db() print("Finally Delete Store and Items in correct order") self.assertIsInstance(result, ConstraintException)
def add_item_no_parent(): item1 = models.ItemModel('itemNoParent', 9.99, None) item1.save_to_db()