def put_user(self, user_id): client = self._get_datastore_client() result = util._validate_json(flask.request) if result is not True: return result json = flask.request.get_json() json = util._escape_json(json) result = self._validate_create_user(user_id, json) if result is not True: return result result = self._validate_fields(json) if result is not True: return result with client.transaction(): try: if users.check_if_user_exists(client, user_id): return self.Response('User exists', status=409) entity = users.get_empty_user_entity(client, user_id) util._update_entity(json, ALL_MUTABLE_FIELDS, entity) users.create_or_update_user(client, entity) roles.create_user_role(client, user_id) except Exception as e: logging.error("Datastore put operation failed: %s" % str(e)) self.Response('Internal server error', status=500) return self.Response('OK', status=200)
def test_delete_user_role(self): result = roles.create_user_role(self.datastore_client, self.USER_HASH) self.assertTrue(result) result = roles.delete_user_role(self.datastore_client, self.USER_HASH) self.assertTrue(result) get_roles = roles.get_all_user_roles(self.datastore_client) self.assertEqual(get_roles, {})
def test_update_user_role(self): result = roles.create_user_role(self.datastore_client, self.USER_HASH) self.assertTrue(result) result = roles.update_user_role(self.datastore_client, self.USER_HASH, ['admin']) self.assertTrue(result) get_roles = roles.get_user_role(self.datastore_client, self.USER_HASH) self.assertEqual(get_roles, ['admin'])
def test_create_user_role_exists(self): result = roles.create_user_role(self.datastore_client, self.USER_HASH) self.assertTrue(result) result = roles.create_user_role(self.datastore_client, self.USER_HASH) self.assertFalse(result)
def _create_user_via_datastore(self, userid_hash): user = datastore.Entity(key=self.client.key("User", userid_hash)) user['name'] = u"Test User " + userid_hash user['email'] = u"test" + userid_hash + u"@example.com" users.create_or_update_user(self.client, user) roles.create_user_role(self.client, userid_hash)
def test_get_count_not_admin(self): self._setup_user(self.USER_HASH) roles.create_user_role(self.datastore_client, self.USER_HASH, [u'user']) self._get_count_root(expected_status=403)
def test_get_location(self): self._setup_user(self.USER_HASH) roles.create_user_role(self.datastore_client, self.USER_HASH, [u'admin']) self._get_location_root(expected_status=200)