summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2008-09-20 12:59:16 +1000
committerJeremy Kerr <jk@ozlabs.org>2008-09-20 12:59:16 +1000
commit6bc7f923bbe48a76d34377aa35a841f38500f0c9 (patch)
treefd9a719ca2ddc7cf1c086c042e8f8b88148878db
parent04d8e8e08c06d8dafccdfaf90352b473d5e0d048 (diff)
downloadpatchwork-6bc7f923bbe48a76d34377aa35a841f38500f0c9.tar.bz2
patchwork-6bc7f923bbe48a76d34377aa35a841f38500f0c9.tar.xz
[parser] Merge senders with different case
... and add tests Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-rwxr-xr-xapps/patchwork/bin/parsemail.py2
-rw-r--r--apps/patchwork/tests/patchparser.py41
2 files changed, 42 insertions, 1 deletions
diff --git a/apps/patchwork/bin/parsemail.py b/apps/patchwork/bin/parsemail.py
index 07554bc..a3edad4 100755
--- a/apps/patchwork/bin/parsemail.py
+++ b/apps/patchwork/bin/parsemail.py
@@ -104,7 +104,7 @@ def find_author(mail):
new_person = False
try:
- person = Person.objects.get(email = email)
+ person = Person.objects.get(email__iexact = email)
except Person.DoesNotExist:
person = Person(name = name, email = email)
new_person = True
diff --git a/apps/patchwork/tests/patchparser.py b/apps/patchwork/tests/patchparser.py
index eb07eb7..61ab57d 100644
--- a/apps/patchwork/tests/patchparser.py
+++ b/apps/patchwork/tests/patchparser.py
@@ -175,3 +175,44 @@ class SenderUTF8QPSplitEncodingTest(SenderEncodingTest):
class SenderUTF8B64EncodingTest(SenderUTF8QPEncodingTest):
from_header = '=?utf-8?B?w6l4YW1wbGUgdXNlcg==?= <user@example.com>'
+
+
+class SenderCorrelationTest(unittest.TestCase):
+ existing_sender = 'Existing Sender <existing@example.com>'
+ non_existing_sender = 'Non-existing Sender <nonexisting@example.com>'
+
+ def mail(self, sender):
+ return message_from_string('From: %s\nSubject: Test\n\ntest\n' % sender)
+
+ def setUp(self):
+ self.existing_sender_mail = self.mail(self.existing_sender)
+ self.non_existing_sender_mail = self.mail(self.non_existing_sender)
+ (self.person, new) = find_author(self.existing_sender_mail)
+ self.person.save()
+
+ print Person.objects.all()
+
+ def testExisingSender(self):
+ (person, new) = find_author(self.existing_sender_mail)
+ self.assertEqual(new, False)
+ self.assertEqual(person.id, self.person.id)
+
+ def testNonExisingSender(self):
+ (person, new) = find_author(self.non_existing_sender_mail)
+ self.assertEqual(new, True)
+ self.assertEqual(person.id, None)
+
+ def testExistingDifferentFormat(self):
+ mail = self.mail('existing@example.com')
+ (person, new) = find_author(mail)
+ self.assertEqual(new, False)
+ self.assertEqual(person.id, self.person.id)
+
+ def testExistingDifferentCase(self):
+ mail = self.mail(self.existing_sender.upper())
+ (person, new) = find_author(mail)
+ self.assertEqual(new, False)
+ self.assertEqual(person.id, self.person.id)
+
+ def tearDown(self):
+ self.person.delete()