Skip to content

Commit f0f5b3f

Browse files
committed
Added & optimized existing tests
1 parent c9efcbc commit f0f5b3f

12 files changed

+98
-37
lines changed

appointment/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ def check_q_cluster():
6565
for warning in missing_conf:
6666
logger.warning(warning)
6767
return False
68-
68+
print(f"Mising conf: {missing_conf}")
6969
# Both 'django_q' is installed and 'Q_CLUSTER' is configured
7070
return True

appointment/tests/test_availability_slot.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# test_availability_slot.py
2+
# Path: appointment/tests/test_availability_slot.py
3+
14
from datetime import date, time, timedelta
25

36
from django.test import TestCase

appointment/tests/test_services.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# test_services.py
2+
# Path: appointment/tests/test_services.py
3+
14
import datetime
25
import json
36
from _decimal import Decimal

appointment/tests/test_settings.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# test_settings.py
2+
# Path: appointment/tests/test_settings.py
3+
4+
from unittest.mock import patch
5+
6+
from django.test import TestCase
7+
8+
from appointment.settings import check_q_cluster
9+
10+
11+
class CheckQClusterTest(TestCase):
12+
@patch('appointment.settings.settings')
13+
@patch('appointment.settings.logger')
14+
def test_check_q_cluster_with_django_q_missing(self, mock_logger, mock_settings):
15+
# Simulate 'django_q' not being in INSTALLED_APPS
16+
mock_settings.INSTALLED_APPS = []
17+
18+
# Call the function under test
19+
result = check_q_cluster()
20+
21+
# Check the result
22+
self.assertFalse(result)
23+
# Verify logger was called with the expected warning about 'django_q' not being installed
24+
mock_logger.warning.assert_called_with(
25+
"Django Q is not in settings.INSTALLED_APPS. Please add it to the list.\n"
26+
"Example: \n\n"
27+
"INSTALLED_APPS = [\n"
28+
" ...\n"
29+
" 'appointment',\n"
30+
" 'django_q',\n"
31+
"]\n")
32+
33+
@patch('appointment.settings.settings')
34+
@patch('appointment.settings.logger')
35+
def test_check_q_cluster_with_all_configurations_present(self, mock_logger, mock_settings):
36+
# Simulate both 'django_q' being in INSTALLED_APPS and 'Q_CLUSTER' configuration present
37+
mock_settings.INSTALLED_APPS = ['django_q']
38+
mock_settings.Q_CLUSTER = {'name': 'DjangORM'}
39+
40+
# Call the function under test
41+
result = check_q_cluster()
42+
43+
# Check the result and ensure no warnings are logged
44+
self.assertTrue(result)
45+
mock_logger.warning.assert_not_called()

appointment/tests/test_tasks.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
from django.test import TestCase
1+
# test_tasks.py
2+
# Path: appointment/tests/test_tasks.py
3+
24
from unittest.mock import patch
5+
6+
from django.utils.translation import gettext as _
7+
38
from appointment.tasks import send_email_reminder
49
from appointment.tests.base.base_test import BaseTest
5-
from django.utils.translation import gettext as _
610

711

812
class SendEmailReminderTest(BaseTest):

appointment/tests/test_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# test_utils.py
2+
# Path: appointment/tests/test_utils.py
3+
14
import datetime
25
import logging
36
from unittest.mock import patch

appointment/tests/test_views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# test_views.py
2+
# Path: appointment/tests/test_views.py
3+
14
import datetime
25
import json
36
from datetime import date, time, timedelta

appointment/tests/utils/test_date_time.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
# test_date_time.py
2+
# Path: appointment/tests/utils/test_date_time.py
3+
14
import datetime
25
from unittest.mock import Mock, patch
36

47
from django.test import TestCase
58

69
from appointment.settings import APP_TIME_ZONE
7-
from appointment.utils.date_time import convert_12_hour_time_to_24_hour_time, \
8-
convert_str_to_date, convert_str_to_time, get_ar_end_time, time_difference, get_timezone, get_current_year, \
9-
get_weekday_num, get_timestamp, convert_minutes_in_human_readable_format
10+
from appointment.utils.date_time import convert_12_hour_time_to_24_hour_time, convert_minutes_in_human_readable_format, \
11+
convert_str_to_date, convert_str_to_time, get_ar_end_time, get_current_year, get_timestamp, get_timezone, \
12+
get_weekday_num, time_difference
1013

