Exemplo n.º 1
0
def add_store_with_x():
    store = models.StoreModel("StoreXYZ")
    try:
        store.save_to_db()
    except ValidationError :
        session.rollback()  
    else:
        print("Missing Constraint exception: 'NO x in Store Name'")
Exemplo n.º 2
0
def add_store_and_delete_again():
    store = models.StoreModel("StoreToAdd")
    store.save_to_db()
    print("added store: {}".format(store.json()))
    count_stores()
    store.delete_from_db()
    print("store  deleted")
    count_stores()
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
    def test_add_store_with_x_trigger_constraint(self):
        store = models.StoreModel("StoreXYZ")
        result: (Exception, None) = None
        try:
            store.save_to_db()
        except ConstraintException as e:
            print("expected exception: {} ".format(e))
            session = db.Session()
            session.rollback()
            result = e
        else:
            print("Missing Constraint exception: 'NO x in Store Name'")

        self.assertIsInstance(result, ConstraintException)
Exemplo n.º 5
0
 def test_add_store_and_delete_again(self):
     orig = count_stores()
     expected = orig + 1
     store = models.StoreModel("StoreToAdd")
     store.save_to_db()
     result = count_stores()
     print("added store: {}".format(store.json()))
     self.assertEqual(result, expected)
     store.delete_from_db()
     result = count_stores()
     expected = orig
     self.assertEqual(result, expected)
     print("store  deleted")
     count_stores()
Exemplo n.º 6
0
 def test_add_store_and_delete_again(self):
     orig = count_stores()
     expected = orig + 1
     store = models.StoreModel(name="StoreToAdd",
                               email="*****@*****.**",
                               store_type="pos")
     store.save_to_db()
     util.log(store.json())
     result = count_stores()
     print("added store: {}".format(store.json()))
     self.assertEqual(result, expected)
     store.delete_from_db()
     result = count_stores()
     expected = orig
     self.assertEqual(result, expected)
     print("store  deleted")
     count_stores()
Exemplo n.º 7
0
 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()
Exemplo n.º 8
0
    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)