Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
exclude = build,.svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg
13 changes: 7 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
*.pyc
*.egg
*.egg-info
dist
eggs
build
sdist
*.pyc
.coverage
.env
.Python
bin/
build
dist
eggs
include/
lib/
.env
sdist
smtpapi/VERSION.txt
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ python:
install:
- python setup.py install
- pip install codecov
- if [[ $TRAVIS_PYTHON_VERSION != 2.6 ]]; then pip install flake8; fi
script:
- python test/__init__.py
- coverage run test/__init__.py
- if [[ $TRAVIS_PYTHON_VERSION != 2.6 ]]; then flake8 --statistics --count; fi
after_success:
- codecov
notifications:
Expand Down
22 changes: 13 additions & 9 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
from smtpapi import SMTPAPIHeader

import time
from os import path, sys
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll admit a personal preference towards using import os in this particular case but the real question is consistency. You don't seem to modify these imports in the other files this PR touches, why only here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will check the remaining comments later, thanks for the reviews!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably only moved imports in this file as flake8 only complained about these ones.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hugovk

So, why not fix it to be consistent with everything else?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't disagree with the sentiment of having consistency. But the acceptance criteria for #49 is simply that everything passes PEP8. So let's focus on that piece here, and then if folks like, other PRs can be opened to improve the consistency.


if __name__ == '__main__' and __package__ is None:
from os import sys, path

sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
from smtpapi import SMTPAPIHeader

header = SMTPAPIHeader()

# [To](http://sendgrid.com/docs/API_Reference/SMTP_API/index.html)
# header.add_to('[email protected]')
header.set_tos(['[email protected]', '[email protected]'])

# [Substitutions](http://sendgrid.com/docs/API_Reference/SMTP_API/substitution_tags.html)
# [Substitutions]
# (http://sendgrid.com/docs/API_Reference/SMTP_API/substitution_tags.html)
# header.add_substitution('key', 'value')
header.set_substitutions({'key': ['value1', 'value2']})

# [Unique Arguments](http://sendgrid.com/docs/API_Reference/SMTP_API/unique_arguments.html)
# [Unique Arguments]
# (http://sendgrid.com/docs/API_Reference/SMTP_API/unique_arguments.html)
# header.add_unique_arg('key', 'value')
header.set_unique_args({'key': 'value'})

Expand All @@ -32,16 +32,20 @@
# header.add_section('key', 'section')
header.set_sections({'key1': 'section1', 'key2': 'section2'})

# [Filters](http://sendgrid.com/docs/API_Reference/SMTP_API/apps.html)
# [Filters]
# (http://sendgrid.com/docs/API_Reference/SMTP_API/apps.html)
header.add_filter('filter', 'setting', 'value')

# [ASM Group ID](https://sendgrid.com/docs/User_Guide/advanced_suppression_manager.html)
# [ASM Group ID]
# (https://sendgrid.com/docs/User_Guide/advanced_suppression_manager.html)
header.set_asm_group_id('value')

# [IP Pools](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_pools.html)
# [IP Pools]
# (https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_pools.html)
header.set_ip_pool("testPool")

# [Scheduling Parameters](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html)
# [Scheduling Parameters]
# (https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html)
# header.add_send_each_at(unix_timestamp) # must be a unix timestamp
# header.set_send_each_at([]) # must be a unix timestamp
header.set_send_at(int(time.time())) # must be a unix timestamp
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

dir_path = os.path.abspath(os.path.dirname(__file__))
readme = io.open(os.path.join(dir_path, 'README.rst'), encoding='utf-8').read()
version = io.open(os.path.join(dir_path, 'VERSION.txt'), encoding='utf-8').read().strip()
version = io.open(
os.path.join(dir_path, 'VERSION.txt'),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, no modification of import os. Again, I personally prefer it this way and it seems like having consistency throughout the repo would be better overall.

encoding='utf-8',
).read().strip()
copy_file(os.path.join(dir_path, 'VERSION.txt'),
os.path.join(dir_path, 'smtpapi', 'VERSION.txt'),
verbose=0)
Expand Down
3 changes: 2 additions & 1 deletion smtpapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class _CustomJSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, decimal.Decimal):
return float(o)
# Provide a fallback to the default encoder if we haven't implemented special support for the object's class
# Provide a fallback to the default encoder if we haven't implemented
# special support for the object's class
return super(_CustomJSONEncoder, self).default(o)


Expand Down
25 changes: 20 additions & 5 deletions test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ def test_add(self):

