コード例 #1
0
    def test_filtered(self):
        """Make sure watches cull properly by additional filters."""
        # A watch with just the filter we're searching for:
        registered_user = user(email='*****@*****.**', save=True)
        exact_watch = watch(event_type=TYPE, user=registered_user, save=True)
        watch_filter(watch=exact_watch, name='color', value=1).save()

        # A watch with extra filters:
        extra_watch = watch(event_type=TYPE, email='*****@*****.**', save=True)
        watch_filter(watch=extra_watch, name='color', value=1).save()
        watch_filter(watch=extra_watch, name='flavor', value=2).save()

        # A watch with no row for the filter we're searching on:
        watch(event_type=TYPE, email='*****@*****.**').save()

        # A watch with a mismatching filter--shouldn't be found
        mismatch_watch = watch(event_type=TYPE,
                               email='*****@*****.**',
                               save=True)
        watch_filter(watch=mismatch_watch, name='color', value=3).save()

        self._emails_eq(['*****@*****.**', '*****@*****.**', '*****@*****.**'],
                        FilteredEvent(),
                        color=1)

        # Search on multiple filters to test joining the filters table twice.
        # We provide values that match for both filters, as [email protected]
        # suffices to test exclusion.
        self._emails_eq(['*****@*****.**', '*****@*****.**', '*****@*****.**'],
                        FilteredEvent(),
                        color=1,
                        flavor=2)
コード例 #2
0
ファイル: test_events.py プロジェクト: AprilMorone/kuma
    def test_filtered(self):
        """Make sure watches cull properly by additional filters."""
        # A watch with just the filter we're searching for:
        registered_user = user(email='*****@*****.**', save=True)
        exact_watch = watch(event_type=TYPE, user=registered_user, save=True)
        watch_filter(watch=exact_watch, name='color', value=1).save()

        # A watch with extra filters:
        extra_watch = watch(event_type=TYPE, email='*****@*****.**', save=True)
        watch_filter(watch=extra_watch, name='color', value=1).save()
        watch_filter(watch=extra_watch, name='flavor', value=2).save()

        # A watch with no row for the filter we're searching on:
        watch(event_type=TYPE, email='*****@*****.**').save()

        # A watch with a mismatching filter--shouldn't be found
        mismatch_watch = watch(event_type=TYPE, email='*****@*****.**',
                               save=True)
        watch_filter(watch=mismatch_watch, name='color', value=3).save()

        self._emails_eq(['*****@*****.**', '*****@*****.**', '*****@*****.**'],
                        FilteredEvent(), color=1)

        # Search on multiple filters to test joining the filters table twice.
        # We provide values that match for both filters, as [email protected]
        # suffices to test exclusion.
        self._emails_eq(['*****@*****.**', '*****@*****.**', '*****@*****.**'],
                        FilteredEvent(), color=1, flavor=2)
コード例 #3
0
    def test_duplicate_tolerance(self):
        """Assure notify() returns an existing watch if there is a matching
        one.

        Also make sure it returns only 1 watch even if there are duplicate
        matches.

        """
        w1 = watch(event_type=TYPE, email='*****@*****.**', save=True)
        w2 = watch(event_type=TYPE, email='*****@*****.**', save=True)
        assert SimpleEvent.notify('*****@*****.**').pk in [w1.pk, w2.pk]
コード例 #4
0
ファイル: test_events.py プロジェクト: AprilMorone/kuma
    def test_duplicate_tolerance(self):
        """Assure notify() returns an existing watch if there is a matching
        one.

        Also make sure it returns only 1 watch even if there are duplicate
        matches.

        """
        w1 = watch(event_type=TYPE, email='*****@*****.**', save=True)
        w2 = watch(event_type=TYPE, email='*****@*****.**', save=True)
        assert SimpleEvent.notify('*****@*****.**').pk in [w1.pk, w2.pk]
コード例 #5
0
ファイル: test_events.py プロジェクト: AprilMorone/kuma
    def test_mock_model(self):
        """Deleting an instance of MockModel should delete watches.

        Create instance of MockModel from notifications.tests.models, then
        delete it and watch the cascade go.

        """
        mock_m = MockModel.objects.create()
        watch(event_type=TYPE, email='*****@*****.**', content_object=mock_m,
              save=True)
        MockModel.objects.all().delete()
        assert not Watch.objects.count(), 'Cascade delete failed.'
