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 userInGroup(groupId, userId): return q.checkRecordExistByConditions( "GroupUsers", "group_id = '%s' AND member_id " " = '%s'", (groupId, userId), )
def test_sign_up_notexist(self): username = "******" userpwd = "12345" check = q.checkRecordExistByConditions( "Users", "user_name = '%s' AND " "user_pwd = '%s'", (username, userpwd), ) self.assertFalse(check) # No such user f.signUp(username, userpwd) check = q.checkRecordExistByConditions( "Users", "user_name = '%s' AND " "user_pwd = '%s'", (username, userpwd), ) self.assertTrue(check) # Exist now
def test_login_notexist(self): username = "******" userpwd = "12345" check = q.checkRecordExistByConditions( "Users", "user_name = '%s' AND user_pwd = '%s'", (username, userpwd), ) self.assertFalse(check) # No such user u_id = f.login(username, userpwd) # invalid u_id indicating no such user exist self.assertEqual(u_id, -1)
def test_sign_up_exist(self): username = "******" userpwd1 = "12345" userpwd2 = "123456" f.signUp(username, userpwd1) # "Jason" inserted f.signUp(username, userpwd2) # Same name but different pwds check = q.checkRecordExistByConditions( "Users", "user_name = '%s' AND user_pwd = '%s'", (username, userpwd2), ) self.assertFalse(check) # Still no exist now
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_create_group_with_members(self): # numOfGroups = q.getNumOfRecordByConditions("gGroups") self.assertEqual(q.getNumOfRecordByConditions("gGroups"), 0) # No exsiting group # Create group members memberIds = [] ownerId = f.signUp("Amy", "1234") # Amy is the group owner # Create member list memberIds.append(f.signUp("Bob", "1234")) memberIds.append(f.signUp("Candy", "1234")) groupName = "group1" # Groupname: "group1", ownerId = 1, memberIds = [2,3] groupId = f.createGroupWithMembers(groupName, ownerId, memberIds) # check if group exists now check = q.checkRecordExistByConditions( "gGroups", "group_name = '%s' AND owner_id = '%s'", (groupName, ownerId), ) self.assertTrue(check) # The group exsits now # For convenience, add the owner to the memberlist memberIds.append(ownerId) # Member list result_list = q.selectInfoByConditions( "GroupUsers", "member_id", "group_id = '%s'", str(groupId), ) self.assertEqual(len(result_list), len(memberIds)) # All members in the tables from memberIds membersDB = u.getAllMemberIds(groupId) self.assertEqual(set(membersDB), set(memberIds))
def groupNameExists(groupName): return q.checkRecordExistByConditions("gGroups", "group_name = '%s'", groupName)
def groupExists(groupId): return q.checkRecordExistByConditions("gGroups", "group_id = '%s'", groupId)
def usernameExists(username): return q.checkRecordExistByConditions("Users", "user_name = '%s'", username)
def itemExists(itemId): return q.checkRecordExistByConditions("Items", "item_id = '%s'", itemId)
def orderExists(orderId): return q.checkRecordExistByConditions("Orders", "order_id = '%s'", orderId)
def allocationExists(alloId): return q.checkRecordExistByConditions("Allocations", "allo_id = '%s'", alloId)