Unit testing for MIT user name calculation / mailing list protection.

(imported from commit ae7d4c0a1fea0b0887861a71828eae7c3022ec6f)
This commit is contained in:
Luke Faraone
2013-08-13 10:21:45 -07:00
parent 3129b6374d
commit 8c35db91c0

View File

@@ -4,6 +4,7 @@ from __future__ import absolute_import
from django.test import TestCase from django.test import TestCase
from django.test.simple import DjangoTestSuiteRunner from django.test.simple import DjangoTestSuiteRunner
from django.utils.timezone import now from django.utils.timezone import now
from django.core.exceptions import ValidationError
from django.db.models import Q from django.db.models import Q
from zerver.models import Message, UserProfile, Stream, Recipient, Subscription, \ from zerver.models import Message, UserProfile, Stream, Recipient, Subscription, \
@@ -14,11 +15,12 @@ from zerver.tornadoviews import json_get_updates, api_get_messages
from zerver.decorator import RespondAsynchronously, RequestVariableConversionError, profiled from zerver.decorator import RespondAsynchronously, RequestVariableConversionError, profiled
from zerver.lib.initial_password import initial_password from zerver.lib.initial_password import initial_password
from zerver.lib.actions import do_send_message, gather_subscriptions, \ from zerver.lib.actions import do_send_message, gather_subscriptions, \
create_stream_if_needed, do_add_subscription create_stream_if_needed, do_add_subscription, compute_mit_user_fullname
from zerver.lib.rate_limiter import add_ratelimit_rule, remove_ratelimit_rule from zerver.lib.rate_limiter import add_ratelimit_rule, remove_ratelimit_rule
from zerver.lib import bugdown from zerver.lib import bugdown
from zerver.lib.cache import bounce_key_prefix_for_testing from zerver.lib.cache import bounce_key_prefix_for_testing
from zerver.lib.rate_limiter import clear_user_history from zerver.lib.rate_limiter import clear_user_history
from zerver.forms import not_mit_mailing_list
from django.conf import settings from django.conf import settings
import os import os
@@ -1682,6 +1684,20 @@ class ChangeSettingsTest(AuthedTestCase):
result = self.post_with_params({"old_password": "bad_password"}) result = self.post_with_params({"old_password": "bad_password"})
self.assert_json_error(result, "Wrong password!") self.assert_json_error(result, "Wrong password!")
class MITNameTest(TestCase):
def test_valid_hesiod(self):
self.assertEquals(compute_mit_user_fullname("starnine@mit.edu"), "Athena Consulting Exchange User")
self.assertEquals(compute_mit_user_fullname("sipbexch@mit.edu"), "Exch Sipb")
def test_invalid_hesiod(self):
self.assertEquals(compute_mit_user_fullname("1234567890@mit.edu"), "1234567890@mit.edu")
self.assertEquals(compute_mit_user_fullname("ec-discuss@mit.edu"), "ec-discuss@mit.edu")
def test_mailinglist(self):
self.assertRaises(ValidationError, not_mit_mailing_list, "1234567890@mit.edu")
self.assertRaises(ValidationError, not_mit_mailing_list, "ec-discuss@mit.edu")
def test_notmailinglist(self):
self.assertTrue(not_mit_mailing_list("sipbexch@mit.edu"))
class S3Test(AuthedTestCase): class S3Test(AuthedTestCase):
test_uris = [] test_uris = []