コード例 #6
0
    def test_new_user_claim_watches(self, get_current):
        """Claim user watches upon activation."""
        watch(email='*****@*****.**', save=True)

        get_current.return_value.domain = 'su.mo.com'
        user = RegistrationProfile.objects.create_inactive_user(
            'sumouser1234', 'testpass', '*****@*****.**')
        key = RegistrationProfile.objects.all()[0].activation_key
        self.client.get(reverse('users.activate', args=[key]), follow=True)

        # Watches are claimed.
        assert user.watch_set.exists()
コード例 #7
0
ファイル: test_views.py プロジェクト: fwenzel/kitsune
    def test_new_user_claim_watches(self, get_current):
        """Claim user watches upon activation."""
        watch(email='*****@*****.**', save=True)

        get_current.return_value.domain = 'su.mo.com'
        user = RegistrationProfile.objects.create_inactive_user(
            'sumouser1234', 'testpass', '*****@*****.**')
        key = RegistrationProfile.objects.all()[0].activation_key
        self.client.get(reverse('users.activate', args=[key]), follow=True)

        # Watches are claimed.
        assert user.watch_set.exists()
コード例 #8
0
    def test_mock_model(self):
        """Deleting an instance of MockModel should delete watches.

        Create instance of MockModel from notifications.tests.models, then
        delete it and watch the cascade go.

        """
        mock_m = MockModel.objects.create()
        watch(event_type=TYPE,
              email='*****@*****.**',
              content_object=mock_m,
              save=True)
        MockModel.objects.all().delete()
        assert not Watch.objects.count(), 'Cascade delete failed.'
コード例 #9
0
ファイル: test_views.py プロジェクト: HarshaJagadish/kuma
    def test_new_user_claim_watches(self, get_current):
        """Claim user watches upon activation."""
        old, settings.CELERY_ALWAYS_EAGER = settings.CELERY_ALWAYS_EAGER, True

        get_current.return_value.domain = 'su.mo.com'

        watch(email='*****@*****.**', save=True)

        now = time()
        username = '******' % now
        user = RegistrationProfile.objects.create_inactive_user(
            username, 'testpass', '*****@*****.**')
        key = RegistrationProfile.objects.all()[0].activation_key
        self.client.get(reverse('users.activate', args=[key]), follow=True)

        # Watches are claimed.
        assert user.watch_set.exists()

        settings.CELERY_ALWAYS_EAGER = old
コード例 #10
0
ファイル: test_views.py プロジェクト: swznd/kuma
    def test_new_user_claim_watches(self, get_current):
        """Claim user watches upon activation."""
        old, settings.CELERY_ALWAYS_EAGER = settings.CELERY_ALWAYS_EAGER, True

        get_current.return_value.domain = 'su.mo.com'

        watch(email='*****@*****.**', save=True)

        now = time()
        username = '******' % now
        user = RegistrationProfile.objects.create_inactive_user(
            username, 'testpass', '*****@*****.**')
        key = RegistrationProfile.objects.all()[0].activation_key
        self.client.get(reverse('users.activate', args=[key]), follow=True)

        # Watches are claimed.
        assert user.watch_set.exists()

        settings.CELERY_ALWAYS_EAGER = old
コード例 #11
0
ファイル: test_events.py プロジェクト: AprilMorone/kuma
 def test_simple(self):
     """Test whether a watch scoped only by event type fires for both
     anonymous and registered users."""
     registered_user = user(email='*****@*****.**', save=True)
     watch(event_type=TYPE, user=registered_user).save()
     watch(event_type=TYPE, email='*****@*****.**').save()
     watch(event_type='something else', email='*****@*****.**').save()
     self._emails_eq(['*****@*****.**', '*****@*****.**'], SimpleEvent())
