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 get_user(username): # Get info from database doc_data = {'collection_name': 'users', 'document_id': username} r = requests.get(database_url, json=doc_data) if r.status_code == requests.codes.ok: user_js = r.json() return User(**user_js) return None
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_invalid_param(self): self.assertFalse(AccountManager.update_user(5, User('user')))
def test_update_nonexistent(self): self.assertFalse( AccountManager.update_user('notauser', User(**bare_user)))
def test_username_taken(self): self.assertFalse( AccountManager.update_user(user1['username'], User(**user2)))
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 make_user(self, data): return User(**data)