Skip to content

Commit 3bcf55e

Browse files
committed
Added new tests
1 parent df07a19 commit 3bcf55e

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

appointment/templates/appointment/thank_you.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{% load static %}
44
{% block customCSS %}
55
<style>
6-
/* Add your custom CSS here */
76
body {
87
font-family: 'Nunito', sans-serif;
98
background-color: #f7f7f7;

appointment/tests/test_services.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import datetime
55
import json
66
from _decimal import Decimal
7+
from unittest.mock import patch
78

89
from django.core.cache import cache
910
from django.test import Client
@@ -637,6 +638,21 @@ def test_email_already_exists(self):
637638
self.assertIsNone(user)
638639
self.assertEqual(error_message, "email: This email is already taken.")
639640

641+
@patch('appointment.services.send_reset_link_to_staff_member')
642+
def test_send_reset_link_to_new_staff_member(self, mock_send_reset_link):
643+
"""Test if a reset password link is sent to a new staff member."""
644+
post_data = {
645+
'first_name': 'Jane',
646+
'last_name': 'Smith',
647+
'email': '[email protected]'
648+
}
649+
user, success, _ = create_staff_member_service(post_data, self.request)
650+
self.assertTrue(success)
651+
self.assertIsNotNone(user)
652+
653+
# Check that the mock_send_reset_link function was called once
654+
mock_send_reset_link.assert_called_once_with(user, self.request, user.email)
655+
640656

641657
class HandleServiceManagementRequestTest(BaseTest):
642658

appointment/tests/utils/test_email_ops.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from unittest import mock
22
from unittest.mock import MagicMock, patch
33

4-
from django.test import TestCase
54
from django.test.client import RequestFactory
65
from django.utils import timezone
76
from django.utils.translation import gettext as _
@@ -10,12 +9,48 @@
109
from appointment.models import AppointmentRescheduleHistory
1110
from appointment.tests.base.base_test import BaseTest
1211
from appointment.utils.email_ops import (
13-
get_thank_you_message, notify_admin_about_appointment, send_reschedule_confirmation_email, send_thank_you_email,
12+
get_thank_you_message, notify_admin_about_appointment, send_reschedule_confirmation_email,
13+
send_reset_link_to_staff_member, send_thank_you_email,
1414
send_verification_email
1515
)
1616

1717

18-
class GetThankYouMessageTests(TestCase):
18+
class SendResetLinkToStaffMemberTests(BaseTest):
19+
20+
def setUp(self):
21+
super().setUp()
22+
self.user = self.user1
23+
self.user.is_staff = True
24+
self.user.save()
25+
self.factory = RequestFactory()
26+
self.request = self.factory.get('/')
27+
self.email = '[email protected]'
28+
29+
@mock.patch('appointment.utils.email_ops.send_email')
30+
@mock.patch('appointment.models.PasswordResetToken.create_token')
31+
def test_send_reset_link(self, mock_create_token, mock_send_email):
32+
# Setup the token
33+
mock_token = mock.Mock()
34+
mock_token.token = 'token123'
35+
mock_create_token.return_value = mock_token
36+
37+
# Assume get_absolute_url_ and get_website_name are utility functions you've defined somewhere
38+
with mock.patch('appointment.utils.email_ops.get_absolute_url_') as mock_get_absolute_url:
39+
with mock.patch('appointment.utils.email_ops.get_website_name') as mock_get_website_name:
40+
mock_get_absolute_url.return_value = 'http://testserver/reset_password'
41+
mock_get_website_name.return_value = 'TestCompany'
42+
43+
send_reset_link_to_staff_member(self.user, self.request, self.email)
44+
45+
# Check send_email was called with correct parameters
46+
mock_send_email.assert_called_once()
47+
args, kwargs = mock_send_email.call_args
48+
self.assertEqual(kwargs['recipient_list'], [self.email])
49+
self.assertIn('TestCompany', kwargs['message'])
50+
self.assertIn('http://testserver/reset_password', kwargs['message'])
51+
52+
53+
class GetThankYouMessageTests(BaseTest):
1954
def test_thank_you_no_payment(self):
2055
with patch('appointment.utils.email_ops.APPOINTMENT_PAYMENT_URL', None):
2156
ar = MagicMock()

0 commit comments

Comments
 (0)