def test_08_publish_error(self, mock_sn):
        sn = SocialNetworks()
        sn_mock = sn._social_networks[0]

        event = BoEvent.objects.get(id=1)
        # XXX don't save the obj we don't want to test the post_save trigger
        event.msg = 'not empyt event'
        sn.publish(event)
        self.assertEqual(len(self.log._info), 0)
        self.assertEqual(len(self.log._error), 1)
        msg = "Can't publish msg: %s, event_id: %d for sn: %s (%s)" % (
            event.msg, event.id, sn_mock.name, 'not connected')
        self.assertEqual(self.log._error[0], msg)
        self.assertEqual(len(sn_mock._msg), 0)

        eventlog = BoEventLog.objects.get(id=1)
        # XXX don't save the obj we don't want to test the post_save trigger
        eventlog.msg = 'not empyt eventlog'
        sn.publish(eventlog)
        self.assertEqual(len(self.log._info), 0)
        self.assertEqual(len(self.log._error), 2)
        msg = "Can't publish msg: %s, event_id: %d for sn: %s (%s)" % (
            eventlog.msg, eventlog.event.id, sn_mock.name, 'not connected')
        self.assertEqual(self.log._error[1], msg)
        self.assertEqual(len(sn_mock._msg), 0)
    def test_08_publish_error(self, mock_sn):
        sn = SocialNetworks()
        sn_mock = sn._social_networks[0]

        event = BoEvent.objects.get(id=1)
        # XXX don't save the obj we don't want to test the post_save trigger
        event.msg = 'not empyt event'
        sn.publish(event)
        self.assertEqual(len(self.log._info), 0)
        self.assertEqual(len(self.log._error), 1)
        msg = "Can't publish msg: %s, event_id: %d for sn: %s (%s)" % (
            event.msg, event.id, sn_mock.name, 'not connected')
        self.assertEqual(self.log._error[0], msg)
        self.assertEqual(len(sn_mock._msg), 0)

        eventlog = BoEventLog.objects.get(id=1)
        # XXX don't save the obj we don't want to test the post_save trigger
        eventlog.msg = 'not empyt eventlog'
        sn.publish(eventlog)
        self.assertEqual(len(self.log._info), 0)
        self.assertEqual(len(self.log._error), 2)
        msg = "Can't publish msg: %s, event_id: %d for sn: %s (%s)" % (
            eventlog.msg, eventlog.event.id, sn_mock.name, 'not connected')
        self.assertEqual(self.log._error[1], msg)
        self.assertEqual(len(sn_mock._msg), 0)
Exemple #3
0
def cron_social_network():
    now = datetime.now(pytz.timezone('UTC'))
    sn = SocialNetworks()

    filters = Q(date_start__lte=now) & (Q(date_end__gte=now)
                                        | Q(date_end__isnull=True))
    for event in Event.objects.filter(filters):
        sn.publish(event)

    deltat = now - timedelta(minutes=5)
    filters = Q(date__lte=now) & (Q(event__date_end__gte=deltat)
                                  | Q(event__date_end__isnull=True))
    for eventlog in EventLog.objects.filter(filters):
        sn.publish(eventlog)
Exemple #4
0
def cron_social_network():
    now = datetime.now(pytz.timezone('UTC'))
    sn = SocialNetworks()

    filters = Q(date_start__lte=now) & (
        Q(date_end__gte=now) | Q(date_end__isnull=True)
    )
    for event in Event.objects.filter(filters):
        sn.publish(event)

    deltat = now - timedelta(minutes=5)
    filters = Q(date__lte=now) & (
        Q(event__date_end__gte=deltat) | Q(event__date_end__isnull=True)
    )
    for eventlog in EventLog.objects.filter(filters):
        sn.publish(eventlog)
    def test_06_empty_msg(self):
        sn = SocialNetworks()
        sn_mock = sn._social_networks[0]

        event = BoEvent.objects.get(id=1)
        self.assertEqual(event.msg, None)
        sn.publish(event)
        self.assertEqual(len(self.log._info), 0)
        self.assertEqual(len(self.log._error), 0)
        self.assertEqual(len(sn_mock._msg), 0)

        eventlog = BoEventLog.objects.get(id=1)
        self.assertEqual(eventlog.msg, None)
        sn.publish(eventlog)
        self.assertEqual(len(self.log._info), 0)
        self.assertEqual(len(self.log._error), 0)
        self.assertEqual(len(sn_mock._msg), 0)
