Exemple #1
0
 def mark_as_created(self):
     from rest_hooks.signals import hook_event
     hook_event.send(
         sender=self.__class__,
         action='created',
         instance=self # the Book object
     )
Exemple #2
0
    def test_custom_instance_hook(self, method_mock):
        from rest_hooks.signals import hook_event

        method_mock.return_value = None
        target = 'http://example.com/test_custom_instance_hook'

        hook = self.make_hook('comment.moderated', target)

        comment = Comment.objects.create(
            site=self.site,
            content_object=self.user,
            user=self.user,
            comment='Hello world!'
        )

        hook_event.send(
            sender=comment.__class__,
            action='moderated',
            instance=comment
        )
        # time.sleep(1) # should change a setting to turn off async

        payloads = [json.loads(call[2]['data']) for call in method_mock.mock_calls]

        self.assertEquals('comment.moderated', payloads[0]['hook']['event'])
        self.assertEquals('Hello world!', payloads[0]['data']['fields']['comment'])
Exemple #3
0
    def test_custom_instance_hook(self, method_mock):
        from rest_hooks.signals import hook_event

        method_mock.return_value = None
        target = 'http://example.com/test_custom_instance_hook'

        hook = self.make_hook('comment.moderated', target)

        comment = Comment.objects.create(site=self.site,
                                         content_object=self.user,
                                         user=self.user,
                                         comment='Hello world!')

        hook_event.send(sender=comment.__class__,
                        action='moderated',
                        instance=comment)
        # time.sleep(1) # should change a setting to turn off async

        payloads = [
            json.loads(call[2]['data']) for call in method_mock.mock_calls
        ]

        self.assertEquals('comment.moderated', payloads[0]['hook']['event'])
        self.assertEquals('Hello world!',
                          payloads[0]['data']['fields']['comment'])
Exemple #4
0
 def mark_as_read(self):
     # models can also have custom defined events
     from rest_hooks.signals import hook_event
     hook_event.send(
         sender=self.__class__,
         action='read',
         instance=self  # the Book object
     )
Exemple #5
0
 def serialize_employee(self):
     from rest_hooks.signals import hook_event
     hook_event.send(
         sender=self.__class__,
         action='create',
         instance=self,
     )
     return {
         'hook': hook.dict(),
         'data': {
             'id': self.id,
             'name': self.name,
             'hometown': self.hometown,
         }
     }