コード例 #12
0
 def test_simple(self):
     """Test whether a watch scoped only by event type fires for both
     anonymous and registered users."""
     registered_user = user(email='*****@*****.**', save=True)
     watch(event_type=TYPE, user=registered_user).save()
     watch(event_type=TYPE, email='*****@*****.**').save()
     watch(event_type='something else', email='*****@*****.**').save()
     self._emails_eq(['*****@*****.**', '*****@*****.**'], SimpleEvent())
コード例 #13
0
ファイル: test_events.py プロジェクト: AprilMorone/kuma
    def test_duplicates(self):
        """Don't return duplicate email addresses."""
        watch(event_type=TYPE, user=user(email='*****@*****.**', save=True),
              save=True)
        watch(event_type=TYPE, email='*****@*****.**').save()
        watch(event_type=TYPE, email='*****@*****.**').save()
        eq_(3, Watch.objects.all().count())  # We created what we meant to.

        self._emails_eq(['*****@*****.**'], SimpleEvent())
コード例 #14
0
ファイル: test_events.py プロジェクト: AprilMorone/kuma
    def test_registered_users_favored(self):
        """When removing duplicates, make sure registered users are kept in
        favor of anonymous ones having the same email address."""
        def make_anonymous_watches():
            for x in xrange(3):
                watch(event_type=TYPE, email='*****@*****.**').save()

        # Throw some anonymous watches in there in the hope that they would
        # come out on top if we didn't purposely favor registered users.
        # Suggestions on how to make this test more reliable are welcome.
        make_anonymous_watches()

        # File the registered watch:
        watch(event_type=TYPE,
              user=user(first_name='Jed', email='*****@*****.**',
                        save=True)).save()

        # A few more anonymous watches in case the BTrees flop in the other
        # direction:
        make_anonymous_watches()

        users_and_watches = list(SimpleEvent()._users_watching_by_filter())
        u, w = users_and_watches[0]
        eq_('Jed', u.first_name)
コード例 #15
0
    def test_registered_users_favored(self):
        """When removing duplicates, make sure registered users are kept in
        favor of anonymous ones having the same email address."""
        def make_anonymous_watches():
            for x in xrange(3):
                watch(event_type=TYPE, email='*****@*****.**').save()

        # Throw some anonymous watches in there in the hope that they would
        # come out on top if we didn't purposely favor registered users.
        # Suggestions on how to make this test more reliable are welcome.
        make_anonymous_watches()

        # File the registered watch:
        watch(event_type=TYPE,
              user=user(first_name='Jed', email='*****@*****.**',
                        save=True)).save()

        # A few more anonymous watches in case the BTrees flop in the other
        # direction:
        make_anonymous_watches()

        users_and_watches = list(SimpleEvent()._users_watching_by_filter())
        u, w = users_and_watches[0]
        eq_('Jed', u.first_name)
コード例 #16
0
    def test_duplicates(self):
        """Don't return duplicate email addresses."""
        watch(event_type=TYPE,
              user=user(email='*****@*****.**', save=True),
              save=True)
        watch(event_type=TYPE, email='*****@*****.**').save()
        watch(event_type=TYPE, email='*****@*****.**').save()
        eq_(3, Watch.objects.all().count())  # We created what we meant to.

        self._emails_eq(['*****@*****.**'], SimpleEvent())
コード例 #17
0
    def test_merging(self):
        """Test that duplicate emails across multiple events get merged."""
        # Remember to keep the emails in order when writing these test cases.
        # [Ed: But doesn't the SQL query have an ORDER BY?]
        watch(event_type=TYPE, email='*****@*****.**').save()
        watch(event_type=TYPE, email='*****@*****.**').save()
        registered_user = user(email='*****@*****.**', save=True)
        watch(event_type=ANOTHER_TYPE, user=registered_user).save()

        self._emails_eq(['*****@*****.**', '*****@*****.**'],
                        EventUnion(SimpleEvent(), AnotherEvent()))
コード例 #18
0
ファイル: test_events.py プロジェクト: AprilMorone/kuma
    def test_merging(self):
        """Test that duplicate emails across multiple events get merged."""
        # Remember to keep the emails in order when writing these test cases.
        # [Ed: But doesn't the SQL query have an ORDER BY?]
        watch(event_type=TYPE, email='*****@*****.**').save()
        watch(event_type=TYPE, email='*****@*****.**').save()
        registered_user = user(email='*****@*****.**', save=True)
        watch(event_type=ANOTHER_TYPE, user=registered_user).save()

        self._emails_eq(['*****@*****.**', '*****@*****.**'],
                        EventUnion(SimpleEvent(), AnotherEvent()))
