def test_immediate_frequency_subscriptions_are_not_included(self):
        dataset = factories.DatasetActivity()
        factories.Subscription(dataset_id=dataset['id'], frequency='immediate')

        notifies = get_daily_notifications()

        eq(_get_activities(notifies), [])
    def test_activities_older_than_a_day_are_not_notified(self):
        dataset = factories.DatasetActivity(timestamp=datetime.datetime.now() -
                                            datetime.timedelta(hours=25))
        factories.Subscription(dataset_id=dataset['id'], frequency='daily')

        notifies = get_daily_notifications()

        eq(_get_activities(notifies), [])
    def test_basic(self):
        dataset = factories.DatasetActivity()
        _ = factories.DatasetActivity()  # decoy
        subscription = factories.Subscription(dataset_id=dataset['id'],
                                              frequency='daily')

        notifies = get_daily_notifications()

        eq(notifies.keys(), [subscription['email']])
        eq(_get_activities(notifies),
           [(u'*****@*****.**', u'new package', dataset['id'])])
    def test_activities_already_notified_are_not_notified_again(self):
        dataset = factories.DatasetActivity(timestamp=datetime.datetime.now() -
                                            datetime.timedelta(hours=1))
        factories.Subscription(dataset_id=dataset['id'], frequency='daily')
        subscribe_model.Subscribe.set_emails_last_sent(
            frequency=Frequency.DAILY.value,
            emails_last_sent=datetime.datetime.now())
        model.Session.commit()

        notifies = get_daily_notifications()

        eq(_get_activities(notifies), [])