Ejemplo n.º 1
0
    def test_weekly_frequency_subscriptions_are_not_included(self):
        dataset = factories.DatasetActivity()
        factories.Subscription(dataset_id=dataset['id'], frequency='weekly')

        notifies = get_immediate_notifications()

        eq(_get_activities(notifies), [])
Ejemplo n.º 2
0
    def test_lots_of_users_and_datasets(self):
        datasetx = _create_dataset_and_activity([70, 50, 10])
        datasety = _create_dataset_and_activity([40, 20])
        _ = factories.DatasetActivity()  # decoy
        factories.Subscription(email='*****@*****.**',
                               dataset_id=datasetx['id'],
                               created=datetime.datetime.now() -
                               datetime.timedelta(hours=2))
        factories.Subscription(email='*****@*****.**',
                               dataset_id=datasetx['id'],
                               created=datetime.datetime.now() -
                               datetime.timedelta(hours=2))
        factories.Subscription(email='*****@*****.**',
                               dataset_id=datasety['id'],
                               created=datetime.datetime.now() -
                               datetime.timedelta(hours=2))

        notifies = get_immediate_notifications()

        eq(set(notifies.keys()), set(
            ('*****@*****.**', '*****@*****.**', '*****@*****.**')))
        from pprint import pprint
        pprint(_get_activities(notifies))
        eq(
            set(_get_activities(notifies)),
            set((
                (u'*****@*****.**', u'new package', datasetx['id']),
                (u'*****@*****.**', u'changed package', datasetx['id']),
                (u'*****@*****.**', u'changed package', datasetx['id']),
                (u'*****@*****.**', u'new package', datasetx['id']),
                (u'*****@*****.**', u'changed package', datasetx['id']),
                (u'*****@*****.**', u'changed package', datasetx['id']),
                (u'*****@*****.**', u'new package', datasety['id']),
                (u'*****@*****.**', u'changed package', datasety['id']),
            )))
Ejemplo n.º 3
0
    def test_old_activity_not_notified(self):
        dataset = factories.DatasetActivity(timestamp=datetime.datetime.now() -
                                            datetime.timedelta(hours=49))
        factories.Subscription(dataset_id=dataset['id'])

        notifies = get_immediate_notifications()

        eq(_get_activities(notifies), [])
Ejemplo n.º 4
0
    def test_basic(self):
        dataset = factories.DatasetActivity()
        _ = factories.DatasetActivity()  # decoy
        subscription = factories.Subscription(dataset_id=dataset['id'])

        notifies = get_immediate_notifications()

        eq(notifies.keys(), [subscription['email']])
        eq(_get_activities(notifies),
           [(u'*****@*****.**', u'new package', dataset['id'])])
Ejemplo n.º 5
0
    def test_subscribe_to_an_group_and_its_dataset_has_activity(self):
        group = Group()
        subscription = factories.Subscription(group_id=group['id'])
        subscribe_model.Subscribe.set_emails_last_sent(
            Frequency.IMMEDIATE.value, datetime.datetime.now())
        dataset = Dataset(groups=[{'id': group['id']}])

        notifies = get_immediate_notifications()

        eq(notifies.keys(), [subscription['email']])
        eq(_get_activities(notifies),
           [(u'*****@*****.**', u'new package', dataset['id'])])
Ejemplo n.º 6
0
    def test_subscribe_to_an_org_and_its_dataset_has_activity(self):
        org = Organization()
        subscription = factories.Subscription(organization_id=org['id'])
        subscribe_model.Subscribe.set_emails_last_sent(
            Frequency.IMMEDIATE.value, datetime.datetime.now())
        dataset = Dataset(owner_org=org['id'])

        notifies = get_immediate_notifications()

        eq(notifies.keys(), [subscription['email']])
        eq(_get_activities(notifies),
           [(u'*****@*****.**', u'new package', dataset['id'])])
Ejemplo n.º 7
0
    def test_activity_already_notified_not_notified_again(self):
        dataset = factories.DatasetActivity(timestamp=datetime.datetime.now() -
                                            datetime.timedelta(minutes=10))
        subscribe_model.Subscribe.set_emails_last_sent(
            Frequency.IMMEDIATE.value,
            datetime.datetime.now() - datetime.timedelta(minutes=5))
        model.Session.commit()
        factories.Subscription(dataset_id=dataset['id'])

        notifies = get_immediate_notifications()

        eq(_get_activities(notifies), [])
Ejemplo n.º 8
0
    def test_activity_before_the_subscription_is_not_notified(self):
        dataset = Dataset()
        factories.Activity(object_id=dataset['id'],
                           activity_type='changed package')
        factories.Subscription(dataset_id=dataset['id'],
                               created=datetime.datetime.now())
        factories.Activity(object_id=dataset['id'],
                           activity_type='changed package')

        notifies = get_immediate_notifications()

        eq(_get_activities(notifies),
           [(u'*****@*****.**', u'changed package', dataset['id'])])