Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1893e95
README: add instruction to use gmail app password
tai271828 May 17, 2020
d04d8f5
Add suffix option
tai271828 May 17, 2020
1912df0
README: instruction of multiple receiver format
tai271828 May 17, 2020
f7a0e6b
Update the example data for testing the suffix option
tai271828 May 17, 2020
e6ba004
Add more test receiver types
tai271828 May 17, 2020
7ddd873
feat(render and send): use separator option instead of suffix
tai271828 May 20, 2020
bb93c88
style: apply black style fix
tai271828 May 20, 2020
3952a13
test(tox): init tox.ini
tai271828 May 24, 2020
c9d5081
test(render_mail): introduce test_render_mail.py and its testing data
tai271828 May 25, 2020
1545dba
chore(pipfile.lock): update version of components
tai271828 May 25, 2020
b768850
style(test_render_mail.py): update by black
tai271828 May 25, 2020
524a3d4
test(test_render_mail.py): update relative path to fetch data correctly
tai271828 May 25, 2020
3f7b212
docs(readme.md): update option name of send_mail.py
tai271828 May 25, 2020
3b0a1f3
test(send_mail.py): add test cases for send_mail.py
tai271828 May 26, 2020
0c0e1e5
style: reformat through isort
Lee-W May 26, 2020
e0ec9fc
ci(github-actions): set python check to pushed and pull request
Lee-W May 26, 2020
9402894
style: style updating according to pr discussion
tai271828 May 26, 2020
e1a501b
test(tox): integreate tox to CI
tai271828 May 26, 2020
8d2192c
test(tox): remove flake8 in tox
tai271828 May 26, 2020
206423a
refactor: apply more pythonic idioms
tai271828 May 26, 2020
ffde802
refactor(tests): introduce utils.py
tai271828 May 26, 2020
f6b2b22
refactor(tests): introduce conftest.py
tai271828 May 26, 2020
3ddc37d
test: implement expected tearing down behavior
tai271828 May 26, 2020
189e475
style: apply black fix
tai271828 May 26, 2020
a827a01
style: apply pep8 and inv style fix
tai271828 May 26, 2020
fdcfbcc
style: apply isort fix via inv style.reformat
tai271828 May 26, 2020
2e63c67
refactor: apply more pythonic styling
tai271828 May 27, 2020
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
Prev Previous commit
Next Next commit
style(test_render_mail.py): update by black
  • Loading branch information
tai271828 committed May 25, 2020
commit b768850ecbccb37301bab0789f099274a1260b3c
80 changes: 56 additions & 24 deletions tests/test_render_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@
from render_mail import main


path_j2 = '../templates/sponsorship/spam_sponsors_2020.j2'
path_receivers_json = '../examples/sponsorship/spam_sponsors_2020.json'
path_mails_to_send_no_separator = '/tmp/mails_to_send/no-separator'
path_mails_to_send_with_separator = '/tmp/mails_to_send/with-separator'
path_pre_rendered_mails_no_separator = './data/no-separator'
path_pre_rendered_mails_with_separator = './data/with-separator'
path_j2 = "../templates/sponsorship/spam_sponsors_2020.j2"
path_receivers_json = "../examples/sponsorship/spam_sponsors_2020.json"
path_mails_to_send_no_separator = "/tmp/mails_to_send/no-separator"
path_mails_to_send_with_separator = "/tmp/mails_to_send/with-separator"
path_pre_rendered_mails_no_separator = "./data/no-separator"
path_pre_rendered_mails_with_separator = "./data/with-separator"


@pytest.fixture
def all_mails_base_no_separator():
return get_all_mail_names_from_path(glob.glob('/'.join((path_pre_rendered_mails_no_separator, '*@*'))))
return get_all_mail_names_from_path(
glob.glob("/".join((path_pre_rendered_mails_no_separator, "*@*")))
)


@pytest.fixture
def all_mails_base_with_separator():
return get_all_mail_names_from_path(glob.glob('/'.join((path_pre_rendered_mails_with_separator, '*@*'))))
return get_all_mail_names_from_path(
glob.glob("/".join((path_pre_rendered_mails_with_separator, "*@*")))
)


def get_all_mail_names_from_path(mails):
Expand All @@ -33,9 +37,13 @@ def get_all_mail_names_from_path(mails):
return all_mail_names


def compare_rendered_mail_all(targets, base_prefix='./data', target_prefix='../examples'):
def compare_rendered_mail_all(
targets, base_prefix="./data", target_prefix="../examples"
):
for mail_name in targets:
if not compare_rendered_mail('/'.join((base_prefix, mail_name)), '/'.join((target_prefix, mail_name))):
if not compare_rendered_mail(
"/".join((base_prefix, mail_name)), "/".join((target_prefix, mail_name))
):
return False

return True
Expand All @@ -47,27 +55,51 @@ def compare_rendered_mail(base, target):

def test_rendered_mail_no_separator(all_mails_base_no_separator):
runner = CliRunner()
result = runner.invoke(main, [path_j2, path_receivers_json, '--output_path', path_mails_to_send_no_separator])

all_mails_target = get_all_mail_names_from_path(glob.glob('/'.join((path_mails_to_send_no_separator, '*@*'))))
result = runner.invoke(
main,
[
path_j2,
path_receivers_json,
"--output_path",
path_mails_to_send_no_separator,
],
)

all_mails_target = get_all_mail_names_from_path(
glob.glob("/".join((path_mails_to_send_no_separator, "*@*")))
)

assert result.exit_code == 0
assert len(all_mails_base_no_separator) == len(all_mails_target)
assert compare_rendered_mail_all(all_mails_target,
base_prefix=path_pre_rendered_mails_no_separator,
target_prefix=path_mails_to_send_no_separator)
assert compare_rendered_mail_all(
all_mails_target,
base_prefix=path_pre_rendered_mails_no_separator,
target_prefix=path_mails_to_send_no_separator,
)


def test_rendered_mail_with_separator_dash(all_mails_base_with_separator):
runner = CliRunner()
result = runner.invoke(main, [path_j2, path_receivers_json,
'--output_path', path_mails_to_send_with_separator,
'--separator', ' - '])

all_mails_target = get_all_mail_names_from_path(glob.glob('/'.join((path_mails_to_send_with_separator, '*@*'))))
result = runner.invoke(
main,
[
path_j2,
path_receivers_json,
"--output_path",
path_mails_to_send_with_separator,
"--separator",
" - ",
],
)

all_mails_target = get_all_mail_names_from_path(
glob.glob("/".join((path_mails_to_send_with_separator, "*@*")))
)

assert result.exit_code == 0
assert len(all_mails_base_with_separator) == len(all_mails_target)
assert compare_rendered_mail_all(all_mails_target,
base_prefix=path_pre_rendered_mails_with_separator,
target_prefix=path_mails_to_send_with_separator)
assert compare_rendered_mail_all(
all_mails_target,
base_prefix=path_pre_rendered_mails_with_separator,
target_prefix=path_mails_to_send_with_separator,
)