def test_set(self):
header = SMTPAPIHeader()
header.set_tos(["[email protected]", "[email protected]", "[email protected]"])
header.set_tos([
"[email protected]",
"[email protected]",
"[email protected]",
])
header.set_substitutions({
"subKey": ["subValue"],
"decimalKey": [decimal.Decimal("1.23456789")]
Expand Down Expand Up @@ -85,7 +89,11 @@ def test_license_year(self):
if line.startswith('Copyright'):
copyright_line = line.strip()
break
self.assertEqual('Copyright (c) 2013-%s SendGrid, Inc.' % datetime.datetime.now().year, copyright_line)
self.assertEqual(
'Copyright (c) 2013-%s SendGrid, Inc.'
% datetime.datetime.now().year,
copyright_line
)


class TestRepository(unittest.TestCase):
Expand Down Expand Up @@ -118,10 +126,17 @@ def test_repository_files_exists(self):
for file_path in self.required_files:
if isinstance(file_path, list):
# multiple file paths: assert that any one of the files exists
self.assertTrue(any(os.path.exists(f) for f in file_path),
msg=self.file_not_found_message.format('" or "'.join(file_path)))
self.assertTrue(
any(os.path.exists(f) for f in file_path),
msg=self.file_not_found_message.format(
'" or "'.join(file_path)
),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the trailing comma really necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but in general, if another parameter was added (in practice, not likely with assertTrue), it would mean this previous line wouldn't be included in the diff. Happy to remove it if needed.

This is something Black could sort out automatically :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said before, using black would get rid of a bunch of overlapping PRs in sendgrid's repos.

)
else:
self.assertTrue(os.path.exists(file_path), msg=self.file_not_found_message.format(file_path))
self.assertTrue(
os.path.exists(file_path),
msg=self.file_not_found_message.format(file_path),
)


if __name__ == '__main__':
Expand Down
18 changes: 18 additions & 0 deletions test/test_license.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
try:
import unittest2 as unittest
except ImportError:
import unittest

import datetime


class LicenseTests(unittest.TestCase):
def test_license_year(self):
with open("license.txt", "r") as f:
copyright_line = f.readline().rstrip()

self.assertEqual(
"Copyright (c) 2012-%s SendGrid, Inc."
% datetime.datetime.now().year,
copyright_line,
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even this test seems to have the closing bracket consistent (on a separate line) unlike above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do the maintainers think about running Black on the codebase?

https://github.com/ambv/black

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hugovk

Using black is a great idea and sendgrid would only have to send out a fraction of the t-shirts after all the overlapping PEP8 pull requests were closed haha

22 changes: 0 additions & 22 deletions test/test_lisence.py

This file was deleted.

42 changes: 26 additions & 16 deletions test/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,67 +10,77 @@ class ProjectTests(unittest.TestCase):

# ./Docker or docker/Docker
def test_docker_dir(self):
self.assertEqual(True, os.path.isdir("./Dockerfile") || os.path.isdir("./docker/Dockerfile"))
self.assertTrue(
os.path.isdir("./Dockerfile")
or os.path.isdir("./docker/Dockerfile"),
)

# ./docker-compose.yml or ./docker/docker-compose.yml
def test_docker_compose(self):
self.assertEqual(True, os.path.isfile('./docker-compose.yml') || os.path.isfile('./docker/docker-compose.yml'))
self.assertTrue(
os.path.isfile('./docker-compose.yml')
or os.path.isfile('./docker/docker-compose.yml'),
)

# ./.env_sample
def test_env(self):
self.assertEqual(True, os.path.isfile('./env_sample'))
self.assertTrue(os.path.isfile('./env_sample'))

# ./.gitignore
def test_gitignore(self):
self.assertEqual(True, os.path.isfile('./.gitignore'))
self.assertTrue(os.path.isfile('./.gitignore'))

# ./.travis.yml
def test_travis(self):
self.assertEqual(True, os.path.isfile('./.travis.yml'))
self.assertTrue(os.path.isfile('./.travis.yml'))

# ./.codeclimate.yml
def test_codeclimate(self):
self.assertEqual(True, os.path.isfile('./.codeclimate.yml'))
self.assertTrue(os.path.isfile('./.codeclimate.yml'))

# ./CHANGELOG.md
def test_changelog(self):
self.assertEqual(True, os.path.isfile('./CHANGELOG.md'))
self.assertTrue(os.path.isfile('./CHANGELOG.md'))

# ./CODE_OF_CONDUCT.md
def test_code_of_conduct(self):
self.assertEqual(True, os.path.isfile('./CODE_OF_CONDUCT.md'))
self.assertTrue(os.path.isfile('./CODE_OF_CONDUCT.md'))

# ./CONTRIBUTING.md
def test_contributing(self):
self.assertEqual(True, os.path.isfile('./CONTRIBUTING.md'))
self.assertTrue(os.path.isfile('./CONTRIBUTING.md'))

# ./.github/ISSUE_TEMPLATE
def test_issue_template(self):
self.assertEqual(True, os.path.isfile('./.github/ISSUE_TEMPLATE'))
self.assertTrue(os.path.isfile('./.github/ISSUE_TEMPLATE'))

# ./LICENSE.md
def test_license(self):
self.assertEqual(True, os.path.isfile('./LICENSE.md') || os.path.isfile('./LICENSE.txt'))
self.assertTrue(
os.path.isfile('./LICENSE.md') or os.path.isfile('./LICENSE.txt'),
)

# ./.github/PULL_REQUEST_TEMPLATE
def test_pr_template(self):
self.assertEqual(True, os.path.isfile('./.github/PULL_REQUEST_TEMPLATE'))
self.assertTrue(
os.path.isfile('./.github/PULL_REQUEST_TEMPLATE'),
)

# ./README.rst
def test_readme(self):
self.assertEqual(True, os.path.isfile('./README.rst'))
self.assertTrue(os.path.isfile('./README.rst'))

# ./TROUBLESHOOTING.md
def test_troubleshooting(self):
self.assertEqual(True, os.path.isfile('./TROUBLESHOOTING.md'))
self.assertTrue(os.path.isfile('./TROUBLESHOOTING.md'))

# ./USAGE.md
def test_usage(self):
self.assertEqual(True, os.path.isfile('./USAGE.md'))
self.assertTrue(os.path.isfile('./USAGE.md'))

# ./VERSION.txt
def test_use_cases(self):
self.assertEqual(True, os.path.isfile('./VERSION.txt'))
self.assertTrue(os.path.isfile('./VERSION.txt'))


if __name__ == '__main__':
Expand Down