Esempio n. 1
0
    def test_duplicate_feeds(self):
        """Ensure that duplicate feed codes aren't allowed."""
        d = HUGH_MANN.copy()
        d["email"] = "*****@*****.**"

        c = Client()
        self.login_as_tabler(c)

        self.assertEqual(models.Player.objects.count(), 0)
        self.assertEqual(models.User.objects.count(), 1)

        c.post(reverse("register"), HUGH_MANN)

        self.assertEqual(models.Player.objects.count(), 1)
        self.assertEqual(models.User.objects.count(), 2)

        # Register a different player with the same feed code. Some
        # error should be thrown, and the registration should not go
        # through.
        response = c.post(reverse("register"), d)
        self.assertFormError(response, "form", 'feed',
                             forms.RegisterForm.error_messages['duplicate_feed'],
        )
        self.assertEqual(User.objects.count(), 2)
        self.assertEqual(models.Player.objects.count(), 1)
Esempio n. 2
0
    def test_duplicate_feeds(self):
        """Ensure that duplicate feed codes aren't allowed."""
        d = HUGH_MANN.copy()
        d["email"] = "*****@*****.**"

        c = Client()
        self.login_as_tabler(c)

        self.assertEqual(models.Player.objects.count(), 0)
        self.assertEqual(models.User.objects.count(), 1)

        c.post(reverse("register"), HUGH_MANN)

        self.assertEqual(models.Player.objects.count(), 1)
        self.assertEqual(models.User.objects.count(), 2)

        # Register a different player with the same feed code. Some
        # error should be thrown, and the registration should not go
        # through.
        response = c.post(reverse("register"), d)
        self.assertFormError(response, "form", 'feed',
                             forms.RegisterForm.error_messages['duplicate_feed'],
        )
        self.assertEqual(User.objects.count(), 2)
        self.assertEqual(models.Player.objects.count(), 1)
Esempio n. 3
0
    def test_invalid_chars(self):
        """Ensure feedcodes with invalid characters throw error messages."""

        d = HUGH_MANN.copy()
        d["feed"] = "XYXYX"

        c = Client()
        self.login_as_tabler(c)
        response = c.post(reverse("register"), d)
        self.assertFormError(response, "form", "feed", "Y is not a valid character.")
Esempio n. 4
0
    def test_invalid_chars(self):
        """Ensure feedcodes with invalid characters throw error messages."""

        d = HUGH_MANN.copy()
        d["feed"] = "XYXYX"

        c = Client()
        self.login_as_tabler(c)
        response = c.post(reverse("register"), d)
        self.assertFormError(response, "form", "feed", "Y is not a valid character.")
Esempio n. 5
0
    def test_password_match(self):
        """Ensure that the password fields must match when registering."""
        c = Client()
        self.login_as_tabler(c)

        p = HUGH_MANN.copy()
        p['password2'] = "wrong"

        response = c.post(reverse('register'), p)

        self.assertFormError(
            response, 'form', 'password2',
            forms.RegisterForm.error_messages['password_mismatch']
        )

        self.assertEqual(models.Player.objects.count(), 0)
Esempio n. 6
0
    def test_password_match(self):
        """Ensure that the password fields must match when registering."""
        c = Client()
        self.login_as_tabler(c)

        p = HUGH_MANN.copy()
        p['password2'] = "wrong"

        response = c.post(reverse('register'), p)

        self.assertFormError(
            response, 'form', 'password2',
            forms.RegisterForm.error_messages['password_mismatch']
        )

        self.assertEqual(models.Player.objects.count(), 0)
Esempio n. 7
0
    def test_feed_length(self):
        """Ensure a feedcode must have the correct length."""
        d = HUGH_MANN.copy()
        d["feed"] = "PLAN"

        c = Client()
        self.login_as_tabler(c)

        with self.settings(FEED_LEN=5):
            response = c.post(reverse("register"), d)
            self.assertFormError(response, "form", "feed",
                                 "Ensure this value has at least 5 characters (it has 4).")

            d["feed"] = "SPLANS"
            response = c.post(reverse("register"), d)
            self.assertFormError(response, "form", "feed",
                                 "Ensure this value has at most 5 characters (it has 6).")
