-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from moshthepitt/issue-24
version 0.1.5
- Loading branch information
Showing
16 changed files
with
469 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
""" | ||
Main init file for small_small_hr | ||
""" | ||
VERSION = (0, 1, 4) | ||
VERSION = (0, 1, 5) | ||
__version__ = '.'.join(str(v) for v in VERSION) | ||
# pylint: disable=invalid-name | ||
default_app_config = 'small_small_hr.apps.SmallSmallHrConfig' # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
small_small_hr/templates/small_small_hr/email/leave_application_email_body.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Hello {{name}},<br/><br/> | ||
{{message|linebreaks}} | ||
<br/><br/> | ||
Thank you,<br/> | ||
{{SITE.name}}<br/> | ||
------<br/> | ||
http://{{SITE.domain}} |
9 changes: 9 additions & 0 deletions
9
small_small_hr/templates/small_small_hr/email/leave_application_email_body.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Hello {{name}}, | ||
|
||
{{message}} | ||
|
||
Thank you, | ||
|
||
{{SITE.name}} | ||
------ | ||
http://{{SITE.domain}} |
1 change: 1 addition & 0 deletions
1
small_small_hr/templates/small_small_hr/email/leave_application_email_subject.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{subject}} |
7 changes: 7 additions & 0 deletions
7
small_small_hr/templates/small_small_hr/email/overtime_application_email_body.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Hello {{name}},<br/><br/> | ||
{{message|linebreaks}} | ||
<br/><br/> | ||
Thank you,<br/> | ||
{{SITE.name}}<br/> | ||
------<br/> | ||
http://{{SITE.domain}} |
9 changes: 9 additions & 0 deletions
9
small_small_hr/templates/small_small_hr/email/overtime_application_email_body.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Hello {{name}}, | ||
|
||
{{message}} | ||
|
||
Thank you, | ||
|
||
{{SITE.name}} | ||
------ | ||
http://{{SITE.domain}} |
1 change: 1 addition & 0 deletions
1
small_small_hr/templates/small_small_hr/email/overtime_application_email_subject.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{subject}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
Module to test small_small_hr Emails | ||
""" | ||
from datetime import datetime | ||
from unittest.mock import patch | ||
from unittest.mock import call, patch | ||
|
||
from django.conf import settings | ||
from django.core import mail | ||
|
@@ -59,7 +59,8 @@ def test_leave_application_email(self, mock): | |
email="[email protected]", | ||
subject="New Leave Application", | ||
message="There has been a new leave application. Please log in to process it.", # noqa | ||
obj=leave | ||
obj=leave, | ||
template="leave_application", | ||
) | ||
|
||
@patch('small_small_hr.emails.send_email') | ||
|
@@ -107,7 +108,8 @@ def test_overtime_application_email(self, mock): | |
email="[email protected]", | ||
subject="New Overtime Application", | ||
message="There has been a new overtime application. Please log in to process it.", # noqa | ||
obj=overtime | ||
obj=overtime, | ||
template="overtime_application", | ||
) | ||
|
||
@patch('small_small_hr.emails.send_email') | ||
|
@@ -163,3 +165,121 @@ def test_send_email(self): | |
mail.outbox[0].alternatives[0][0], | ||
'Hello Bob Munro,<br/><br/><p>The quick brown fox.</p><br/><br/>' | ||
'Thank you,<br/>example.com<br/>------<br/>http://example.com') | ||
|
||
@patch('small_small_hr.emails.Site.objects.get_current') | ||
@patch('small_small_hr.emails.render_to_string') | ||
def test_send_email_templates(self, mock, site_mock): | ||
""" | ||
Test the templates used with send_email | ||
""" | ||
mock.return_value = "Some random text" | ||
site_mock.return_value = 42 # ensure that this is predictable | ||
|
||
# test generic | ||
data = { | ||
'name': 'Bob Munro', | ||
'email': '[email protected]', | ||
'subject': "I love oov", | ||
'message': "Its dangerous", | ||
} | ||
|
||
send_email(**data) | ||
|
||
context = data.copy() | ||
context.pop("email") | ||
context["object"] = None | ||
context["SITE"] = 42 | ||
|
||
expected_calls = [ | ||
call( | ||
"small_small_hr/email/generic_email_subject.txt", | ||
context | ||
), | ||
call( | ||
"small_small_hr/email/generic_email_body.txt", | ||
context | ||
), | ||
call( | ||
"small_small_hr/email/generic_email_body.html", | ||
context | ||
) | ||
] | ||
|
||
mock.assert_has_calls(expected_calls) | ||
|
||
mock.reset_mock() | ||
|
||
# test leave | ||
start = datetime( | ||
2017, 6, 5, 0, 0, 0, tzinfo=pytz.timezone(settings.TIME_ZONE)) | ||
end = datetime( | ||
2017, 6, 10, 0, 0, 0, tzinfo=pytz.timezone(settings.TIME_ZONE)) | ||
leave = mommy.make( | ||
'small_small_hr.Leave', staff=self.staffprofile, start=start, | ||
end=end, leave_type=Leave.SICK, | ||
status=Leave.PENDING) | ||
|
||
leave_application_email(leave) | ||
|
||
context = dict( | ||
name="Bob Ndoe", | ||
subject="New Leave Application", | ||
message="There has been a new leave application. Please log in to process it.", # noqa | ||
object=leave, | ||
SITE=42 | ||
) | ||
|
||
expected_calls = [ | ||
call( | ||
"small_small_hr/email/leave_application_email_subject.txt", | ||
context | ||
), | ||
call( | ||
"small_small_hr/email/leave_application_email_body.txt", | ||
context | ||
), | ||
call( | ||
"small_small_hr/email/leave_application_email_body.html", | ||
context | ||
) | ||
] | ||
|
||
mock.assert_has_calls(expected_calls) | ||
|
||
mock.reset_mock() | ||
|
||
# test overtime | ||
start = datetime( | ||
2017, 6, 5, 0, 0, 0, tzinfo=pytz.timezone(settings.TIME_ZONE)) | ||
end = datetime( | ||
2017, 6, 10, 0, 0, 0, tzinfo=pytz.timezone(settings.TIME_ZONE)) | ||
overtime = mommy.make( | ||
'small_small_hr.OverTime', staff=self.staffprofile, start=start, | ||
end=end, status=OverTime.PENDING) | ||
|
||
overtime_application_email(overtime) | ||
|
||
context = dict( | ||
name="Bob Ndoe", | ||
subject="New Overtime Application", | ||
message="There has been a new overtime application. Please log in to process it.", # noqa | ||
object=overtime, | ||
SITE=42 | ||
) | ||
|
||
expected_calls = [ | ||
call( | ||
"small_small_hr/email/overtime_application_email_subject.txt", | ||
context | ||
), | ||
call( | ||
"small_small_hr/email/overtime_application_email_body.txt", | ||
context | ||
), | ||
call( | ||
"small_small_hr/email/overtime_application_email_body.html", | ||
context | ||
) | ||
] | ||
|
||
mock.assert_has_calls(expected_calls) |
Oops, something went wrong.