Skip to content

Conversation

@tai271828
Copy link
Member

By adding suffix option we could then appending suffix to the original email subject. This will help us separate the corresponding threads of gmail. Gmail is happy to group emails with the same subjects, but in the scenario of how the sponsorship team organizes the emails, the sponsorship team would like to handle each email separately rather than folding them in the same thread.

Steps to Test This PR

The following steps are also performed and verified.

The Rendered Contents Are The Same

$ ./render_mail.py ./mail_handler/templates/sponsorship/sponsorship_spam_spons
ors_2020.j2 ./mail_handler/examples/sponsorship/spam_sponsors_2020.json --no-subject-suffix
$ ./render_mail.py ./mail_handler/templates/sponsorship/sponsorship_spam_spons
ors_2020.j2 ./mail_handler/examples/sponsorship/spam_sponsors_2020.json

And diff the files in mails_to_sent

Expected Result

No difference shown by the diff command.

Send The Rendered Emails

$ ./send_mail.py ./examples/sponsorship/spam_sponsors_2020_mail_config.json
You are about to send the mails under "mails_to_sent". Do you want to continue? [y/N]: y      
Please enter your mail account: tai271828@pycon.tw
Please enter you mail password:
INFO:root:Email sent to tai271828+sponsorship@gmail.com!
INFO:root:Email sent to tai271828+sponsorship@gmail.com!

Expected Result

The receivers could get the email with the render contents.

More Information

Please note I did not upload the corresponding testing json files because #1 has not merged. Touching the same json files will raise conflicts. I could upload them later after #1 is merged.

@tai271828 tai271828 mentioned this pull request May 17, 2020
Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! I leave some discussion regarding the try catch block. Also, I'll try to apply new tools in this repo. You might need to pull the latest version from this repo after that.

@tai271828 tai271828 force-pushed the pr-render-mail-config branch from 11342a9 to e6ba004 Compare May 19, 2020 15:18
@tai271828
Copy link
Member Author

tai271828 commented May 26, 2020

The PR is ready for review again except one coding style error Imports are incorrectly sorted. May @Lee-W tell me which rule we are going to apply to?

This updated PR includes:

  • Resolved conversation: add configurable suffix and pythonic idiom.
  • Add pytest-based tox test env and test cases to include the regresssion test of option "attachment" and "separator".

The implementation of the test cases has a lot of improvement space. It was implemented on top of the data structure that is out of scope. We may want to use this imperfect test as a foundation for the possible refactoring in the future rather than a very large code change for review (this PR is large enough, right? ; ) )

Verify This PR

By pytest and/or tox in the root folder.

More Tests Were Performed

pytest

(mail_handler) tai271828@dongl:~/work-my-projects/pycontw/mail_handler⟫ pytest
======================================================================================================== test session starts =========================================================================================================
platform linux -- Python 3.7.4, pytest-5.4.2, py-1.8.1, pluggy-0.13.1
rootdir: /home/tai271828/work-my-projects/pycontw/mail_handler, inifile: pytest.ini
collected 6 items                                                                                                                                                                                                                    

tests/test_render_mail.py ..                                                                                                                                                                                                   [ 33%]
tests/test_send_mail.py ....                                                                                                                                                                                                   [100%]

========================================================================================================== warnings summary =========================================================================================================$
/home/tai271828/.local/share/virtualenvs/mail_handler-q4_CV26H/lib/python3.7/site-packages/jinja2/utils.py:485
  /home/tai271828/.local/share/virtualenvs/mail_handler-q4_CV26H/lib/python3.7/site-packages/jinja2/utils.py:485: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    from collections import MutableMapping

/home/tai271828/.local/share/virtualenvs/mail_handler-q4_CV26H/lib/python3.7/site-packages/jinja2/runtime.py:318
  /home/tai271828/.local/share/virtualenvs/mail_handler-q4_CV26H/lib/python3.7/site-packages/jinja2/runtime.py:318: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecate$, and in 3.8 it will stop working
    from collections import Mapping

-- Docs: https://docs.pytest.org/en/latest/warnings.html
=================================================================================================== 6 passed, 2 warnings in 3.36s ===================================================================================================$

tox

(mail_handler) tai271828@dongl:~/work-my-projects/pycontw/mail_handler⟫ tox
py37 recreate: /home/tai271828/work-my-projects/pycontw/mail_handler/.tox/py37
py37 installdeps: pipenv
py37 installed: appdirs==1.4.4,certifi==2020.4.5.1,distlib==0.3.0,filelock==3.0.12,importlib-metadata==1.6.0,pipenv==2018.11.26,six==1.15.0,virtualenv==20.0.21,virtualenv-clone==0.5.4,zipp==3.1.0
py37 run-test-pre: PYTHONHASHSEED='3223062599'
py37 run-test: commands[0] | pipenv install --dev
Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to igno
re that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning.
Installing dependencies from Pipfile.lock (b813cd)…
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 77/77 — 00:00:56
py37 run-test: commands[1] | pytest
======================================================================================================== test session starts =========================================================================================================
platform linux -- Python 3.7.4, pytest-5.4.2, py-1.8.1, pluggy-0.13.1
cachedir: .tox/py37/.pytest_cache
rootdir: /home/tai271828/work-my-projects/pycontw/mail_handler, inifile: pytest.ini
plugins: cov-2.9.0, hypothesis-5.15.1, xdist-1.32.0, mock-3.1.0, forked-1.1.3
collected 6 items                                                                                                                                                                                                                    

