From 8cab446f69e40b68c68f332afd53875ed252f694 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Wed, 23 Apr 2025 13:50:22 -0400 Subject: [PATCH] test: Make pytz api related tests more resilient. Compare the output of our API with the library that backs them so that we don't have brittle tests that need to be updated when the number of timezones changes. --- .../djangoapps/user_api/tests/test_views.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/openedx/core/djangoapps/user_api/tests/test_views.py b/openedx/core/djangoapps/user_api/tests/test_views.py index 75740cf5d2..446ade442c 100644 --- a/openedx/core/djangoapps/user_api/tests/test_views.py +++ b/openedx/core/djangoapps/user_api/tests/test_views.py @@ -5,7 +5,7 @@ import ddt from django.test.utils import override_settings from django.urls import reverse from opaque_keys.edx.keys import CourseKey -from pytz import common_timezones_set +from pytz import common_timezones_set, common_timezones, country_timezones from openedx.core.djangoapps.django_comment_common import models from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms @@ -634,13 +634,16 @@ class CountryTimeZoneListViewTest(UserApiTestCase): assert time_zone_name in common_timezones_set assert time_zone_info['description'] == get_display_time_zone(time_zone_name) - # The time zones count may need to change each time we upgrade pytz - @ddt.data((ALL_TIME_ZONES_URI, 432), - (COUNTRY_TIME_ZONES_URI, 23)) - @ddt.unpack - def test_get_basic(self, country_uri, expected_count): + def test_get_country_timezones(self): """ Verify that correct time zone info is returned """ - results = self.get_json(country_uri) - assert len(results) == expected_count + results = self.get_json(self.COUNTRY_TIME_ZONES_URI) + assert len(results) == len(country_timezones['cA']) + for time_zone_info in results: + self._assert_time_zone_is_valid(time_zone_info) + + def test_get_all_common_timezones(self): + """ Verify that correct time zone info is returned """ + results = self.get_json(self.ALL_TIME_ZONES_URI) + assert len(results) == len(common_timezones) for time_zone_info in results: self._assert_time_zone_is_valid(time_zone_info)