Skip to content

Commit

Permalink
Add test for list filtering feature
Browse files Browse the repository at this point in the history
Signed-off-by: Veronika Kabatova <vkabatov@redhat.com>
  • Loading branch information
veruu committed Feb 14, 2018
1 parent 380a69c commit 83d52c0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions patchwork/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,59 @@ def test_version(self):
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):
Expand Down
1 change: 1 addition & 0 deletions patchwork/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 83d52c0

Please sign in to comment.