From patchwork Wed Feb 14 13:34:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Veronika Kabatova X-Patchwork-Id: 873345 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zhL4774Bdz9t3C for ; Thu, 15 Feb 2018 00:34:47 +1100 (AEDT) Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3zhL474Y9fzF1Gv for ; Thu, 15 Feb 2018 00:34:47 +1100 (AEDT) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=redhat.com (client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=vkabatov@redhat.com; receiver=) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3zhL416DLRzF1F1 for ; Thu, 15 Feb 2018 00:34:41 +1100 (AEDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D1E6EB6F9 for ; Wed, 14 Feb 2018 13:34:38 +0000 (UTC) Received: from vkabatova.usersys.redhat.com (unknown [10.43.17.150]) by smtp.corp.redhat.com (Postfix) with ESMTP id 390D42023488; Wed, 14 Feb 2018 13:34:38 +0000 (UTC) From: vkabatov@redhat.com To: patchwork@lists.ozlabs.org Subject: [PATCH v2 2/2] Add test for list filtering feature Date: Wed, 14 Feb 2018 14:34:29 +0100 Message-Id: <20180214133429.18848-2-vkabatov@redhat.com> In-Reply-To: <20180214133429.18848-1-vkabatov@redhat.com> References: <20180214133429.18848-1-vkabatov@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 14 Feb 2018 13:34:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 14 Feb 2018 13:34:38 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'vkabatov@redhat.com' RCPT:'' X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" From: Veronika Kabatova Signed-off-by: Veronika Kabatova Reviewed-by: Stephen Finucane --- patchwork/tests/test_parser.py | 53 ++++++++++++++++++++++++++++++++++++++++++ patchwork/tests/utils.py | 1 + 2 files changed, 54 insertions(+) diff --git a/patchwork/tests/test_parser.py b/patchwork/tests/test_parser.py index abe11ad..c2704a4 100644 --- a/patchwork/tests/test_parser.py +++ b/patchwork/tests/test_parser.py @@ -896,6 +896,59 @@ class SubjectTest(TestCase): self.assertEqual(parse_version('Hello, world (V6)', []), 6) +class SubjectMatchTest(TestCase): + def setUp(self): + self.list_id = 'test-subject-match.test.org' + self.project_x = create_project(name='PROJECT X', + listid=self.list_id, + subject_match='.*PROJECT[\s]?X.*') + self.default_project = create_project(name='Default', + listid=self.list_id, + subject_match='') + self.keyword_project = create_project(name='keyword', + listid=self.list_id, + subject_match='keyword') + + self.email = MIMEText('') + self.email['List-Id'] = self.list_id + + self.email_no_project = MIMEText('') + self.email_no_project['List-Id'] = 'nonexistent-project.test.org' + self.email_no_project['Subject'] = '[PATCH keyword]' + + def test_project_with_regex(self): + self.email['Subject'] = '[PATCH PROJECT X subsystem]' + project = find_project(self.email) + self.assertEqual(project, self.project_x) + + self.email['Subject'] = '[PATCH PROJECTX another subsystem]' + project = find_project(self.email) + self.assertEqual(project, self.project_x) + + def test_project_with_keyword(self): + self.email['Subject'] = '[PATCH keyword] subsystem' + project = find_project(self.email) + self.assertEqual(project, self.keyword_project) + + def test_default_project(self): + self.email['Subject'] = '[PATCH unknown project]' + project = find_project(self.email) + self.assertEqual(project, self.default_project) + + self.email['Subject'] = '[PATCH NOT-PROJECT-X]' + project = find_project(self.email) + self.assertEqual(project, self.default_project) + + def test_nonexistent_project(self): + project = find_project(self.email_no_project) + self.assertEqual(project, None) + + def test_list_id_override(self): + project = find_project(self.email_no_project, + self.keyword_project.listid) + self.assertEqual(project, self.keyword_project) + + class FuzzTest(TransactionTestCase): """Test fuzzed patches.""" def setUp(self): diff --git a/patchwork/tests/utils.py b/patchwork/tests/utils.py index 004c2ca..fcd6762 100644 --- a/patchwork/tests/utils.py +++ b/patchwork/tests/utils.py @@ -72,6 +72,7 @@ def create_project(**kwargs): 'linkname': 'test-project-%d' % num, 'name': 'Test Project %d' % num, 'listid': 'test%d.example.com' % num, + 'subject_match': '', } values.update(kwargs)