示例#1
0
 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())
示例#2
0
 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)
示例#3
0
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
示例#4
0
 def test_delete_user(self):
     AccountManager.delete_user(user1['username'])
     self.assertIsNone(get_user(user1['username']))
示例#5
0
 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']))
示例#6
0
 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)
示例#7
0
 def tearDown(self):
     for line in file_users:
         current = get_user(line[0]).group_id
         AccountManager.delete_group(current)
示例#8
0
 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
示例#9
0
 def test_get_invalid_param(self):
     self.assertIsNone(get_user(1))
示例#10
0
 def test_get_unknown_user(self):
     self.assertIsNone(get_user('unknown_user'))
示例#11
0
 def test_get_user(self):
     user = get_user(user1['username']).to_dict()
     self.assertDictEqual(user, user1)
示例#12
0
 def test_create_user(self):
     create_user(**user1)
     user = get_user(user1['username']).to_dict()
     self.assertDictEqual(user, user1)