def test_create_empty_group_exist_name(self): ownerId = f.signUp("Jason", "12345") groupName = "unique group name" g_id = f.createEmptyGroup(groupName, ownerId) g_id = f.createEmptyGroup(groupName, ownerId) self.assertEqual(g_id, -1)
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_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_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_create_empty_group_notexist(self): ownerId = f.signUp("Jason", "12345") groupName = "group1" check = q.checkRecordExistByConditions( "gGroups", "group_name = '%s'", groupName, ) self.assertFalse(check) # No such group exsit g_id = f.createEmptyGroup(groupName, ownerId) # create a new group check = q.checkRecordExistByConditions( "gGroups", "group_name = '%s' AND owner_id = '%s'", (groupName, ownerId), ) self.assertTrue(check) # The group exsits now check = q.checkRecordExistByConditions( "GroupUsers", "group_id = '%s' AND member_id = '%s'", (g_id, ownerId), ) self.assertTrue(check) # Owner in this group now
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_create_empty_group_exist(self): ownerId = f.signUp("Jason", "12345") groupName = "group1" g_id = f.createEmptyGroup(groupName, ownerId) # create a new group check = q.checkRecordExistByConditions( "gGroups", "group_name = '%s'", groupName, ) self.assertTrue(check) # No such group exsit g_id = f.createEmptyGroup(groupName, ownerId) # insert again result_list = q.selectAllByConditions( "gGroups", "group_name = '%s'", groupName, ) self.assertEqual(g_id, -1) self.assertEqual(len(result_list), 1) # Only one record exsit
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_receipt(self): # No exsiting receipt self.assertEqual(q.getNumOfRecordByConditions("OrderReceipts"), 0) groupId = f.createEmptyGroup("Group", f.signUp("Owner", "12345")) orderId = f.createOrder(groupId, "Order", 5) receiptIdx = 1 f.createReceipt(orderId, "abc.jpg", receiptIdx) numOfRecords = q.getNumOfRecordByConditions( "OrderReceipts", " order_id = '%s' AND receipt_idx = '%s'", (orderId, receiptIdx), ) self.assertEqual(numOfRecords, 1)
def test_delete_order(self): ownerId = f.signUp("Owner", "12345") groupId = f.createEmptyGroup("Group", ownerId) orderName = "Order0" numOfItems = 5 orderId = f.createOrder(groupId, orderName, numOfItems) f.deleteOrder(orderId) numOfRecord = q.getNumOfRecordByConditions( "Orders", "order_id = '%s'", str(orderId), ) self.assertEqual(numOfRecord, 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_create_order(self): ownerId = f.signUp("Owner", "12345") groupId = f.createEmptyGroup("Group", ownerId) orderName = "Order0" numOfItems = 5 self.assertEqual( q.getNumOfRecordByConditions("Orders", ), 0, ) # No exsiting group orderId = f.createOrder(groupId, orderName, numOfItems) result_list = q.selectAllByConditions("Orders") self.assertEqual(len(result_list), 1) self.assertEqual(result_list[0]['order_id'], 1) self.assertEqual(result_list[0]['group_id'], groupId) self.assertEqual(result_list[0]['order_name'], orderName) self.assertEqual(result_list[0]['item_unres_num'], numOfItems)
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)
def test_create_empty_group(self): ownerId = f.signUp("Jason", "12345") groupName = "unique group name" g_id = f.createEmptyGroup(groupName, ownerId) # create a new group self.assertNotEqual(g_id, -1)