def test_delete_allocation(self): userId = f.signUp("Amy", "12345") groupId = f.createEmptyGroup("Group", userId) orderId = f.createOrder(groupId, "Order", 5) oriAmount = 124.3 itemId = f.createItem("item", 124.3, orderId) alloAmount = 110 a_id = f.createAllocation(userId, itemId, alloAmount) check = f.deleteAllocation(a_id) self.assertTrue(check) self.assertEqual( q.getNumOfRecordByConditions( "Allocations", "allo_id = '%s'", a_id, ), 0, ) self.assertEqual( q.selectInfoByConditions( "Items", "left_amount", "item_id = '%s'", itemId, )[0]['left_amount'], oriAmount, )
def test_modify_allocation_invalid(self): userId = f.signUp("Amy", "12345") groupId = f.createEmptyGroup("Group", userId) orderId = f.createOrder(groupId, "Order", 5) oriAmount = 124.3 itemId = f.createItem("item", 124.3, orderId) prevAlloAmount = 110 curAlloAmount = 150 a_id = f.createAllocation(userId, itemId, prevAlloAmount) check = f.modifyAllocatedAmount(a_id, curAlloAmount) self.assertFalse(check) result = q.selectAllByConditions( "Allocations", "allo_id = '%s'", str(a_id), )[0] self.assertEqual(result['allo_amount'], prevAlloAmount) self.assertEqual( q.selectInfoByConditions( "Items", "left_amount", "item_id = '%s'", result['item_id'], )[0]['left_amount'], round(oriAmount - prevAlloAmount, 4), )
def test_create_allocation_invalid(self): # No exsiting allocation self.assertEqual( q.getNumOfRecordByConditions("Allocations", ), 0, ) # userId = f.signUp("Amy", "12345") groupId = f.createEmptyGroup("Group", userId) orderId = f.createOrder(groupId, "Order", 5) oriAmount = 124.3 itemId = f.createItem("item", oriAmount, orderId) alloAmount = 150 a_id = f.createAllocation(userId, itemId, alloAmount) result_list = q.selectInfoByConditions( "Items", "left_amount", "item_id = '%s'", itemId, ) self.assertEqual(a_id, -1) self.assertEqual(len(result_list), 1) self.assertEqual(result_list[0]['left_amount'], oriAmount) # remains numOfRecords = q.getNumOfRecordByConditions( "Allocations", "item_id = '%s' AND user_id = '%s'", (itemId, userId), ) self.assertEqual(numOfRecords, 0)
def test_modify_item_amount(self): groupId = f.createEmptyGroup("Group", f.signUp("Owner", "12345")) orderId = f.createOrder(groupId, "Order", 5) itemPrevAmount = 124.3 itemCurAmount_valid = 150 itemCurAmount_small = -34 itemCurAmount_Large = 1001 itemId = f.createItem("itemOld", 124.3, orderId) check = f.modifyItemAmount(itemId, itemCurAmount_valid) result_list = q.selectInfoByConditions( "Items", "left_amount", "item_id = '%s'", itemId, ) self.assertTrue(check) self.assertEqual(len(result_list), 1) self.assertEqual(result_list[0]['left_amount'], itemCurAmount_valid) f.modifyItemAmount(itemId, itemPrevAmount) # reset # Too small check = f.modifyItemAmount(itemId, itemCurAmount_small) result_list = q.selectInfoByConditions( "Items", "left_amount", "item_id = '%s'", itemId, ) self.assertFalse(check) self.assertEqual(len(result_list), 1) self.assertEqual( result_list[0]['left_amount'], itemPrevAmount, ) # remains # Too large check = f.modifyItemAmount(itemId, itemCurAmount_Large) result_list = q.selectInfoByConditions( "Items", "left_amount", "item_id = '%s'", itemId, ) self.assertFalse(check) self.assertEqual(len(result_list), 1) self.assertEqual( result_list[0]['left_amount'], itemPrevAmount, ) # remains
def test_delete_item(self): groupId = f.createEmptyGroup("Group", f.signUp("Owner", "12345")) orderId = f.createOrder(groupId, "Order", 5) itemId = f.createItem("item1", 124.3, orderId) f.deleteItem(itemId) numOfRecords = q.getNumOfRecordByConditions( "Items", "item_id = '%s'", itemId, ) self.assertEqual(numOfRecords, 0)
def test_create_item(self): # No exsiting receipt self.assertEqual(q.getNumOfRecordByConditions("Items"), 0) groupId = f.createEmptyGroup("Group", f.signUp("Owner", "12345")) orderId = f.createOrder(groupId, "Order", 5) itemName = "item1" leftAmount = 124.3 itemId = f.createItem(itemName, leftAmount, orderId) numOfRecords = q.getNumOfRecordByConditions( "Items", " order_id = '%s' AND item_name = '%s' AND left_amount = '%s'", (orderId, itemName, leftAmount), ) self.assertEqual(numOfRecords, 1) self.assertEqual(itemId, 1)
def test_modify_item_name(self): groupId = f.createEmptyGroup("Group", f.signUp("Owner", "12345")) orderId = f.createOrder(groupId, "Order", 5) itemOldName = "itemOld" itemNewName = "itemNew" itemId = f.createItem(itemOldName, 124.3, orderId) check = f.modifyItemName(itemId, itemNewName) result_list = q.selectInfoByConditions( "Items", "item_name", "item_id = '%s'", itemId, ) self.assertTrue(check) self.assertEqual(len(result_list), 1) self.assertEqual(result_list[0]['item_name'], itemNewName)