Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BTR-39] Cherry-pick warning squash commits #25714

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@

# A newer and safer request cache.
'edx_django_utils.cache.middleware.RequestCacheMiddleware',
'edx_django_utils.monitoring.middleware.MonitoringMemoryMiddleware',
'edx_django_utils.monitoring.MonitoringMemoryMiddleware',

# Cookie monitoring
'openedx.core.lib.request_utils.CookieMonitoringMiddleware',
Expand Down
5 changes: 3 additions & 2 deletions common/lib/xmodule/xmodule/modulestore/tests/django_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from django.conf import settings
from django.contrib.auth.models import AnonymousUser, User
from django.db import connections
from django.test import TestCase
from django.test.utils import override_settings
from mock import patch
Expand Down Expand Up @@ -397,7 +398,7 @@ def setUp(self):
for Django ORM models that will get cleaned up properly.
"""
# Tell Django to clean out all databases, not just default
multi_db = True
databases = {alias for alias in connections}

@classmethod
@contextmanager
Expand Down Expand Up @@ -486,7 +487,7 @@ class FooTest(ModuleStoreTestCase):
CREATE_USER = True

# Tell Django to clean out all databases, not just default
multi_db = True
databases = {alias for alias in connections}

@classmethod
def setUpClass(cls):
Expand Down
6 changes: 3 additions & 3 deletions common/lib/xmodule/xmodule/video_module/transcripts_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


import copy
import html
import logging
import os
from functools import wraps
Expand All @@ -19,7 +20,6 @@
from pysrt.srtexc import Error
from six import text_type
from six.moves import range, zip
from six.moves.html_parser import HTMLParser

from openedx.core.djangolib import blockstore_cache
from openedx.core.lib import blockstore_api
Expand Down Expand Up @@ -660,7 +660,7 @@ def convert(content, input_format, output_format):

if output_format == 'txt':
text = SubRipFile.from_string(content.decode('utf-8')).text
return HTMLParser().unescape(text)
return html.unescape(text)

elif output_format == 'sjson':
try:
Expand All @@ -679,7 +679,7 @@ def convert(content, input_format, output_format):
if output_format == 'txt':
text = json.loads(content)['text']
text_without_none = [line if line else '' for line in text]
return HTMLParser().unescape("\n".join(text_without_none))
return html.unescape("\n".join(text_without_none))

elif output_format == 'srt':
return generate_srt_from_sjson(json.loads(content), speed=1.0)
Expand Down
3 changes: 2 additions & 1 deletion lms/djangoapps/ccx/tests/test_field_override_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.conf import settings
from django.contrib.messages.storage.fallback import FallbackStorage
from django.core.cache import caches
from django.db import connections
from django.test.client import RequestFactory
from django.test.utils import override_settings
from edx_django_utils.cache import RequestCache
Expand Down Expand Up @@ -57,7 +58,7 @@ class FieldOverridePerformanceTestCase(FieldOverrideTestMixin, ProceduralCourseT
"""
__test__ = False
# Tell Django to clean out all databases, not just default
multi_db = True
databases = {alias for alias in connections}

# TEST_DATA must be overridden by subclasses
TEST_DATA = None
Expand Down
6 changes: 3 additions & 3 deletions lms/djangoapps/courseware/tests/test_model_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import json
from functools import partial

from django.db import DatabaseError
from django.db import connections, DatabaseError
from django.test import TestCase
from mock import Mock, patch
from xblock.core import XBlock
Expand Down Expand Up @@ -105,7 +105,7 @@ class TestStudentModuleStorage(OtherUserFailureTestMixin, TestCase):
other_key_factory = partial(DjangoKeyValueStore.Key, Scope.user_state, 2, location('usage_id')) # user_id=2, not 1
existing_field_name = "a_field"
# Tell Django to clean out all databases, not just default
multi_db = True
databases = {alias for alias in connections}

def setUp(self):
super(TestStudentModuleStorage, self).setUp()
Expand Down Expand Up @@ -230,7 +230,7 @@ def test_set_many_failure(self):