def on_eventlog(instance, raw, **kwargs):
    """
    Send a Tweet on Tweeter
    """

    # no trigger when loading fixture
    if raw:
        return

    if instance.event.category == Event.MAINTENANCE and \
            instance.event.date_start > datetime.now(pytz.timezone('UTC')):
        return

    from baobab.socialnetwork import SocialNetworks

    sn = SocialNetworks()
    sn.publish(instance)
    def test_06_empty_msg(self):
        sn = SocialNetworks()
        sn_mock = sn._social_networks[0]

        event = BoEvent.objects.get(id=1)
        self.assertEqual(event.msg, None)
        sn.publish(event)
        self.assertEqual(len(self.log._info), 0)
        self.assertEqual(len(self.log._error), 0)
        self.assertEqual(len(sn_mock._msg), 0)

        eventlog = BoEventLog.objects.get(id=1)
        self.assertEqual(eventlog.msg, None)
        sn.publish(eventlog)
        self.assertEqual(len(self.log._info), 0)
        self.assertEqual(len(self.log._error), 0)
        self.assertEqual(len(sn_mock._msg), 0)
Exemple #8
0
def on_eventlog(instance, raw, **kwargs):
    """
    Send a Tweet on Tweeter
    """

    # no trigger when loading fixture
    if raw:
        return

    if instance.event.category == Event.MAINTENANCE and \
            instance.event.date_start > datetime.now(pytz.timezone('UTC')):
        return

    from baobab.socialnetwork import SocialNetworks

    sn = SocialNetworks()
    sn.publish(instance)
    def test_09_publish(self):
        sn = SocialNetworks()
        sn_mock = sn._social_networks[0]

        event = BoEvent.objects.get(id=1)
        # XXX don't save the obj we don't want to test the post_save trigger
        event.msg = 'not empyt event'
        filters = {
            'event': event,
            'name': 'MockSN',
        }
        self.assertFalse(SnEvent.objects.filter(**filters).exists())
        sn.publish(event)
        self.assertTrue(SnEvent.objects.filter(**filters).exists())
        self.assertEqual(len(self.log._info), 1)
        url = '%s%d' % (settings.URL_EVENT, event.id)
        msg = 'publish sn: %s msg: %s, url: %s' % (sn_mock.name, event.msg,
                                                   url)
        self.assertEqual(self.log._info[0], msg)
        self.assertEqual(len(self.log._error), 0)
        self.assertEqual(len(sn_mock._msg), 1)
        self.assertEqual(sn_mock._msg[0], (event.msg, url))

        eventlog = BoEventLog.objects.get(id=1)
        # XXX don't save the obj we don't want to test the post_save trigger
        eventlog.msg = 'not empyt eventlog'
        filters = {
            'eventlog': eventlog,
            'name': 'MockSN',
        }
        self.assertFalse(SnEventLog.objects.filter(**filters).exists())
        sn.publish(eventlog)
        self.assertTrue(SnEventLog.objects.filter(**filters).exists())
        self.assertEqual(len(self.log._info), 2)
        url = '%s%d' % (settings.URL_EVENT, eventlog.event.id)
        msg = 'publish sn: %s msg: %s, url: %s' % (sn_mock.name, eventlog.msg,
                                                   url)
        self.assertEqual(self.log._info[1], msg)
        self.assertEqual(len(self.log._error), 0)
        self.assertEqual(len(sn_mock._msg), 2)
        self.assertEqual(sn_mock._msg[1], (eventlog.msg, url))
    def test_09_publish(self):
        sn = SocialNetworks()
        sn_mock = sn._social_networks[0]

        event = BoEvent.objects.get(id=1)
        # XXX don't save the obj we don't want to test the post_save trigger
        event.msg = 'not empyt event'
        filters = {
            'event': event,
            'name': 'MockSN',
        }
        self.assertFalse(SnEvent.objects.filter(**filters).exists())
        sn.publish(event)
        self.assertTrue(SnEvent.objects.filter(**filters).exists())
        self.assertEqual(len(self.log._info), 1)
        url = '%s%d' % (settings.URL_EVENT, event.id)
        msg = 'publish sn: %s msg: %s, url: %s' % (sn_mock.name, event.msg,
                                                   url)
        self.assertEqual(self.log._info[0], msg)
        self.assertEqual(len(self.log._error), 0)
        self.assertEqual(len(sn_mock._msg), 1)
        self.assertEqual(sn_mock._msg[0], (event.msg, url))

        eventlog = BoEventLog.objects.get(id=1)
        # XXX don't save the obj we don't want to test the post_save trigger
        eventlog.msg = 'not empyt eventlog'
        filters = {
            'eventlog': eventlog,
            'name': 'MockSN',
        }
        self.assertFalse(SnEventLog.objects.filter(**filters).exists())
        sn.publish(eventlog)
        self.assertTrue(SnEventLog.objects.filter(**filters).exists())
        self.assertEqual(len(self.log._info), 2)
        url = '%s%d' % (settings.URL_EVENT, eventlog.event.id)
        msg = 'publish sn: %s msg: %s, url: %s' % (sn_mock.name, eventlog.msg,
                                                   url)
        self.assertEqual(self.log._info[1], msg)
        self.assertEqual(len(self.log._error), 0)
        self.assertEqual(len(sn_mock._msg), 2)
        self.assertEqual(sn_mock._msg[1], (eventlog.msg, url))
    def test_07_published_msg(self):
        sn = SocialNetworks()
        sn_mock = sn._social_networks[0]

        event = BoEvent.objects.get(id=1)
        # XXX don't save the obj we don't want to test the post_save trigger
        event.msg = 'not empyt event'
        SnEvent.objects.create(event=event, name=sn_mock.name, sn_id=42)
        sn.publish(event)
        self.assertEqual(len(self.log._info), 0)
        self.assertEqual(len(self.log._error), 0)
        self.assertEqual(len(sn_mock._msg), 0)

        eventlog = BoEventLog.objects.get(id=1)
        # XXX don't save the obj we don't want to test the post_save trigger
        eventlog.msg = 'not empyt eventlog'
        SnEventLog.objects.create(
            eventlog=eventlog, name=sn_mock.name, sn_id=42)
        sn.publish(eventlog)
        self.assertEqual(len(self.log._info), 0)
        self.assertEqual(len(self.log._error), 0)
        self.assertEqual(len(sn_mock._msg), 0)
    def test_07_published_msg(self):
        sn = SocialNetworks()
        sn_mock = sn._social_networks[0]

        event = BoEvent.objects.get(id=1)
        # XXX don't save the obj we don't want to test the post_save trigger
        event.msg = 'not empyt event'
        SnEvent.objects.create(event=event, name=sn_mock.name, sn_id=42)
        sn.publish(event)
        self.assertEqual(len(self.log._info), 0)
        self.assertEqual(len(self.log._error), 0)
        self.assertEqual(len(sn_mock._msg), 0)

        eventlog = BoEventLog.objects.get(id=1)
        # XXX don't save the obj we don't want to test the post_save trigger
        eventlog.msg = 'not empyt eventlog'
        SnEventLog.objects.create(eventlog=eventlog,
                                  name=sn_mock.name,
                                  sn_id=42)
        sn.publish(eventlog)
        self.assertEqual(len(self.log._info), 0)
        self.assertEqual(len(self.log._error), 0)
        self.assertEqual(len(sn_mock._msg), 0)