From 3363e01f99cd60d23029d25c7102abdafa5aeacc Mon Sep 17 00:00:00 2001 From: Peter Yasi Date: Thu, 18 Oct 2018 23:23:12 -0400 Subject: [PATCH 1/2] Add unit tests for spam check --- test/test_spam_check.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test/test_spam_check.py diff --git a/test/test_spam_check.py b/test/test_spam_check.py new file mode 100644 index 000000000..240b5b114 --- /dev/null +++ b/test/test_spam_check.py @@ -0,0 +1,38 @@ +from sendgrid.helpers.mail.spam_check import SpamCheck + +try: + import unittest2 as unittest +except ImportError: + import unittest + + +class UnitTests(unittest.TestCase): + + def test_spam_all_values(self): + expected = {'enable': True, 'threshold': 5, 'post_to_url': 'https://www.test.com'} + spam_check = SpamCheck(enable=True, threshold=5, post_to_url='https://www.test.com') + self.assertEqual(spam_check.get(), expected) + + def test_spam_no_url(self): + expected = {'enable': True, 'threshold': 10} + spam_check = SpamCheck(enable=True, threshold=10) + self.assertEqual(spam_check.get(), expected) + + def test_spam_no_threshold(self): + expected = {'enable': True} + spam_check = SpamCheck(enable=True) + self.assertEqual(spam_check.get(), expected) + + def test_has_values_but_not_enabled(self): + expected = {'enable': False, 'threshold': 1, 'post_to_url': 'https://www.test.com'} + spam_check = SpamCheck(enable=False, threshold=1, post_to_url='https://www.test.com') + self.assertEqual(spam_check.get(), expected) + + def test_spam_change_properties(self): + expected = {'enable': False, 'threshold': 10, 'post_to_url': 'https://www.testing.com'} + spam_check = SpamCheck(enable=True, threshold=5, post_to_url='https://www.test.com') + spam_check.enable = False + spam_check.threshold = 10 + spam_check.post_to_url = 'https://www.testing.com' + self.assertEqual(spam_check.get(), expected) + From 0f7e83616db51172e3836bdcf4aec7392e00bfaf Mon Sep 17 00:00:00 2001 From: Peter Yasi Date: Thu, 18 Oct 2018 23:28:23 -0400 Subject: [PATCH 2/2] Test description --- test/test_spam_check.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_spam_check.py b/test/test_spam_check.py index 240b5b114..326c5d070 100644 --- a/test/test_spam_check.py +++ b/test/test_spam_check.py @@ -29,6 +29,8 @@ def test_has_values_but_not_enabled(self): self.assertEqual(spam_check.get(), expected) def test_spam_change_properties(self): + """Tests changing the properties of the spam check class""" + expected = {'enable': False, 'threshold': 10, 'post_to_url': 'https://www.testing.com'} spam_check = SpamCheck(enable=True, threshold=5, post_to_url='https://www.test.com') spam_check.enable = False