コード例 #19
0
ファイル: test_events.py プロジェクト: AprilMorone/kuma
    def test_duplicates_case_insensitive(self):
        """De-duping should compare case-insensitively."""
        watch(event_type=TYPE, user=user(email='*****@*****.**', save=True),
              save=True)
        watch(event_type=TYPE, email='*****@*****.**').save()
        watch(event_type=TYPE, email='*****@*****.**').save()
        eq_(3, Watch.objects.all().count())  # We created what we meant to.

        addresses = [u.email
                     for u, w in SimpleEvent()._users_watching_by_filter()]
        eq_(1, len(addresses))
        eq_('*****@*****.**', addresses[0].lower())
コード例 #20
0
ファイル: test_events.py プロジェクト: AprilMorone/kuma
 def test_content_type(self):
     """Make sure watches filter properly by content type."""
     watch_type = ContentType.objects.get_for_model(Watch)
     content_type_type = ContentType.objects.get_for_model(ContentType)
     registered_user = user(email='*****@*****.**', save=True)
     watch(event_type=TYPE, content_type=content_type_type,
           user=registered_user).save()
     watch(event_type=TYPE, content_type=content_type_type,
           email='*****@*****.**').save()
     watch(event_type=TYPE, content_type=watch_type,
           email='*****@*****.**').save()
     self._emails_eq(['*****@*****.**', '*****@*****.**'],
                     ContentTypeEvent())
コード例 #21
0
    def test_duplicates_case_insensitive(self):
        """De-duping should compare case-insensitively."""
        watch(event_type=TYPE,
              user=user(email='*****@*****.**', save=True),
              save=True)
        watch(event_type=TYPE, email='*****@*****.**').save()
        watch(event_type=TYPE, email='*****@*****.**').save()
        eq_(3, Watch.objects.all().count())  # We created what we meant to.

        addresses = [
            u.email for u, w in SimpleEvent()._users_watching_by_filter()
        ]
        eq_(1, len(addresses))
        eq_('*****@*****.**', addresses[0].lower())
コード例 #22
0
 def test_content_type(self):
     """Make sure watches filter properly by content type."""
     watch_type = ContentType.objects.get_for_model(Watch)
     content_type_type = ContentType.objects.get_for_model(ContentType)
     registered_user = user(email='*****@*****.**', save=True)
     watch(event_type=TYPE,
           content_type=content_type_type,
           user=registered_user).save()
     watch(event_type=TYPE,
           content_type=content_type_type,
           email='*****@*****.**').save()
     watch(event_type=TYPE,
           content_type=watch_type,
           email='*****@*****.**').save()
     self._emails_eq(['*****@*****.**', '*****@*****.**'],
                     ContentTypeEvent())
コード例 #23
0
ファイル: test_tasks.py プロジェクト: gerv/kuma
    def test_anonymous_only(self):
        """Make sure having mixed watches claims right ones."""
        # Watch some before registering.
        watch(email='*****@*****.**', save=True)
        watch(email='*****@*****.**', save=True)
        watch(email='*****@*****.**', save=True)

        # Register.
        u = user(email='*****@*****.**', save=True)

        claim_watches(u)

        # Original anonymous watch is claimed.
        assert not Watch.objects.filter(email='*****@*****.**').exists()
        eq_(2, Watch.objects.filter(email=None).count())
        eq_(2, Watch.objects.filter(user=u).count())

        # No other watches are affected.
        assert Watch.objects.filter(email='*****@*****.**').exists()
コード例 #24
0
 def test_inactive(self):
     """Make sure inactive watches don't fire."""
     watch(event_type=TYPE, email='*****@*****.**', is_active=False).save()
     watch(event_type=TYPE, email='*****@*****.**').save()
     self._emails_eq(['*****@*****.**'], SimpleEvent())
