diff --git a/examples/helpers/stats/stats_example.py b/examples/helpers/stats/stats_example.py index d48664c3f..f3196881a 100644 --- a/examples/helpers/stats/stats_example.py +++ b/examples/helpers/stats/stats_example.py @@ -45,6 +45,7 @@ def build_subuser_stats(): # subuser_stats.add_subuser(Subuser("bar")) return subuser_stats.get() + def build_subuser_stats_sums(): subuser_stats = SubuserStats() subuser_stats.start_date = '2017-10-15' @@ -92,6 +93,7 @@ def get_subuser_stats_sums(): print(response.headers) pprint_json(response.body) + get_global_stats() get_category_stats() get_category_stats_sums() diff --git a/register.py b/register.py index 0a7ffe8d8..00ddca15c 100644 --- a/register.py +++ b/register.py @@ -17,4 +17,4 @@ ''' final_text = readme_rst.replace(replace, replacement) with open('./README.txt', 'w', encoding='utf-8') as f: - f.write(final_text) + f.write(final_text) diff --git a/sendgrid/helpers/inbound/config.py b/sendgrid/helpers/inbound/config.py index d0c6517bc..32bec0793 100644 --- a/sendgrid/helpers/inbound/config.py +++ b/sendgrid/helpers/inbound/config.py @@ -15,7 +15,7 @@ def __init__(self, **opts): self.path = opts.get( 'path', os.path.abspath(os.path.dirname(__file__)) ) - with open(self.path + '/config.yml') as stream: + with open('{0}/config.yml'.format(self.path)) as stream: config = yaml.load(stream) self._debug_mode = config['debug_mode'] self._endpoint = config['endpoint'] @@ -28,8 +28,9 @@ def init_environment(): """Allow variables assigned in .env available using os.environ.get('VAR_NAME')""" base_path = os.path.abspath(os.path.dirname(__file__)) - if os.path.exists(base_path + '/.env'): - with open(base_path + '/.env') as f: + env_path = '{0}/.env'.format(base_path) + if os.path.exists(env_path): + with open(env_path) as f: lines = f.readlines() for line in lines: var = line.strip().split('=') diff --git a/sendgrid/helpers/inbound/send.py b/sendgrid/helpers/inbound/send.py index 6de575aab..e3526eb7c 100644 --- a/sendgrid/helpers/inbound/send.py +++ b/sendgrid/helpers/inbound/send.py @@ -37,6 +37,7 @@ def url(self): """URL to send to.""" return self._url + def main(): config = Config() parser = argparse.ArgumentParser(description='Test data and optional host.') @@ -54,5 +55,6 @@ def main(): print(response.headers) print(response.body) + if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/sendgrid/helpers/mail/content.py b/sendgrid/helpers/mail/content.py index cff8ac498..da4ed8027 100644 --- a/sendgrid/helpers/mail/content.py +++ b/sendgrid/helpers/mail/content.py @@ -1,5 +1,6 @@ from .validators import ValidateAPIKey + class Content(object): """Content to be included in your email. diff --git a/sendgrid/helpers/mail/exceptions.py b/sendgrid/helpers/mail/exceptions.py index ab4dd9c0c..5279c365a 100644 --- a/sendgrid/helpers/mail/exceptions.py +++ b/sendgrid/helpers/mail/exceptions.py @@ -2,6 +2,7 @@ # Various types of extensible SendGrid related exceptions ################################################################ + class SendGridException(Exception): """Wrapper/default SendGrid-related exception""" pass @@ -19,4 +20,3 @@ def __init__(self, message="SendGrid API Key detected"): self.expression = expression self.message = message - diff --git a/sendgrid/helpers/mail/validators.py b/sendgrid/helpers/mail/validators.py index b4a69f697..96e81795e 100644 --- a/sendgrid/helpers/mail/validators.py +++ b/sendgrid/helpers/mail/validators.py @@ -3,6 +3,7 @@ # Various types of Validators ################################################################ + class ValidateAPIKey(object): """Validates content to ensure SendGrid API key is not present""" @@ -27,7 +28,6 @@ def __init__(self, regex_strings=None, use_default=True): default_regex_string = 'SG\.[0-9a-zA-Z]+\.[0-9a-zA-Z]+' self.regexes.add(re.compile(default_regex_string)) - def validate_message_dict(self, request_body): """With the JSON dict that will be sent to SendGrid's API, check the content for SendGrid API keys - throw exception if found @@ -54,7 +54,6 @@ def validate_message_dict(self, request_body): message_text = content.get("value", "") self.validate_message_text(message_text) - def validate_message_text(self, message_string): """With a message string, check to see if it contains a SendGrid API Key If a key is found, throw an exception @@ -68,4 +67,3 @@ def validate_message_text(self, message_string): for regex in self.regexes: if regex.match(message_string) is not None: raise APIKeyIncludedException() - diff --git a/setup.py b/setup.py index 014691b61..11aa3a07e 100644 --- a/setup.py +++ b/setup.py @@ -20,6 +20,7 @@ def getRequires(): deps.append('unittest2py3k') return deps + setup( name='sendgrid', version=str(__version__), diff --git a/test/test_app.py b/test/test_app.py index 1a8e4a698..13b0a9522 100644 --- a/test/test_app.py +++ b/test/test_app.py @@ -23,4 +23,4 @@ def test_up_and_running(self): def test_used_port_true(self): if self.config.debug_mode: port = int(os.environ.get("PORT", self.config.port)) - self.assertEqual(port, self.config.port) \ No newline at end of file + self.assertEqual(port, self.config.port) diff --git a/test/test_config.py b/test/test_config.py index 301bacc92..d20af40e2 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -43,7 +43,7 @@ def test_initialization(self): def test_init_environment(self): config_file = sendgrid.helpers.inbound.config.__file__ - env_file_path = os.path.abspath(os.path.dirname(config_file)) + '/.env' + env_file_path = '{0}/.env'.format(os.path.abspath(os.path.dirname(config_file))) with open(env_file_path, 'w') as f: f.write('RANDOM_VARIABLE=RANDOM_VALUE') Config() diff --git a/test/test_mail.py b/test/test_mail.py index 08d0feb8e..ffe5586b4 100644 --- a/test/test_mail.py +++ b/test/test_mail.py @@ -52,7 +52,7 @@ def test_sendgridAPIKey(self): personalization.add_to(Email("test@example.com")) mail.add_personalization(personalization) - #Try to include SendGrid API key + # Try to include SendGrid API key try: mail.add_content(Content("text/plain", "some SG.2123b1B.1212lBaC here")) mail.add_content( @@ -72,11 +72,11 @@ def test_sendgridAPIKey(self): '"subject": "Hello World from the SendGrid Python Library"}' ) - #Exception should be thrown + # Exception should be thrown except Exception as e: pass - #Exception not thrown + # Exception not thrown else: self.fail("Should have failed as SendGrid API key included") diff --git a/test/test_project.py b/test/test_project.py index 4fbc8147c..5e269ae43 100644 --- a/test/test_project.py +++ b/test/test_project.py @@ -5,6 +5,7 @@ except ImportError: import unittest + class ProjectTests(unittest.TestCase): # ./docker @@ -71,5 +72,6 @@ def test_usage(self): def test_use_cases(self): self.assertTrue(os.path.isfile('./use_cases/README.md')) + if __name__ == '__main__': unittest.main() diff --git a/test/test_send.py b/test/test_send.py index 16d496b85..7079c8b0e 100644 --- a/test/test_send.py +++ b/test/test_send.py @@ -30,13 +30,18 @@ def test_send(self): x = send.Send(fake_url) x.test_payload(fake_url) - send.Client.assert_called_once_with(host=fake_url, request_headers={'User-Agent': 'SendGrid-Test', - 'Content-Type': 'multipart/form-data; boundary=xYzZY'}) + send.Client.assert_called_once_with(host=fake_url, request_headers={ + 'User-Agent': 'SendGrid-Test', + 'Content-Type': 'multipart/form-data; boundary=xYzZY' + }) def test_main_call(self): fake_url = 'https://fake_url' - with mock.patch('argparse.ArgumentParser.parse_args', return_value=argparse.Namespace(host=fake_url, data='test_file.txt')): + with mock.patch('argparse.ArgumentParser.parse_args', return_value=argparse.Namespace( + host=fake_url, data='test_file.txt')): send.main() - send.Client.assert_called_once_with(host=fake_url, request_headers={'User-Agent': 'SendGrid-Test', - 'Content-Type': 'multipart/form-data; boundary=xYzZY'}) + send.Client.assert_called_once_with(host=fake_url, request_headers={ + 'User-Agent': 'SendGrid-Test', + 'Content-Type': 'multipart/form-data; boundary=xYzZY' + }) diff --git a/test/test_sendgrid.py b/test/test_sendgrid.py index c545cbb2d..37fe9f9f8 100644 --- a/test/test_sendgrid.py +++ b/test/test_sendgrid.py @@ -1,6 +1,7 @@ import sendgrid from sendgrid.helpers.mail import * from sendgrid.version import __version__ + try: import unittest2 as unittest except ImportError: @@ -25,7 +26,7 @@ def setUpClass(cls): cls.sg = sendgrid.SendGridAPIClient(host=host) cls.devnull = open(os.devnull, 'w') prism_cmd = None - + # try: # # check for prism in the PATH # if subprocess.call('prism version'.split(), stdout=cls.devnull) == 0: @@ -134,7 +135,7 @@ def test_reset_request_headers(self): self.assertNotIn('blah', self.sg.client.request_headers) self.assertNotIn('blah2x', self.sg.client.request_headers) - for k,v in self.sg._default_headers.items(): + for k, v in self.sg._default_headers.items(): self.assertEqual(v, self.sg.client.request_headers[k]) def test_hello_world(self): @@ -144,8 +145,11 @@ def test_hello_world(self): content = Content( "text/plain", "and easy to do anywhere, even with Python") mail = Mail(from_email, subject, to_email, content) - self.assertTrue(mail.get() == {'content': [{'type': 'text/plain', 'value': 'and easy to do anywhere, even with Python'}], 'personalizations': [ - {'to': [{'email': 'test@example.com'}]}], 'from': {'email': 'test@example.com'}, 'subject': 'Sending with SendGrid is Fun'}) + self.assertTrue( + mail.get() == {'content': [{'type': 'text/plain', 'value': 'and easy to do anywhere, even with Python'}], + 'personalizations': [ + {'to': [{'email': 'test@example.com'}]}], 'from': {'email': 'test@example.com'}, + 'subject': 'Sending with SendGrid is Fun'}) def test_access_settings_activity_get(self): params = {'limit': 1} diff --git a/test/test_unassigned.py b/test/test_unassigned.py index d13451277..6054447d8 100644 --- a/test/test_unassigned.py +++ b/test/test_unassigned.py @@ -55,6 +55,7 @@ } ] ''' + def get_all_ip(): ret_val = json.loads(ret_json) return ret_val @@ -67,7 +68,6 @@ def make_data(): return data - def test_unassigned_ip_json(): data = make_data() @@ -79,6 +79,7 @@ def test_unassigned_ip_json(): for item in calculated: assert item["ip"] in data + def test_unassigned_ip_obj(): data = make_data() @@ -89,6 +90,7 @@ def test_unassigned_ip_obj(): for item in calculated: assert item["ip"] in data + def test_unassigned_baddata(): as_json = False calculated = unassigned(dict(), as_json=as_json)