コード例 #1
0
    def test_callback_is_called_on_read_if_specified(self):
        config = self.make_app({
            'event_listeners.redis.actions': 'read',
        })
        event = ResourceRead(ACTIONS.READ, 123456, [], Request())
        config.registry.notify(event)

        self.assertTrue(self.redis_mocked.return_value.called)
コード例 #2
0
    def test_callback_is_not_called_on_read_by_default(self):
        config = self.make_app({
            'event_listeners': 'demo',
            'event_listeners.demo.use': 'tests.core.listeners',
        })
        event = ResourceRead({'action': ACTIONS.READ.value}, [], Request())
        config.registry.notify(event)

        self.assertFalse(self.demo_mocked.return_value.called)
コード例 #3
0
    def test_callback_is_called_on_read_if_specified(self):
        config = self.make_app({
            "event_listeners": "demo",
            "event_listeners.demo.use": "tests.core.listeners",
            "event_listeners.demo.actions": "read",
        })
        event = ResourceRead({"action": ACTIONS.READ.value}, [], Request())
        config.registry.notify(event)

        self.assertTrue(self.demo_mocked.return_value.called)
コード例 #4
0
    def test_same_callback_is_called_for_read_and_write_specified(self):
        config = self.make_app({
            'event_listeners.redis.actions':
            'read create delete',
        })
        event = ResourceRead(ACTIONS.READ, 123456, [], Request())
        config.registry.notify(event)
        event = ResourceChanged(ACTIONS.CREATE, 123456, [], Request())
        config.registry.notify(event)

        self.assertEqual(self.redis_mocked.return_value.call_count, 2)
コード例 #5
0
    def test_same_callback_is_called_for_read_and_write_specified(self):
        config = self.make_app({
            'event_listeners': 'demo',
            'event_listeners.demo.use': 'tests.core.listeners',
            'event_listeners.demo.actions': 'read create delete',
        })
        ev = ResourceRead({'action': ACTIONS.READ.value}, [], Request())
        config.registry.notify(ev)
        ev = ResourceChanged({'action': ACTIONS.CREATE.value}, [], Request())
        config.registry.notify(ev)

        self.assertEqual(self.demo_mocked.return_value.call_count, 2)
コード例 #6
0
    def test_read_records_is_deprecated(self):
        event = ResourceRead(None, [], None)
        event.read_records

        message = "`read_records` is deprecated, use `read_objects` instead."
        self.mocked_warnings.assert_called_with(message, DeprecationWarning)
コード例 #7
0
    def test_callback_is_not_called_on_read_by_default(self):
        config = self.make_app()
        event = ResourceRead(ACTIONS.READ, 123456, [], Request())
        config.registry.notify(event)

        self.assertFalse(self.redis_mocked.return_value.called)