def test_ping_returns_false_if_unavailable_in_readonly_mode(self): self.request.registry.settings["readonly"] = "true" ping = heartbeat(self.permission) with mock.patch.object( self.permission, "get_user_principals", side_effect=exceptions.BackendError("Boom!") ): self.assertFalse(ping(self.request))
def test_ping_returns_false_if_unavailable_in_readonly_mode(self): self.request.registry.settings['readonly'] = 'true' ping = heartbeat(self.permission) with mock.patch.object(self.permission, 'get_user_principals', side_effect=exceptions.BackendError("Boom!")): self.assertFalse(ping(self.request))
def test_ping_logs_error_if_unavailable(self): for patch in self.client_error_patcher: patch.start() ping = heartbeat(self.permission) with mock.patch("kinto.core.permission.logger.exception") as exc_handler: self.assertFalse(ping(self.request)) self.assertTrue(exc_handler.called)
def setup_permission(config): settings = config.get_settings() permission_mod = settings["permission_backend"] if not permission_mod: return permission_mod = config.maybe_dotted(permission_mod) backend = permission_mod.load_from_config(config) if not isinstance(backend, permission.PermissionBase): raise ConfigurationError(f"Invalid permission backend: {backend}") config.registry.permission = backend heartbeat = permission.heartbeat(backend) config.registry.heartbeats["permission"] = heartbeat
def setup_permission(config): settings = config.get_settings() permission_mod = settings['permission_backend'] if not permission_mod: return permission_mod = config.maybe_dotted(permission_mod) backend = permission_mod.load_from_config(config) if not isinstance(backend, permission.PermissionBase): raise ConfigurationError("Invalid permission backend: %s" % backend) config.registry.permission = backend heartbeat = permission.heartbeat(backend) config.registry.heartbeats['permission'] = heartbeat
def test_ping_returns_true_if_available(self): ping = heartbeat(self.permission) self.assertTrue(ping(self.request))
def test_ping_returns_false_if_unavailable(self): ping = heartbeat(self.permission) for patch in self.client_error_patcher: patch.start() self.assertFalse(ping(self.request))
def test_ping_returns_true_if_available_in_readonly_mode(self): self.request.registry.settings['readonly'] = 'true' ping = heartbeat(self.permission) self.assertTrue(ping(self.request))