Beispiel #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,
                            'user_principals',
                            side_effect=exceptions.BackendError("Boom!")):
         self.assertFalse(ping(self.request))
Beispiel #2
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('cliquet.permission.logger.exception') as exc_handler:
            self.assertFalse(ping(self.request))

        self.assertTrue(exc_handler.called)
Beispiel #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('cliquet.permission.logger.exception') as exc_handler:
            self.assertFalse(ping(self.request))

        self.assertTrue(exc_handler.called)
Beispiel #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("Invalid permission backend: %s" % backend)
    config.registry.permission = backend

    heartbeat = permission.heartbeat(backend)
    config.registry.heartbeats['permission'] = heartbeat
Beispiel #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
Beispiel #6
0
 def test_ping_returns_true_if_available(self):
     ping = heartbeat(self.permission)
     self.assertTrue(ping(self.request))
Beispiel #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))
Beispiel #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))
Beispiel #9
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, 'user_principals',
                            side_effect=exceptions.BackendError("Boom!")):
         self.assertFalse(ping(self.request))
Beispiel #10
0
 def test_ping_returns_true_if_available(self):
     ping = heartbeat(self.permission)
     self.assertTrue(ping(self.request))
Beispiel #11
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))
Beispiel #12
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))