tests/test_render_mail.py ..                                                                                                                                                                                                   [ 33%]
tests/test_send_mail.py ....                                                                                                                                                                                                   [100%]

========================================================================================================= 6 passed in 3.31s ==========================================================================================================
______________________________________________________________________________________________________________ summary _______________________________________________________________________________________________________________
  py37: commands succeeded
  congratulations :)

Render and send the mails

(mail_handler) tai271828@dongl:~/work-my-projects/pycontw/mail_handler⟫ ./render_mail.py ./templates/sponsorship/spam_sponsors_2020.j2 ./examples/sponsorship/spam_sponsors_2020.json                                                 
(mail_handler) tai271828@dongl:~/work-my-projects/pycontw/mail_handler⟫ ./render_mail.py --separator ' - ' ./templates/sponsorship/spam_sponsors_2020.j2 ./examples/sponsorship/spam_sponsors_2020.json                               
(mail_handler) tai271828@dongl:~/work-my-projects/pycontw/mail_handler⟫ ./render_mail.py --separator ' - ' ./templates/sponsorship/spam_sponsors_2020.j2 ./examples/sponsorship/spam_sponsors_2020.json
(mail_handler) tai271828@dongl:~/work-my-projects/pycontw/mail_handler⟫ ./send_mail.py --separator ' - ' ./examples/sponsorship/spam_sponsors_2020_mail_config.json 
You are about to send the mails under "mails_to_sent". Do you want to continue? [y/N]: y
Please enter your mail account: tai271828@pycon.tw
Please enter you mail password: 
INFO:root:Email sent to tai271828+sponsorship.testemail.4@gmail.com, tai271828+sponsorship.testemail.4.1@pycon.tw, taihsiangho+sponsorship.testemail.4.2@gmail.com,tai271828+sponsorship.testemail.4.3@solvcon.net!
INFO:root:Email sent to tai271828+sponsorship.testemail.3@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.2@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.3@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.4@gmail.com, tai271828+sponsorship.testemail.4.1@pycon.tw, taihsiangho+sponsorship.testemail.4.2@gmail.com,tai271828+sponsorship.testemail.4.3@solvcon.net!
INFO:root:Email sent to tai271828+sponsorship.testemail.1@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.2@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.1@gmail.com!
(mail_handler) tai271828@dongl:~/work-my-projects/pycontw/mail_handler⟫ ./send_mail.py --separator ' - ' --attachment_file ./tests/data/attachment-file/attachment01.txt ./examples/sponsorship/spam_sponsors_2020_mail_config.json 
You are about to send the mails under "mails_to_sent". Do you want to continue? [y/N]: y
Please enter your mail account: tai271828@pycon.tw
Please enter you mail password: 
INFO:root:Email sent to tai271828+sponsorship.testemail.4@gmail.com, tai271828+sponsorship.testemail.4.1@pycon.tw, taihsiangho+sponsorship.testemail.4.2@gmail.com,tai271828+sponsorship.testemail.4.3@solvcon.net!
INFO:root:Email sent to tai271828+sponsorship.testemail.3@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.2@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.3@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.4@gmail.com, tai271828+sponsorship.testemail.4.1@pycon.tw, taihsiangho+sponsorship.testemail.4.2@gmail.com,tai271828+sponsorship.testemail.4.3@solvcon.net!
INFO:root:Email sent to tai271828+sponsorship.testemail.1@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.2@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.1@gmail.com!
(mail_handler) tai271828@dongl:~/work-my-projects/pycontw/mail_handler⟫ 

@tai271828 tai271828 requested a review from Lee-W May 26, 2020 05:55
Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! It's a huge improvement in our existing codebase. I like the tox integration to the project.

I already fix the Github action. Two of our tests fail. You can view them here.

As for the Imports are incorrectly sorted. discussion, we use isort to sort our imports. You can use inv style.reformat to reformat the codebase. Aside from following what pep8 suggests, it sort libraries in the same group in alphabetic order.

I did not notice the last part of message regarding to the test part. Surely, we can fix them later if you deem they are too huge to fix in this pull request

@tai271828 tai271828 force-pushed the pr-render-mail-config branch from b1d9753 to 0b3b698 Compare May 26, 2020 12:13
Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

Other than the failed tests, there's no major change needed. Once they're fix, we can merge this PR. 🎉

