def test_update_new_username(self): # update to a new username before = User(**updated_user1) before.username = '******' AccountManager.update_user(user1['username'], before) after = get_user(before.username) self.assertDictEqual(after.to_dict(), before.to_dict())
def update_user(username, update_user): current = get_user(username) if current is None: return False if current.group_id is not None \ and update_user.group_id is not None \ and current.group_id != update_user.group_id: remove_user(username, current.group_id) return UserManager.update_user(username, update_user)
def verify_file(filepath): try: with open(filepath, 'r') as f: lines = f.readlines() except FileNotFoundError: return False lines = [line for line in lines if re.match('.*\\S.*', line)] if not lines: # empty file return False file_users = [] for line in lines: users = line.strip().split() for user in users: if get_user(user) is not None: # username is taken return False if user in file_users: # duplicate user return False file_users.append(user) return True
def test_delete_user(self): AccountManager.delete_user(user1['username']) self.assertIsNone(get_user(user1['username']))
def test_deleted_prev(self): # update to a new username user = User(**updated_user1) user.username = '******' AccountManager.update_user(user1['username'], user) self.assertIsNone(get_user(user1['username']))
def test_update_user(self): # update everything but keep the username AccountManager.update_user(user1['username'], User(**updated_user1)) user = get_user(user1['username']).to_dict() self.assertDictEqual(user, updated_user1)
def tearDown(self): for line in file_users: current = get_user(line[0]).group_id AccountManager.delete_group(current)
def delete_user(username): current = get_user(username) user_deleted = UserManager.delete_user(username) if user_deleted and current is not None and current.group_id is not None: remove_user(username, current.group_id) return user_deleted
def test_get_invalid_param(self): self.assertIsNone(get_user(1))
def test_get_unknown_user(self): self.assertIsNone(get_user('unknown_user'))
def test_get_user(self): user = get_user(user1['username']).to_dict() self.assertDictEqual(user, user1)
def test_create_user(self): create_user(**user1) user = get_user(user1['username']).to_dict() self.assertDictEqual(user, user1)