Esempio n. 8
0
    def test_feed_length(self):
        """Ensure a feedcode must have the correct length."""
        d = HUGH_MANN.copy()
        d["feed"] = "PLAN"

        c = Client()
        self.login_as_tabler(c)

        with self.settings(FEED_LEN=5):
            response = c.post(reverse("register"), d)
            self.assertFormError(response, "form", "feed",
                                 "Ensure this value has at least 5 characters (it has 4).")

            d["feed"] = "SPLANS"
            response = c.post(reverse("register"), d)
            self.assertFormError(response, "form", "feed",
                                 "Ensure this value has at most 5 characters (it has 6).")
Esempio n. 9
0
    def test_user_update(self):
        """Ensure that a user can register once for each game.

        The user's name and password should update with the new info.

        """

        # Register our user
        c = Client()
        self.login_as_tabler(c)
        c.post(reverse("register"), HUGH_MANN)

        # Move our Game into the past
        g = models.Game.objects.get()
        g.start_date, g.end_date = self.last_semester()
        g.save()

        # Create a new current Game
        self.create_new_game()

        # Modify our user settings slightly
        d = HUGH_MANN.copy()
        d["first_name"] = "Harold"
        d["last_name"] = "Zoid"
        d["password1"] = "swordfish"
        d["password2"] = "swordfish"

        # Save the old password
        u = models.User.objects.filter(username=d["email"]).get()
        old_password = u.password

        # And register with the new settings
        c.post(reverse("register"), d)

        # There should be two Players and two Users (remember our tabler user)
        self.assertEqual(models.Player.objects.count(), 2)
        self.assertEqual(models.User.objects.count(), 2)

        # And the new User's fields should be those defined by the newest
        # registration.
        u = models.User.objects.get(username=d["email"])
        self.assertEqual(u.first_name, d["first_name"])
        self.assertEqual(u.last_name, d["last_name"])
        self.assertNotEqual(u.password, old_password)
Esempio n. 10
0
    def test_user_update(self):
        """Ensure that a user can register once for each game.

        The user's name and password should update with the new info.

        """

        # Register our user
        c = Client()
        self.login_as_tabler(c)
        c.post(reverse("register"), HUGH_MANN)

        # Move our Game into the past
        g = models.Game.objects.get()
        g.start_date, g.end_date = self.last_semester()
        g.save()

        # Create a new current Game
        self.create_new_game()

        # Modify our user settings slightly
        d = HUGH_MANN.copy()
        d["first_name"] = "Harold"
        d["last_name"] = "Zoid"
        d["password1"] = "swordfish"
        d["password2"] = "swordfish"

        # Save the old password
        u = models.User.objects.filter(username=d["email"]).get()
        old_password = u.password

        # And register with the new settings
        c.post(reverse("register"), d)

        # There should be two Players and two Users (remember our tabler user)
        self.assertEqual(models.Player.objects.count(), 2)
        self.assertEqual(models.User.objects.count(), 2)

        # And the new User's fields should be those defined by the newest
        # registration.
        u = models.User.objects.get(username=d["email"])
        self.assertEqual(u.first_name, d["first_name"])
        self.assertEqual(u.last_name, d["last_name"])
        self.assertNotEqual(u.password, old_password)
Esempio n. 11
0
    def test_long_email(self):
        """Ensure someone with a long email address can register and log in."""

        LONG_EMAIL = "*****@*****.**"

        d = HUGH_MANN.copy()
        d['email'] = LONG_EMAIL

        # Check assumptions
        self.assertEqual(models.Player.objects.count(), 0)
        self.assertEqual(User.objects.count(), 1)

        # Test registration
        c = Client()
        self.login_as_tabler(c)
        response = c.post(reverse('register'), d, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(models.Player.objects.count(), 1)
        self.assertEqual(User.objects.count(), 2)

        # Test login
        response = c.post(reverse('login'), d, follow=True)
        self.assertEqual(response.status_code, 200)