@tai271828 tai271828 force-pushed the pr-render-mail-config branch from 0b3b698 to a19516a Compare May 26, 2020 16:02
tai271828 added 4 commits May 27, 2020 00:28
We already have flake8 check via invoke and only one flake8 configuration in one place will make the
code easier to maintain.
tai271828 added 4 commits May 27, 2020 01:02
By removing the ephemeral files we may avoid false positive testing result in the future, because
the runner may not generate expected files for each regression test.
@tai271828 tai271828 force-pushed the pr-render-mail-config branch from c32921c to 189e475 Compare May 26, 2020 17:41
@tai271828 tai271828 requested a review from Lee-W May 26, 2020 17:45
@tai271828
Copy link
Member Author

Besides CI, sending rendered emails via gmail was also performed (again)

(mail_handler) tai271828@dongl:~/work-my-projects/pycontw/mail_handler⟫ ./render_mail.py ./templates/sponsorship/spam_sponsors_2020.j2 ./examples/sponsorship/spam_sponsors_2020.json
(mail_handler) tai271828@dongl:~/work-my-projects/pycontw/mail_handler⟫ ./render_mail.py --separator ' - ' ./templates/sponsorship/spam_sponsors_2020.j2 ./examples/sponsorship/spam_sponsors_2020.json                               
(mail_handler) tai271828@dongl:~/work-my-projects/pycontw/mail_handler⟫  ./send_mail.py --separator ' - ' ./examples/sponsorship/spam_sponsors_2020_mail_config.json
You are about to send the mails under "mails_to_sent". Do you want to continue? [y/N]: y
Please enter your mail account: tai271828@pycon.tw
Please enter you mail password: 
INFO:root:Email sent to tai271828+sponsorship.testemail.4@gmail.com, tai271828+sponsorship.testemail.4.1@pycon.tw, taihsiangho+sponsorship.testemail.4.2@gmail.com,tai271828+sponsorship.testemail.4.3@solvcon.net!
INFO:root:Email sent to tai271828+sponsorship.testemail.3@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.2@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.3@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.4@gmail.com, tai271828+sponsorship.testemail.4.1@pycon.tw, taihsiangho+sponsorship.testemail.4.2@gmail.com,tai271828+sponsorship.testemail.4.3@solvcon.net!
INFO:root:Email sent to tai271828+sponsorship.testemail.1@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.2@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.1@gmail.com!
(mail_handler) tai271828@dongl:~/work-my-projects/pycontw/mail_handler⟫ 
(mail_handler) tai271828@dongl:~/work-my-projects/pycontw/mail_handler⟫ 
(mail_handler) tai271828@dongl:~/work-my-projects/pycontw/mail_handler⟫ 
(mail_handler) tai271828@dongl:~/work-my-projects/pycontw/mail_handler⟫ ./send_mail.py --separator ' - ' --attachment_file ./tests/data/attachment-file/attachment01.txt ./examples/sponsorship/spam_sponsors_2020_mail_config.json
You are about to send the mails under "mails_to_sent". Do you want to continue? [y/N]: y
Please enter your mail account: tai271828@pycon.tw
Please enter you mail password: 
INFO:root:Email sent to tai271828+sponsorship.testemail.4@gmail.com, tai271828+sponsorship.testemail.4.1@pycon.tw, taihsiangho+sponsorship.testemail.4.2@gmail.com,tai271828+sponsorship.testemail.4.3@solvcon.net!
INFO:root:Email sent to tai271828+sponsorship.testemail.3@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.2@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.3@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.4@gmail.com, tai271828+sponsorship.testemail.4.1@pycon.tw, taihsiangho+sponsorship.testemail.4.2@gmail.com,tai271828+sponsorship.testemail.4.3@solvcon.net!
INFO:root:Email sent to tai271828+sponsorship.testemail.1@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.2@gmail.com!
INFO:root:Email sent to tai271828+sponsorship.testemail.1@gmail.com!
(mail_handler) tai271828@dongl:~/work-my-projects/pycontw/mail_handler⟫ 

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

I add some nitpicks that you can ignore in this PR. However, I think importing functions in tests is a major one.

Also, I don't quite get your comment here. Is it an example of how we should run the program?

send_mail.py Outdated

import click

from tests.utils import send_mail_debug_dump_path
Copy link
Member

Choose a reason for hiding this comment

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

It seems to me that our program should not depend on our test files. Even duplication seems to be a better solution to me. One of the reasons is that after we make this project a package, it won't pack tests into it. @tai271828 What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair, hahahahahaha

tests/utils.py Outdated
Comment on lines 17 to 21
all_mail_names = []
for mail in mails:
all_mail_names.append(os.path.basename(mail))

return all_mail_names
Copy link
Member

Choose a reason for hiding this comment

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

I prefer using list comprehension for simply iterations. i.e. return [os.path.basename(mail) for mail in mails]

Copy link
Member Author

Choose a reason for hiding this comment

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

+1. We should always insist list comprehension. This is suggested in "fluent python".

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

Thanks for all the hard-working! Let's merge it!

@Lee-W Lee-W merged commit e58e842 into pycontw:master May 27, 2020
@tai271828 tai271828 deleted the pr-render-mail-config branch May 27, 2020 01:34
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.

2 participants