コード例 #25
0
ファイル: test_events.py プロジェクト: AprilMorone/kuma
 def test_fire(self, _mails):
     """Assert firing the union gets the mails from the first event."""
     watch(event_type=TYPE, email='*****@*****.**').save()
     EventUnion(SimpleEvent(), AnotherEvent()).fire()
     assert _mails.called
コード例 #26
0
ファイル: test_events.py プロジェクト: AprilMorone/kuma
    def test_unique_by_email(self):
        """Test the routine that sorts through users and watches having the
        same email addresses."""
        # Test the best in a cluster coming first, in the middle, and last.
        # We mark the correct choices with secret='a'.
        users_and_watches = [
            (user(email='hi'), watch(secret='a')),
            (user(email='hi'), watch()),
            (user(), watch(email='hi')),

            (user(), watch(email='mid')),
            (user(email='mid'), watch(secret='a')),
            (user(), watch(email='mid')),

            (user(), watch(email='lo')),
            (user(), watch(email='lo')),
            (user(email='lo'), watch(secret='a')),

            (user(), watch(email='none', secret='a')),
            (user(), watch(email='none')),

            (user(), watch(email='hi', secret='a')),
            (user(), watch(email='hi')),
            (user(), watch(email='hi'))]

        favorites = list(_unique_by_email(users_and_watches))
        num_clusters = 5
        eq_(num_clusters, len(favorites))
        eq_(['a'] * num_clusters, [w.secret for u, w in favorites])
コード例 #27
0
ファイル: test_events.py プロジェクト: AprilMorone/kuma
 def test_inactive(self):
     """Make sure inactive watches don't fire."""
     watch(event_type=TYPE, email='*****@*****.**', is_active=False).save()
     watch(event_type=TYPE, email='*****@*****.**').save()
     self._emails_eq(['*****@*****.**'], SimpleEvent())
コード例 #28
0
 def test_fire(self, _mails):
     """Assert firing the union gets the mails from the first event."""
     watch(event_type=TYPE, email='*****@*****.**').save()
     EventUnion(SimpleEvent(), AnotherEvent()).fire()
     assert _mails.called
コード例 #29
0
 def _users_watching(self):
     return [(user(email='*****@*****.**'), watch()),
             (user(email='*****@*****.**'), watch())]
コード例 #30
0
 def _users_watching(self):
     return [(user(email='*****@*****.**'), watch())]
コード例 #31
0
ファイル: test_events.py プロジェクト: AprilMorone/kuma
 def make_anonymous_watches():
     for x in xrange(3):
         watch(event_type=TYPE, email='*****@*****.**').save()
コード例 #32
0
    def test_unique_by_email(self):
        """Test the routine that sorts through users and watches having the
        same email addresses."""
        # Test the best in a cluster coming first, in the middle, and last.
        # We mark the correct choices with secret='a'.
        users_and_watches = [(user(email='hi'), watch(secret='a')),
                             (user(email='hi'), watch()),
                             (user(), watch(email='hi')),
                             (user(), watch(email='mid')),
                             (user(email='mid'), watch(secret='a')),
                             (user(), watch(email='mid')),
                             (user(), watch(email='lo')),
                             (user(), watch(email='lo')),
                             (user(email='lo'), watch(secret='a')),
                             (user(), watch(email='none', secret='a')),
                             (user(), watch(email='none')),
                             (user(), watch(email='hi', secret='a')),
                             (user(), watch(email='hi')),
                             (user(), watch(email='hi'))]

        favorites = list(_unique_by_email(users_and_watches))
        num_clusters = 5
        eq_(num_clusters, len(favorites))
        eq_(['a'] * num_clusters, [w.secret for u, w in favorites])
コード例 #33
0
ファイル: test_events.py プロジェクト: AprilMorone/kuma
 def _users_watching(self):
     return [(user(email='*****@*****.**'), watch()),
             (user(email='*****@*****.**'), watch())]
コード例 #34
0
 def make_anonymous_watches():
     for x in xrange(3):
         watch(event_type=TYPE, email='*****@*****.**').save()
コード例 #35
0
ファイル: test_events.py プロジェクト: AprilMorone/kuma
 def _users_watching(self):
     return [(user(email='*****@*****.**'), watch())]