def test_webhook_send_signal(self):
        self.signal_received_count = 0
        test_event = {"event": "send", "msg": {}}

        def my_callback(sender, event_type, data, **kwargs):
            self.signal_received_count += 1
            self.assertEqual(event_type, 'send')
            self.assertEqual(data, test_event)

        try:
            webhook_event.connect(my_callback, weak=False)  # local callback func, so don't use weak ref
            response = self.client.post('/webhook/?secret=abc123', {
                'mandrill_events': json.dumps([test_event])
            })
        finally:
            webhook_event.disconnect(my_callback)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(self.signal_received_count, 1)
    def test_webhook_send_signal(self):
        self.signal_received_count = 0
        test_event = {"event": "send", "msg": {}}

        def my_callback(sender, event_type, data, **kwargs):
            self.signal_received_count += 1
            self.assertEqual(event_type, 'send')
            self.assertEqual(data, test_event)

        try:
            webhook_event.connect(
                my_callback,
                weak=False)  # local callback func, so don't use weak ref
            response = self.client.post(
                '/webhook/?secret=abc123',
                {'mandrill_events': json.dumps([test_event])})
        finally:
            webhook_event.disconnect(my_callback)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(self.signal_received_count, 1)
    def test_webhook_sync_event(self):
        # Mandrill sync events use a different format from other events
        # https://mandrill.zendesk.com/hc/en-us/articles/205583297-Sync-Event-Webhook-format
        self.signal_received_count = 0
        test_event = {"type": "whitelist", "action": "add"}

        def my_callback(sender, event_type, data, **kwargs):
            self.signal_received_count += 1
            self.assertEqual(event_type, 'whitelist_add')  # synthesized event_type
            self.assertEqual(data, test_event)

        try:
            webhook_event.connect(my_callback, weak=False)  # local callback func, so don't use weak ref
            response = self.client.post('/webhook/?secret=abc123', {
                'mandrill_events': json.dumps([test_event])
            })
        finally:
            webhook_event.disconnect(my_callback)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(self.signal_received_count, 1)
    def test_webhook_sync_event(self):
        # Mandrill sync events use a different format from other events
        # https://mandrill.zendesk.com/hc/en-us/articles/205583297-Sync-Event-Webhook-format
        self.signal_received_count = 0
        test_event = {"type": "whitelist", "action": "add"}

        def my_callback(sender, event_type, data, **kwargs):
            self.signal_received_count += 1
            self.assertEqual(event_type,
                             'whitelist_add')  # synthesized event_type
            self.assertEqual(data, test_event)

        try:
            webhook_event.connect(
                my_callback,
                weak=False)  # local callback func, so don't use weak ref
            response = self.client.post(
                '/webhook/?secret=abc123',
                {'mandrill_events': json.dumps([test_event])})
        finally:
            webhook_event.disconnect(my_callback)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(self.signal_received_count, 1)
Beispiel #5
0
    """

    lead = models.ForeignKey(Lead, related_name='notes')
    user = models.ForeignKey(settings.AUTH_USER_MODEL)
    content = models.TextField(blank=True)
    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)

    objects = AgencyIsolatedManager()

    def save(self, **kwargs):
        from fetchmyguest.utils.notifications import notify

        if not self.agency:
            self.agency = get_agency()
        obj = super(Note, self).save(**kwargs)
        #from fetchmyguest.utils.notifications import notify
        notify(self.lead, 'Note for lead: {0}'.format(self.lead.customer), alert=True)
        return obj

    def __unicode__(self):
        return self.content[:50]
Message.add_to_class('lead', models.ForeignKey(Lead, related_name='messages', null=True, blank=True))
Message.add_to_class('is_lead_source', models.NullBooleanField())
Message.add_to_class('events', DictionaryField(verbose_name="Events log", default={"": ""}))
Message.add_to_class('prepare_reply', prepare_reply)
Message.add_to_class('get_text_body', get_text_body)
# Message.objects = HStoreManager()
message_received.connect(check_email_for_lead)
webhook_event.connect(handle_mandrill)