class TestMissingStudentModule(TestCase):
# Tell Django to clean out all databases, not just default
multi_db = True
databases = {alias for alias in connections}

def setUp(self):
super(TestMissingStudentModule, self).setUp()
Expand Down
9 changes: 5 additions & 4 deletions lms/djangoapps/courseware/tests/test_submitting_problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import six
from django.conf import settings
from django.contrib.auth.models import User
from django.db import connections
from django.test import TestCase
from django.test.client import RequestFactory
from django.urls import reverse
Expand Down Expand Up @@ -139,7 +140,7 @@ class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase, Probl
"""

# Tell Django to clean out all databases, not just default
multi_db = True
databases = {alias for alias in connections}
# arbitrary constant
COURSE_SLUG = "100"
COURSE_NAME = "test_course"
Expand Down Expand Up @@ -342,7 +343,7 @@ class TestCourseGrader(TestSubmittingProblems):
Suite of tests for the course grader.
"""
# Tell Django to clean out all databases, not just default
multi_db = True
databases = {alias for alias in connections}

def basic_setup(self, late=False, reset=False, showanswer=False):
"""
Expand Down Expand Up @@ -755,7 +756,7 @@ def test_min_grade_credit_requirements_status(self, mode):
class ProblemWithUploadedFilesTest(TestSubmittingProblems):
"""Tests of problems with uploaded files."""
# Tell Django to clean out all databases, not just default
multi_db = True
databases = {alias for alias in connections}

def setUp(self):
super(ProblemWithUploadedFilesTest, self).setUp()
Expand Down Expand Up @@ -811,7 +812,7 @@ class TestPythonGradedResponse(TestSubmittingProblems):
Check that we can submit a schematic and custom response, and it answers properly.
"""
# Tell Django to clean out all databases, not just default
multi_db = True
databases = {alias for alias in connections}

SCHEMATIC_SCRIPT = dedent("""
# for a schematic response, submission[i] is the json representation
Expand Down
4 changes: 3 additions & 1 deletion lms/djangoapps/courseware/tests/test_user_state_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from collections import defaultdict

from django.db import connections

from edx_user_state_client.tests import UserStateClientTestBase

from lms.djangoapps.courseware.tests.factories import UserFactory
Expand All @@ -20,7 +22,7 @@ class TestDjangoUserStateClient(UserStateClientTestBase, ModuleStoreTestCase):
"""
__test__ = True
# Tell Django to clean out all databases, not just default
multi_db = True
databases = {alias for alias in connections}

def _user(self, user_idx):
return self.users[user_idx].username
Expand Down
3 changes: 2 additions & 1 deletion lms/djangoapps/coursewarehistoryextended/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from unittest import skipUnless

from django.conf import settings
from django.db import connections
from django.test import TestCase
from mock import patch

Expand All @@ -21,7 +22,7 @@
class TestStudentModuleHistoryBackends(TestCase):
""" Tests of data in CSMH and CSMHE """
# Tell Django to clean out all databases, not just default
multi_db = True
databases = {alias for alias in connections}

def setUp(self):
super(TestStudentModuleHistoryBackends, self).setUp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from common.test.utils import MockS3BotoMixin
from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification
from lms.djangoapps.verify_student.tests.test_models import FAKE_SETTINGS, mock_software_secure_post
from student.tests.factories import UserFactory
from common.djangoapps.student.tests.factories import UserFactory

LOGGER_NAME = 'lms.djangoapps.verify_student.management.commands.populate_expiration_date'

Expand Down
4 changes: 2 additions & 2 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1686,10 +1686,10 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring

# A newer and safer request cache.
'edx_django_utils.cache.middleware.RequestCacheMiddleware',
'edx_django_utils.monitoring.middleware.CachedCustomMonitoringMiddleware',
'edx_django_utils.monitoring.CachedCustomMonitoringMiddleware',

# Generate code ownership attributes. Keep this immediately after RequestCacheMiddleware.
'edx_django_utils.monitoring.code_owner.middleware.CodeOwnerMonitoringMiddleware',
'edx_django_utils.monitoring.CodeOwnerMonitoringMiddleware',

# Cookie monitoring
'openedx.core.lib.request_utils.CookieMonitoringMiddleware',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json

from completion.test_utils import CompletionWaffleTestMixin
from django.db import connections
from django.test import TestCase, override_settings
from organizations.models import Organization
from rest_framework.test import APIClient
Expand Down Expand Up @@ -183,7 +184,7 @@ class ContentLibraryXBlockUserStateTest(ContentLibraryContentTestMixin, TestCase
if the library allows direct learning.
"""

multi_db = True
databases = {alias for alias in connections}

@XBlock.register_temp_plugin(UserStateTestBlock, UserStateTestBlock.BLOCK_TYPE)
def test_default_values(self):
Expand Down
28 changes: 14 additions & 14 deletions openedx/features/course_duration_limits/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,13 @@ def test_config_overrides(self, global_setting, site_setting, org_setting, cours
def test_all_current_course_configs(self):
# Set up test objects
for global_setting in (True, False, None):
CourseDurationLimitConfig.objects.create(enabled=global_setting, enabled_as_of=datetime(2018, 1, 1))
CourseDurationLimitConfig.objects.create(enabled=global_setting, enabled_as_of=datetime(2018, 1, 1, tzinfo=pytz.UTC))
for site_setting in (True, False, None):
test_site_cfg = SiteConfigurationFactory.create(
site_values={'course_org_filter': []}
)
CourseDurationLimitConfig.objects.create(
site=test_site_cfg.site, enabled=site_setting, enabled_as_of=datetime(2018, 1, 1)
site=test_site_cfg.site, enabled=site_setting, enabled_as_of=datetime(2018, 1, 1, tzinfo=pytz.UTC)
)

for org_setting in (True, False, None):
Expand All @@ -197,7 +197,7 @@ def test_all_current_course_configs(self):
test_site_cfg.save()

CourseDurationLimitConfig.objects.create(
org=test_org, enabled=org_setting, enabled_as_of=datetime(2018, 1, 1)
org=test_org, enabled=org_setting, enabled_as_of=datetime(2018, 1, 1, tzinfo=pytz.UTC)
)

for course_setting in (True, False, None):
Expand All @@ -206,7 +206,7 @@ def test_all_current_course_configs(self):
id=CourseLocator(test_org, 'test_course', 'run-{}'.format(course_setting))
)
CourseDurationLimitConfig.objects.create(
course=test_course, enabled=course_setting, enabled_as_of=datetime(2018, 1, 1)
course=test_course, enabled=course_setting, enabled_as_of=datetime(2018, 1, 1, tzinfo=pytz.UTC)
)

with self.assertNumQueries(4):
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_all_current_course_configs(self):
)

def test_caching_global(self):
global_config = CourseDurationLimitConfig(enabled=True, enabled_as_of=datetime(2018, 1, 1))
global_config = CourseDurationLimitConfig(enabled=True, enabled_as_of=datetime(2018, 1, 1, tzinfo=pytz.UTC))
global_config.save()

RequestCache.clear_all_namespaces()
Expand All @@ -267,7 +267,7 @@ def test_caching_global(self):

def test_caching_site(self):
site_cfg = SiteConfigurationFactory()
site_config = CourseDurationLimitConfig(site=site_cfg.site, enabled=True, enabled_as_of=datetime(2018, 1, 1))
site_config = CourseDurationLimitConfig(site=site_cfg.site, enabled=True, enabled_as_of=datetime(2018, 1, 1, tzinfo=pytz.UTC))
site_config.save()

RequestCache.clear_all_namespaces()
Expand All @@ -291,7 +291,7 @@ def test_caching_site(self):
with self.assertNumQueries(1):
self.assertFalse(CourseDurationLimitConfig.current(site=site_cfg.site).enabled)

global_config = CourseDurationLimitConfig(enabled=True, enabled_as_of=datetime(2018, 1, 1))
global_config = CourseDurationLimitConfig(enabled=True, enabled_as_of=datetime(2018, 1, 1, tzinfo=pytz.UTC))
global_config.save()

RequestCache.clear_all_namespaces()
Expand All @@ -305,7 +305,7 @@ def test_caching_org(self):
site_cfg = SiteConfigurationFactory.create(
site_values={'course_org_filter': course.org}
)
org_config = CourseDurationLimitConfig(org=course.org, enabled=True, enabled_as_of=datetime(2018, 1, 1))
org_config = CourseDurationLimitConfig(org=course.org, enabled=True, enabled_as_of=datetime(2018, 1, 1, tzinfo=pytz.UTC))
org_config.save()

RequestCache.clear_all_namespaces()
Expand All @@ -329,7 +329,7 @@ def test_caching_org(self):
with self.assertNumQueries(2):
self.assertFalse(CourseDurationLimitConfig.current(org=course.org).enabled)

global_config = CourseDurationLimitConfig(enabled=True, enabled_as_of=datetime(2018, 1, 1))
global_config = CourseDurationLimitConfig(enabled=True, enabled_as_of=datetime(2018, 1, 1, tzinfo=pytz.UTC))
global_config.save()

RequestCache.clear_all_namespaces()
Expand All @@ -338,7 +338,7 @@ def test_caching_org(self):
with self.assertNumQueries(0):
self.assertFalse(CourseDurationLimitConfig.current(org=course.org).enabled)

site_config = CourseDurationLimitConfig(site=site_cfg.site, enabled=True, enabled_as_of=datetime(2018, 1, 1))
site_config = CourseDurationLimitConfig(site=site_cfg.site, enabled=True, enabled_as_of=datetime(2018, 1, 1, tzinfo=pytz.UTC))
site_config.save()

RequestCache.clear_all_namespaces()
Expand All @@ -352,7 +352,7 @@ def test_caching_course(self):
site_cfg = SiteConfigurationFactory.create(
site_values={'course_org_filter': course.org}
)
course_config = CourseDurationLimitConfig(course=course, enabled=True, enabled_as_of=datetime(2018, 1, 1))
course_config = CourseDurationLimitConfig(course=course, enabled=True, enabled_as_of=datetime(2018, 1, 1, tzinfo=pytz.UTC))
course_config.save()

RequestCache.clear_all_namespaces()
Expand All @@ -376,7 +376,7 @@ def test_caching_course(self):
with self.assertNumQueries(2):
self.assertFalse(CourseDurationLimitConfig.current(course_key=course.id).enabled)

global_config = CourseDurationLimitConfig(enabled=True, enabled_as_of=datetime(2018, 1, 1))
global_config = CourseDurationLimitConfig(enabled=True, enabled_as_of=datetime(2018, 1, 1, tzinfo=pytz.UTC))
global_config.save()

RequestCache.clear_all_namespaces()
Expand All @@ -385,7 +385,7 @@ def test_caching_course(self):
with self.assertNumQueries(0):
self.assertFalse(CourseDurationLimitConfig.current(course_key=course.id).enabled)

site_config = CourseDurationLimitConfig(site=site_cfg.site, enabled=True, enabled_as_of=datetime(2018, 1, 1))
site_config = CourseDurationLimitConfig(site=site_cfg.site, enabled=True, enabled_as_of=datetime(2018, 1, 1, tzinfo=pytz.UTC))
site_config.save()

RequestCache.clear_all_namespaces()
Expand All @@ -394,7 +394,7 @@ def test_caching_course(self):
with self.assertNumQueries(0):
self.assertFalse(CourseDurationLimitConfig.current(course_key=course.id).enabled)

org_config = CourseDurationLimitConfig(org=course.org, enabled=True, enabled_as_of=datetime(2018, 1, 1))
org_config = CourseDurationLimitConfig(org=course.org, enabled=True, enabled_as_of=datetime(2018, 1, 1, tzinfo=pytz.UTC))
org_config.save()

RequestCache.clear_all_namespaces()
Expand Down
Loading