Skip to content

Commit

Permalink
An email will be sent to the user with a notice about the pet registr…
Browse files Browse the repository at this point in the history
…ation deactivation
  • Loading branch information
dirtycoder committed Feb 17, 2017
1 parent b206811 commit c508f77
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pets/meupet/models.py
Expand Up @@ -180,6 +180,9 @@ def activate(self):
self.save()

def deactivate(self):
if not services.send_deactivate_email(self):
return

self.active = False
self.save(update_modified=False)

Expand Down
14 changes: 14 additions & 0 deletions pets/meupet/services.py
Expand Up @@ -34,3 +34,17 @@ def send_request_action_email(pet):
}

return send_email(subject, to, template_name, context)


def send_deactivate_email(pet):
subject = _('Deactivation of pet registration')
to = pet.owner.email
template_name = 'meupet/deactivate_email.txt'
current_site = Site.objects.get_current()

context = {
'username': pet.owner.first_name,
'site_name': current_site.name,
}

return send_email(subject, to, template_name, context)
8 changes: 8 additions & 0 deletions pets/meupet/templates/meupet/deactivate_email.txt
@@ -0,0 +1,8 @@
{% load i18n %}{% blocktrans %}Hello, {{ username }}.{% endblocktrans %}

{% blocktrans %}Your pet registration didn't received any updates in the last few months, so it's been deactivated.{% endblocktrans %}

{% blocktrans %}You can make a new registration if necessary.{% endblocktrans %}

{% trans "Best regards," %}
{{ site_name }}
10 changes: 10 additions & 0 deletions pets/meupet/tests/test_model_pet.py
Expand Up @@ -69,6 +69,16 @@ def test_request_action_from_user(self, mock_send_email):

mock_send_email.assert_called_once_with(pet)

@patch('meupet.services.send_deactivate_email')
def test_deactivate_send_email(self, mock_send_email):
"""
Deactivate should call the send_deactivate_email method
"""
pet = mommy.make(Pet)
pet.deactivate()

mock_send_email.assert_called_once_with(pet)

def test_request_sent_saved(self):
"""Should set the request_sent date in the pet and keep modified date"""
pet = mommy.make(Pet)
Expand Down
22 changes: 21 additions & 1 deletion pets/meupet/tests/test_services.py
Expand Up @@ -11,7 +11,9 @@

class ServicesTest(TestCase):
def test_request_action_from_user(self):
"""Validate the information sent in the email"""
"""
Validate the information sent in the email
"""
pet = mommy.make(Pet)
pet.request_action()
email = mail.outbox[0]
Expand All @@ -32,3 +34,21 @@ def test_request_action_from_user(self):
for expected in contents:
with self.subTest():
self.assertIn(expected, email.body)

def test_pet_deactivated(self):
"""
Validates the information present in the email
"""
pet = mommy.make(Pet)
pet.deactivate()
email = mail.outbox[0]
current_site = Site.objects.get_current()

contents = [
pet.owner.first_name,
current_site.name,
]

for expected in contents:
with self.subTest():
self.assertIn(expected, email.body)

0 comments on commit c508f77

Please sign in to comment.