Exemplo n.º 1
0
 def test_on_listen_calls_listen_for_create(self):
     user = factory.make_User()
     handler = EventHandler(user, {})
     mock_listen = self.patch(handler, "listen")
     mock_listen.return_value = None
     pk = random.randint(1, 1000)
     handler.on_listen(sentinel.channel, "create", pk)
     self.assertThat(mock_listen,
                     MockCalledOnceWith(sentinel.channel, "create", pk))
Exemplo n.º 2
0
 def test_on_listen_doesnt_call_listen_for_non_create(self):
     user = factory.make_User()
     handler = EventHandler(user, {})
     mock_listen = self.patch(handler, "listen")
     mock_listen.return_value = None
     pk = random.randint(1, 1000)
     action = factory.make_string()
     if action != "create":
         handler.on_listen(sentinel.channel, action, pk)
         self.assertThat(mock_listen, MockNotCalled())
Exemplo n.º 3
0
 def test_on_listen_returns_None_if_event_node_id_not_in_cache(self):
     user = factory.make_User()
     handler = EventHandler(user, {})
     node = factory.make_Node()
     event = factory.make_Event(node=node)
     self.assertIsNone(
         handler.on_listen(sentinel.channel, "create", event.id))
Exemplo n.º 4
0
 def test_on_listen_returns_None_if_listen_returns_None(self):
     user = factory.make_User()
     handler = EventHandler(user, {})
     mock_listen = self.patch(handler, "listen")
     mock_listen.return_value = None
     self.assertIsNone(
         handler.on_listen(sentinel.channel, sentinel.action,
                           random.randint(1, 1000)))
Exemplo n.º 5
0
 def test_on_listen_returns_None_if_obj_no_longer_exists(self):
     user = factory.make_User()
     handler = EventHandler(user, {})
     mock_listen = self.patch(handler, "listen")
     mock_listen.return_value = HandlerDoesNotExistError()
     self.assertIsNone(
         handler.on_listen(sentinel.channel, sentinel.action,
                           random.randint(1, 1000)))
Exemplo n.º 6
0
 def test_on_listen_returns_handler_name_action_and_event(self):
     user = factory.make_User()
     handler = EventHandler(user, {})
     node = factory.make_Node()
     event = factory.make_Event(node=node)
     handler.cache["node_ids"].append(node.id)
     self.assertEqual((handler._meta.handler_name, "create",
                       self.dehydrate_event(event)),
                      handler.on_listen(sentinel.channel, "create",
                                        event.id))