From 6bc7f923bbe48a76d34377aa35a841f38500f0c9 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Sat, 20 Sep 2008 12:59:16 +1000 Subject: [PATCH] [parser] Merge senders with different case ... and add tests Signed-off-by: Jeremy Kerr --- apps/patchwork/bin/parsemail.py | 2 +- apps/patchwork/tests/patchparser.py | 41 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) 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==?= ' + + +class SenderCorrelationTest(unittest.TestCase): + existing_sender = 'Existing Sender ' + non_existing_sender = 'Non-existing Sender ' + + 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() -- 2.39.2