def testUserToggleRevokedHandler(self): """Test toggle revoked handler changes the revoked status for a user.""" user = self._CreateAndSaveFakeUser() initial_revoked_status = user.is_key_revoked user.did_cron_revoke = True user.save() post_data = {'user_id': json.dumps(user.id)} response = self.client.post(flask.url_for('user_toggle_revoked'), data=post_data, follow_redirects=False) self.assertEquals(not initial_revoked_status, user.is_key_revoked) self.assertEquals(False, user.did_cron_revoke) self.assert_redirects(response, flask.url_for('user_list'))
def testListUsersHandler(self): """Test the list user handler gets users from the database.""" users = [] for fake_email_and_name in base_test.FAKE_EMAILS_AND_NAMES: user = models.User(email=fake_email_and_name['email'], name=fake_email_and_name['name'], private_key=fake_email_and_name['pri'], public_key=fake_email_and_name['pub']) user.save() users.append(user) resp = self.client.get(flask.url_for('user_list')) user_list_output = json.loads(resp.data[len(ufo.XSSI_PREFIX):])['items'] self.assertEquals(len(user_list_output), len(base_test.FAKE_EMAILS_AND_NAMES)) for user in users: self.assertIn(user.to_dict(), user_list_output)
def _CreateAndSaveFakeUser(self): """Create a fake user object, and save it into db.""" user = models.User(email=base_test.FAKE_EMAILS_AND_NAMES[0]['email'], name=base_test.FAKE_EMAILS_AND_NAMES[0]['name']) return user.save()