Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Echo emails to the console if we're in sandbox mode. #45

Merged
merged 3 commits into from
Nov 19, 2018

Conversation

liavkoren
Copy link
Contributor

Hi! I find it extremely useful to be able to see emails in my console while developing. AFAICT, sendgrid doesn't seem to keep a record of what's sent to it while in sandbox mode.

To that end, I've bodged in a thread-safe print-to-console fallback while in sandbox mode, shamelessly based off of Django's ConsoleBackend implementation.

Wanna merge this?

Copy link
Owner

@sklarsa sklarsa left a comment

Choose a reason for hiding this comment

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

Can you make this feature a config option readable in settings.py? And also add tests for this code?

Thanks!

@liavkoren
Copy link
Contributor Author

Happy to write a test; would you want to see something along the lines of 'given expected input, assert self.stream.write' is called with that input?

@sklarsa
Copy link
Owner

sklarsa commented Nov 15, 2018 via email

@liavkoren
Copy link
Contributor Author

lol, first I tried to patch sys.stdout to test this, then got really confused that my terminal went unresponsive when I ran the tests.

I've added a boolean setting specifically for echo to stdout, although alternatively, the setting could be the stream object that you want to echo to itself. I don't mind changing it over to that if you'd prefer.

@liavkoren
Copy link
Contributor Author

Travis is falling over now at the point where it's trying to get the API KEY from the environment. There's something in the logs about them removing encrypted env vars, is that the problem?

@sklarsa
Copy link
Owner

sklarsa commented Nov 19, 2018

Yeah to prevent users from potentially exposing environment variables, travis removes those from tests run on PRs. You may need to add your test to this line (which would ignore it in travis builds so not the preferred choice) https://github.com/sklarsa/django-sendgrid-v5/blob/master/.travis.yml#L20 or set the API key using django's settings overrides https://docs.djangoproject.com/en/dev/topics/testing/tools/#overriding-settings

@liavkoren
Copy link
Contributor Author

If I use settings override, how do I point to the API key?

@sklarsa
Copy link
Owner

sklarsa commented Nov 19, 2018

Hmm you can't get to it until I merge the PR. I'll accept the PR if you feel that the tests should pass, then we can view what happens on the master branch when the key is injected into the environment by travis

@liavkoren
Copy link
Contributor Author

O _ O

Oh my. That's.. not nice.

Well. The patch and the test both Do The Things on my system, so give it a try.

sendgrid_backend/mail.py Outdated Show resolved Hide resolved
@sklarsa sklarsa merged commit b9c6da6 into sklarsa:master Nov 19, 2018
@liavkoren liavkoren deleted the echo-to-console branch November 19, 2018 23:29
@sklarsa
Copy link
Owner

sklarsa commented Nov 19, 2018

Ah looks like tests are still failing for 2 reasons (1 bad import in python 2 and a flake8 error).. I can fix them now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants