Skip to content

Commit

Permalink
Add tests for SubjectContains test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomi Richards committed Jun 15, 2015
1 parent 3be0f0d commit 3017ab1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
3 changes: 1 addition & 2 deletions gmailfilter/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class SubjectContains(Test):
"""

def __init__(self, search_string, case_sensitive=False):
def __init__(self, search_string, case_sensitive=True):
self._search_string = search_string
self._case_sensitive = case_sensitive

Expand All @@ -154,7 +154,6 @@ def __init__(self, target_list):
self._target_list = target_list

def match(self, message):

return get_list_id(message) == self._target_list


Expand Down
6 changes: 5 additions & 1 deletion gmailfilter/tests/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TestFactoryMixin(object):

"""A mixin class that generates test fake values."""

def get_email_message(self, headers=None):
def get_email_message(self, headers=None, subject='Test Subject'):
"""Get an email message.
:param headers: If set, must be a dict or 2-tuple iteratble of key/value
Expand All @@ -15,6 +15,7 @@ def get_email_message(self, headers=None):
message = FakeMessage()
if headers:
message.headers = dict(headers)
message.headers['Subject'] = subject
return message


Expand All @@ -26,3 +27,6 @@ def __init__(self):
def get_headers(self):
return self.headers

def subject(self):
return self.get_headers()['Subject']

37 changes: 37 additions & 0 deletions gmailfilter/tests/test_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
And,
Or,
MatchesHeader,
SubjectContains,
)
from gmailfilter._message import Message

Expand Down Expand Up @@ -86,3 +87,39 @@ def test_fails_when_header_value_is_wrong(self):
def test_passes_with_correct_value(self):
message = self.get_email_message(headers=dict(SomeHeader='123'))
self.assertTrue(MatchesHeader('SomeHeader', '123').match(message))


class SubjectContainsTests(TestCase, TestFactoryMixin):

def test_case_sensitive_contains_matches_whole_string(self):
message = self.get_email_message(subject='Hello World')
self.assertTrue(SubjectContains('Hello World').match(message))

def test_case_sensitive_contains_matches_partial_string(self):
message = self.get_email_message(subject='Hello World')
self.assertTrue(SubjectContains('ello Worl').match(message))

def test_case_sensitive_is_the_default(self):
message = self.get_email_message(subject='Hello World')
self.assertFalse(SubjectContains('hello world').match(message))

def test_case_insensitive_works_with_ascii(self):
message = self.get_email_message(subject='Hello World')
self.assertTrue(
SubjectContains('hello world', case_sensitive=False).match(message)
)

def test_case_insensitive_works_with_unicode(self):
message = self.get_email_message(subject='Hello BUẞE')
self.assertTrue(
SubjectContains('hello BUSSE', case_sensitive=False).match(message)
)
self.assertTrue(
SubjectContains('hello Buße', case_sensitive=False).match(message)
)

def test_case_insensitive_works_with_unicode_accents(self):
message = self.get_email_message(subject='Hêllo')
self.assertTrue(
SubjectContains('h\xeallo', case_sensitive=False).match(message)
)

0 comments on commit 3017ab1

Please sign in to comment.