From 97f5fe035bc242933f2f1503a694c423b527a260 Mon Sep 17 00:00:00 2001 From: Jeremy Bowman Date: Wed, 6 Sep 2017 13:15:34 -0400 Subject: [PATCH] Fixes for pytest database usage --- cms/djangoapps/contentstore/tests/test_courseware_index.py | 2 ++ common/djangoapps/static_replace/test/test_static_replace.py | 2 ++ lms/djangoapps/instructor/tests/test_tools.py | 3 ++- .../core/djangoapps/user_api/tests/test_partition_schemes.py | 3 +++ openedx/core/lib/tests/test_time_zone_utils.py | 3 +-- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_courseware_index.py b/cms/djangoapps/contentstore/tests/test_courseware_index.py index 508f7230c5..488c3a27f4 100644 --- a/cms/djangoapps/contentstore/tests/test_courseware_index.py +++ b/cms/djangoapps/contentstore/tests/test_courseware_index.py @@ -8,6 +8,7 @@ from unittest import skip from uuid import uuid4 import ddt +import pytest from dateutil.tz import tzutc from django.conf import settings from lazy.lazy import lazy @@ -181,6 +182,7 @@ class MixedWithOptionsTestCase(MixedSplitTestCase): store.update_item(item, ModuleStoreEnum.UserID.test) +@pytest.mark.django_db @ddt.ddt class TestCoursewareSearchIndexer(MixedWithOptionsTestCase): """ Tests the operation of the CoursewareSearchIndexer """ diff --git a/common/djangoapps/static_replace/test/test_static_replace.py b/common/djangoapps/static_replace/test/test_static_replace.py index 7c259fed36..802571a777 100644 --- a/common/djangoapps/static_replace/test/test_static_replace.py +++ b/common/djangoapps/static_replace/test/test_static_replace.py @@ -6,6 +6,7 @@ from cStringIO import StringIO from urlparse import parse_qsl, urlparse, urlunparse import ddt +import pytest from django.test import override_settings from django.utils.http import urlencode, urlquote from mock import Mock, patch @@ -162,6 +163,7 @@ def test_raw_static_check(): assert_equals(path, replace_static_urls(path, text)) +@pytest.mark.django_db @patch('static_replace.staticfiles_storage', autospec=True) @patch('static_replace.modulestore', autospec=True) def test_static_url_with_query(mock_modulestore, mock_storage): diff --git a/lms/djangoapps/instructor/tests/test_tools.py b/lms/djangoapps/instructor/tests/test_tools.py index 5eecf44359..07a147788f 100644 --- a/lms/djangoapps/instructor/tests/test_tools.py +++ b/lms/djangoapps/instructor/tests/test_tools.py @@ -7,6 +7,7 @@ import json import unittest import mock +from django.test import TestCase from django.test.utils import override_settings from django.utils.timezone import utc from nose.plugins.attrib import attr @@ -65,7 +66,7 @@ class TestHandleDashboardError(unittest.TestCase): @attr(shard=1) -class TestRequireStudentIdentifier(unittest.TestCase): +class TestRequireStudentIdentifier(TestCase): """ Test require_student_from_identifier() """ diff --git a/openedx/core/djangoapps/user_api/tests/test_partition_schemes.py b/openedx/core/djangoapps/user_api/tests/test_partition_schemes.py index 899603b341..93454844d0 100644 --- a/openedx/core/djangoapps/user_api/tests/test_partition_schemes.py +++ b/openedx/core/djangoapps/user_api/tests/test_partition_schemes.py @@ -2,6 +2,8 @@ Test the user api's partition extensions. """ from collections import defaultdict + +import pytest from django.test import TestCase from mock import patch @@ -32,6 +34,7 @@ class MemoryCourseTagAPI(object): return False +@pytest.mark.django_db class TestRandomUserPartitionScheme(PartitionTestCase): """ Test getting a user's group out of a partition diff --git a/openedx/core/lib/tests/test_time_zone_utils.py b/openedx/core/lib/tests/test_time_zone_utils.py index 4b5afdecaa..273c56e824 100644 --- a/openedx/core/lib/tests/test_time_zone_utils.py +++ b/openedx/core/lib/tests/test_time_zone_utils.py @@ -1,6 +1,5 @@ """Tests covering time zone utilities.""" -from unittest import TestCase - +from django.test import TestCase from freezegun import freeze_time from pytz import timezone, utc