Skip to content

Commit 8cab446

Browse files
committed
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.
1 parent e174ab4 commit 8cab446

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

openedx/core/djangoapps/user_api/tests/test_views.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from django.test.utils import override_settings
66
from django.urls import reverse
77
from opaque_keys.edx.keys import CourseKey
8-
from pytz import common_timezones_set
8+
from pytz import common_timezones_set, common_timezones, country_timezones
99

1010
from openedx.core.djangoapps.django_comment_common import models
1111
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms
@@ -634,13 +634,16 @@ def _assert_time_zone_is_valid(self, time_zone_info):
634634
assert time_zone_name in common_timezones_set
635635
assert time_zone_info['description'] == get_display_time_zone(time_zone_name)
636636

637-
# The time zones count may need to change each time we upgrade pytz
638-
@ddt.data((ALL_TIME_ZONES_URI, 432),
639-
(COUNTRY_TIME_ZONES_URI, 23))
640-
@ddt.unpack
641-
def test_get_basic(self, country_uri, expected_count):
637+
def test_get_country_timezones(self):
638+
""" Verify that correct time zone info is returned """
639+
results = self.get_json(self.COUNTRY_TIME_ZONES_URI)
640+
assert len(results) == len(country_timezones['cA'])
641+
for time_zone_info in results:
642+
self._assert_time_zone_is_valid(time_zone_info)
643+
644+
def test_get_all_common_timezones(self):
642645
""" Verify that correct time zone info is returned """
643-
results = self.get_json(country_uri)
644-
assert len(results) == expected_count
646+
results = self.get_json(self.ALL_TIME_ZONES_URI)
647+
assert len(results) == len(common_timezones)
645648
for time_zone_info in results:
646649
self._assert_time_zone_is_valid(time_zone_info)

0 commit comments

Comments
 (0)