Skip to content
Snippets Groups Projects
Commit 4f9fe597 authored by Feanil Patel's avatar Feanil Patel
Browse files

test: Fix date tests that rely on user preference.

The function under test by the StrftimeLocalizedHtmlTest checks the
timezone in the user preferences of the user making the request.  If we
don't explicitly set a request here, it will simply use the last Request
that `crum` cached in the thread local cache.  This broke now
that we sometimes set the crum request.user to an invalid user in other
tests.

This change ensures that we have a valid request for these tests as a
part of the setup of this test class.
parent c2eabf6c
No related branches found
No related tags found
No related merge requests found
......@@ -6,11 +6,14 @@ import unittest
from datetime import datetime, timedelta, tzinfo
from unittest.mock import patch
import crum
import ddt
import pytest
from markupsafe import Markup
from pytz import utc
from django.test.client import RequestFactory
from common.djangoapps.util.date_utils import (
almost_same_datetime, get_default_time_display, get_time_display, strftime_localized, strftime_localized_html
)
......@@ -217,6 +220,12 @@ class StrftimeLocalizedHtmlTest(unittest.TestCase):
"""
Tests for strftime_localized_html.
"""
def setUp(self):
super().setUp()
request = RequestFactory().request()
self.addCleanup(crum.set_current_request, None)
crum.set_current_request(request)
@ddt.data(
None,
'Africa/Casablanca',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment