summaryrefslogtreecommitdiff
path: root/devel/tests.py
diff options
context:
space:
mode:
authorNicolás Reynolds <fauno@kiwwwi.com.ar>2011-08-03 16:05:35 -0300
committerNicolás Reynolds <fauno@kiwwwi.com.ar>2011-08-03 16:05:35 -0300
commitfbd23db51b7160a308cd88e407e676994eb08b10 (patch)
treee3816cc4e3f0ee07539fb4464b2d886a43ecc318 /devel/tests.py
parenta8b2fc84ba96c83ec1addf89ac04608fbf572705 (diff)
parent0f6c80e9a36bc5770e95543b4374c5ace4383cf5 (diff)
Merge branch 'master' of git://projects.archlinux.org/archweb
Conflicts: packages/urls.py templates/packages/details.html
Diffstat (limited to 'devel/tests.py')
-rw-r--r--devel/tests.py88
1 files changed, 87 insertions, 1 deletions
diff --git a/devel/tests.py b/devel/tests.py
index 604da74c..36691179 100644
--- a/devel/tests.py
+++ b/devel/tests.py
@@ -1,8 +1,10 @@
from django.test import TestCase
+from django.contrib.auth.models import User
+from devel.utils import UserFinder
+from main.models import UserProfile
class DevelTest(TestCase):
-
def test_index(self):
response = self.client.get('/devel/')
self.assertEqual(response.status_code, 302)
@@ -27,3 +29,87 @@ class DevelTest(TestCase):
def test_mirrors(self):
response = self.client.get('/mirrors/')
self.assertEqual(response.status_code, 200)
+
+class FindUserTest(TestCase):
+
+ def setUp(self):
+ self.finder = UserFinder()
+
+ self.user1 = User.objects.create(username="joeuser", first_name="Joe",
+ last_name="User", email="user1@example.com")
+ self.user2 = User.objects.create(username="john", first_name="John",
+ last_name="", email="user2@example.com")
+ self.user3 = User.objects.create(username="bjones", first_name="Bob",
+ last_name="Jones", email="user3@example.com")
+
+ for user in (self.user1, self.user2, self.user3):
+ email_addr = "%s@awesome.com" % user.username
+ UserProfile.objects.create(user=user, public_email=email_addr)
+
+ self.user4 = User.objects.create(username="tim1", first_name="Tim",
+ last_name="One", email="tim@example.com")
+ self.user5 = User.objects.create(username="tim2", first_name="Tim",
+ last_name="Two", email="timtwo@example.com")
+
+ def test_not_matching(self):
+ self.assertIsNone(self.finder.find(None))
+ self.assertIsNone(self.finder.find(""))
+ self.assertIsNone(self.finder.find("Bogus"))
+ self.assertIsNone(self.finder.find("Bogus <invalid"))
+ self.assertIsNone(self.finder.find("Bogus User <bogus@example.com>"))
+ self.assertIsNone(self.finder.find("<bogus@example.com>"))
+ self.assertIsNone(self.finder.find("bogus@example.com"))
+ self.assertIsNone(self.finder.find("Unknown Packager"))
+
+ def test_by_email(self):
+ self.assertEqual(self.user1,
+ self.finder.find("XXX YYY <user1@example.com>"))
+ self.assertEqual(self.user2,
+ self.finder.find("YYY ZZZ <user2@example.com>"))
+
+ def test_by_profile_email(self):
+ self.assertEqual(self.user1,
+ self.finder.find("XXX <joeuser@awesome.com>"))
+ self.assertEqual(self.user2,
+ self.finder.find("YYY <john@awesome.com>"))
+ self.assertEqual(self.user3,
+ self.finder.find("ZZZ <bjones@awesome.com>"))
+
+ def test_by_name(self):
+ self.assertEqual(self.user1,
+ self.finder.find("Joe User <joe@differentdomain.com>"))
+ self.assertEqual(self.user1,
+ self.finder.find("Joe User"))
+ self.assertEqual(self.user2,
+ self.finder.find("John <john@differentdomain.com>"))
+ self.assertEqual(self.user2,
+ self.finder.find("John"))
+ self.assertEqual(self.user3,
+ self.finder.find("Bob Jones <bjones AT Arch Linux DOT org>"))
+
+ def test_by_invalid(self):
+ self.assertEqual(self.user1,
+ self.finder.find("Joe User <user1@example.com"))
+ self.assertEqual(self.user1,
+ self.finder.find("Joe 'nickname' User <user1@example.com"))
+ self.assertEqual(self.user1,
+ self.finder.find("Joe \"nickname\" User <user1@example.com"))
+ self.assertEqual(self.user1,
+ self.finder.find("Joe User <joe@differentdomain.com"))
+
+ def test_cache(self):
+ # simply look two of them up, but then do it repeatedly
+ for i in range(50):
+ self.assertEqual(self.user1,
+ self.finder.find("XXX YYY <user1@example.com>"))
+ self.assertEqual(self.user3,
+ self.finder.find("Bob Jones <bjones AT Arch Linux DOT org>"))
+
+ def test_ambiguous(self):
+ self.assertEqual(self.user4,
+ self.finder.find("Tim One <tim@anotherdomain.com>"))
+ self.assertEqual(self.user5,
+ self.finder.find("Tim Two <tim@anotherdomain.com>"))
+ self.assertIsNone(self.finder.find("Tim <tim@anotherdomain.com>"))
+
+# vim: set ts=4 sw=4 et: