示例#1
0
 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))
示例#2
0
 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))
示例#3
0
    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)
示例#4
0
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
示例#5
0
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
示例#6
0
 def test_ping_returns_true_if_available(self):
     ping = heartbeat(self.permission)
     self.assertTrue(ping(self.request))
示例#7
0
 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))
示例#8
0
 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))
示例#9
0
 def test_ping_returns_true_if_available(self):
     ping = heartbeat(self.permission)
     self.assertTrue(ping(self.request))
示例#10
0
 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))
示例#11
0
 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))