Пример #1
0
    def test_callback_called_when_resource_is_not_filtered(self):
        config = self.make_app()
        event = ResourceChanged('create', Resource(), [], Request())
        event.payload['resource_name'] = 'mushroom'
        config.registry.notify(event)

        self.assertTrue(self.redis_mocked.return_value.called)
Пример #2
0
    def test_callback_is_not_called_when_resource_is_filtered(self):
        config = self.make_app({"event_listeners.redis.resources": "toad"})
        event = ResourceChanged(ACTIONS.CREATE, 123456, [], Request())
        event.payload["resource_name"] = "mushroom"
        config.registry.notify(event)

        self.assertFalse(self.redis_mocked.return_value.called)
Пример #3
0
    def test_callback_called_when_resource_is_not_filtered(self):
        config = self.make_app()
        event = ResourceChanged(ACTIONS.CREATE, 123456, [], Request())
        event.payload['resource_name'] = 'mushroom'
        config.registry.notify(event)

        self.assertTrue(self.redis_mocked.return_value.called)
Пример #4
0
    def test_callback_is_not_called_when_action_is_filtered(self):
        config = self.make_app({
            'event_listeners.redis.actions': 'delete',
        })
        event = ResourceChanged(ACTIONS.CREATE, 123456, [], Request())
        config.registry.notify(event)

        self.assertFalse(self.redis_mocked.return_value.called)
Пример #5
0
 def test_notification_is_broken(self):
     with self.redis_listening():
         # an event with a bad JSON should silently break and send nothing
         # date time objects cannot be dumped
         event2 = ResourceChanged(ACTIONS.CREATE, datetime.now(), [],
                                  Request())
         self.notify(event2)
         self.assertFalse(self.has_redis_changed())
Пример #6
0
    def test_redis_is_broken(self):
        with self.redis_listening():
            # if the redis call fails, same deal: we should ignore it
            self._save_redis()

            with broken_redis():
                event = ResourceChanged(ACTIONS.CREATE, 123456, [], Request())
                self.config.registry.notify(event)

            self.assertFalse(self.has_redis_changed())
Пример #7
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)
Пример #8
0
    def test_redis_is_notified(self):
        with self.redis_listening():
            # let's trigger an event
            event = ResourceChanged(ACTIONS.CREATE, 123456, [], Request())
            self.notify(event)
            self.assertTrue(self.has_redis_changed())

        # okay, we should have the first event in Redis
        last = self._redis.lpop('cliquet.events')
        last = json.loads(last.decode('utf8'))
        self.assertEqual(last['action'], ACTIONS.CREATE.value)
Пример #9
0
    def test_callback_called_when_action_is_not_filtered(self):
        config = self.make_app()
        event = ResourceChanged(ACTIONS.CREATE, 123456, [], Request())
        config.registry.notify(event)

        self.assertTrue(self.redis_mocked.return_value.called)