<reponame>Mozilla-GitHub-Standards/4a4749ba7d28fec451e80ed9de9947acce774a0b4c7db797dc32439740ac770d<gh_stars>10-100
from django.test import TestCase

from tidings.models import Watch
from tidings.tasks import claim_watches
from .base import watch, user


class ClaimWatchesTests(TestCase):
    def test_none(self):
        """No anonymous watches to claim."""
        u = user(email='<EMAIL>', save=True)
        claim_watches(u)
        # Nothing happens, but no error is raised either.

    def test_anonymous_only(self):
        """Make sure having mixed watches claims right ones."""
        # Watch some before registering.
        watch(email='<EMAIL>', save=True)
        watch(email='<EMAIL>', save=True)
        watch(email='<EMAIL>', save=True)

        # Register.
        u = user(email='<EMAIL>', save=True)

        claim_watches(u)

        # Original anonymous watch is claimed.
        assert not Watch.objects.filter(email='<EMAIL>').exists()
        self.assertEqual(2, Watch.objects.filter(email=None).count())
        self.assertEqual(2, Watch.objects.filter(user=u).count())

        # No other watches are affected.
        assert Watch.objects.filter(email='<EMAIL>').exists()

    def test_mixed(self):
        """Make sure having mixed watches claims right ones."""
        # Watch before registering.
        watch(email='<EMAIL>', save=True)
        watch(email='<EMAIL>', save=True)

        # Register nobody.
        user(email='<EMAIL>', save=True)

        # Then register somebody and watch something after registering.
        u = user(email='<EMAIL>', save=True)
        watch(user=u, save=True)

        claim_watches(u)

        # Original anonymous watch is claimed.
        assert not Watch.objects.filter(email='<EMAIL>').exists()
        self.assertEqual(2, Watch.objects.filter(email=None).count())

        # No other watches are affected.
        assert Watch.objects.filter(email='<EMAIL>').exists()

from django.test import TestCase

from tidings.models import Watch
from tidings.tasks import claim_watches
from .base import watch, user


class ClaimWatchesTests(TestCase):
    def test_none(self):
        """No anonymous watches to claim."""
        u = user(email='<EMAIL>', save=True)
        claim_watches(u)
        # Nothing happens, but no error is raised either.

    def test_anonymous_only(self):
        """Make sure having mixed watches claims right ones."""
        # Watch some before registering.
        watch(email='<EMAIL>', save=True)
        watch(email='<EMAIL>', save=True)
        watch(email='<EMAIL>', save=True)

        # Register.
        u = user(email='<EMAIL>', save=True)

        claim_watches(u)

        # Original anonymous watch is claimed.
        assert not Watch.objects.filter(email='<EMAIL>').exists()
        self.assertEqual(2, Watch.objects.filter(email=None).count())
        self.assertEqual(2, Watch.objects.filter(user=u).count())

        # No other watches are affected.
        assert Watch.objects.filter(email='<EMAIL>').exists()

    def test_mixed(self):
        """Make sure having mixed watches claims right ones."""
        # Watch before registering.
        watch(email='<EMAIL>', save=True)
        watch(email='<EMAIL>', save=True)

        # Register nobody.
        user(email='<EMAIL>', save=True)

        # Then register somebody and watch something after registering.
        u = user(email='<EMAIL>', save=True)
        watch(user=u, save=True)

        claim_watches(u)

        # Original anonymous watch is claimed.
        assert not Watch.objects.filter(email='<EMAIL>').exists()
        self.assertEqual(2, Watch.objects.filter(email=None).count())

        # No other watches are affected.
        assert Watch.objects.filter(email='<EMAIL>').exists()
No anonymous watches to claim. # Nothing happens, but no error is raised either. Make sure having mixed watches claims right ones. # Watch some before registering. # Register. # Original anonymous watch is claimed. # No other watches are affected. Make sure having mixed watches claims right ones. # Watch before registering. # Register nobody. # Then register somebody and watch something after registering. # Original anonymous watch is claimed. # No other watches are affected.