1114

1215
class Convert12HourTo24HourTimeTests(TestCase):

appointment/tests/utils/test_db_helpers.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
# Path: appointment/tests/utils/test_db_helpers.py
33

44
import datetime
5-
from unittest.mock import patch, ANY
5+
from unittest.mock import patch
66

77
from django.apps import apps
88
from django.conf import settings
9-
from django.contrib.auth.hashers import make_password
109
from django.core.cache import cache
11-
from django.core.exceptions import FieldDoesNotExist
1210
from django.test import TestCase
1311
from django.urls import reverse
1412
from django.utils import timezone
@@ -17,27 +15,22 @@
1715
from appointment.models import DayOff, PaymentInfo
1816
from appointment.tests.base.base_test import BaseTest
1917
from appointment.utils.date_time import get_current_year
20-
from appointment.utils.db_helpers import (calculate_slots, cancel_existing_reminder, check_day_off_for_staff,
21-
create_and_save_appointment,
22-
create_payment_info_and_get_url, exclude_booked_slots,
23-
day_off_exists_for_date_range, get_all_staff_members,
24-
get_all_appointments, Config, get_appointment_buffer_time,
25-
get_appointment_by_id, get_appointment_finish_time,
26-
get_appointment_lead_time, get_appointment_slot_duration,
27-
get_appointments_for_date_and_time, get_config,
28-
get_day_off_by_id, WorkingHours, get_non_working_days_for_staff,
29-
get_staff_member_appointment_list,
30-
get_weekday_num_from_date, get_staff_member_start_time,
31-
get_staff_member_end_time, get_staff_member_buffer_time,
32-
get_staff_member_slot_duration, get_user_by_email, get_user_model,
33-
get_staff_member_from_user_id_or_logged_in,
34-
get_staff_member_by_user_id, schedule_email_reminder,
35-
update_appointment_reminder, working_hours_exist,
36-
is_working_day,
37-
get_working_hours_for_staff_and_day,
38-
get_working_hours_by_id, get_website_name, get_times_from_config,
39-
create_new_user, generate_unique_username_from_email, parse_name,
40-
create_user_with_email, create_user_with_username)
18+
from appointment.utils.db_helpers import (Config, WorkingHours, calculate_slots, cancel_existing_reminder,
19+
check_day_off_for_staff, create_and_save_appointment, create_new_user,
20+
create_payment_info_and_get_url, day_off_exists_for_date_range,
21+
exclude_booked_slots, generate_unique_username_from_email,
22+
get_all_appointments, get_all_staff_members, get_appointment_buffer_time,
23+
get_appointment_by_id, get_appointment_finish_time, get_appointment_lead_time,
24+
get_appointment_slot_duration, get_appointments_for_date_and_time, get_config,
25+
get_day_off_by_id, get_non_working_days_for_staff,
26+
get_staff_member_appointment_list, get_staff_member_buffer_time,
27+
get_staff_member_by_user_id, get_staff_member_end_time,
28+
get_staff_member_from_user_id_or_logged_in, get_staff_member_slot_duration,
29+
get_staff_member_start_time, get_times_from_config, get_user_by_email,
30+
get_user_model, get_website_name, get_weekday_num_from_date,
31+
get_working_hours_by_id, get_working_hours_for_staff_and_day, is_working_day,
32+
parse_name, schedule_email_reminder, update_appointment_reminder,
33+
working_hours_exist)
4134

4235

4336
class TestCalculateSlots(TestCase):

appointment/tests/utils/test_json_context.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1+
# test_json_context.py
2+
# Path: appointment/tests/utils/test_json_context.py
3+
14
import json
25

36
from django.test import RequestFactory
47

58
from appointment.tests.base.base_test import BaseTest
6-
from appointment.utils.json_context import (
7-
convert_appointment_to_json,
8-
json_response,
9-
get_generic_context,
10-
get_generic_context_with_extra,
11-
handle_unauthorized_response
12-
)
9+
from appointment.utils.json_context import (convert_appointment_to_json, get_generic_context,
10+
get_generic_context_with_extra, handle_unauthorized_response, json_response)
1311

1412

1513
class JsonContextTests(BaseTest):

0 commit comments

Comments
 (0)