From 32000c7a98021f8737e80fa8c72cd058c65e5b5d Mon Sep 17 00:00:00 2001 From: Jeremy Bowman Date: Tue, 29 Aug 2017 13:00:38 -0400 Subject: [PATCH] Clean up TestCase subclassing --- .../commands/tests/test_create_course.py | 4 ++-- .../commands/tests/test_migrate_to_split.py | 5 ++--- .../xmodule/modulestore/tests/test_mongo.py | 20 +++++++++---------- .../block_structure/tests/test_factory.py | 2 +- .../block_structure/tests/test_manager.py | 2 +- .../user_api/tests/test_middleware.py | 2 +- .../user_api/tests/test_partition_schemes.py | 2 +- .../util/tests/test_user_messages.py | 3 +-- 8 files changed, 19 insertions(+), 21 deletions(-) diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_create_course.py b/cms/djangoapps/contentstore/management/commands/tests/test_create_course.py index 02f37e8b16..b6a5920f73 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_create_course.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_create_course.py @@ -1,9 +1,9 @@ """ Unittests for creating a course in an chosen modulestore """ -import unittest import ddt from django.core.management import CommandError, call_command +from django.test import TestCase from contentstore.management.commands.create_course import Command from xmodule.modulestore import ModuleStoreEnum @@ -11,7 +11,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.django import modulestore -class TestArgParsing(unittest.TestCase): +class TestArgParsing(TestCase): """ Tests for parsing arguments for the `create_course` management command """ diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py b/cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py index 64df42d502..1af93bed15 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py @@ -1,9 +1,8 @@ """ Unittests for migrating a course to split mongo """ -import unittest - from django.core.management import CommandError, call_command +from django.test import TestCase from contentstore.management.commands.migrate_to_split import Command from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase @@ -12,7 +11,7 @@ from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError -class TestArgParsing(unittest.TestCase): +class TestArgParsing(TestCase): """ Tests for parsing arguments for the `migrate_to_split` management command """ diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py index 57423b4170..ca1239c402 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py @@ -78,7 +78,7 @@ class TestMongoModuleStoreBase(unittest.TestCase): courses = ['toy', 'simple', 'simple_with_draft', 'test_unicode'] @classmethod - def setupClass(cls): + def setUpClass(cls): cls.connection = pymongo.MongoClient( host=HOST, port=PORT, @@ -93,7 +93,7 @@ class TestMongoModuleStoreBase(unittest.TestCase): cls.content_store, cls.draft_store = cls.initdb() @classmethod - def teardownClass(cls): + def tearDownClass(cls): if cls.connection: cls.connection.drop_database(DB) cls.connection.close() @@ -186,12 +186,12 @@ class TestMongoModuleStore(TestMongoModuleStoreBase): pass @classmethod - def setupClass(cls): - super(TestMongoModuleStore, cls).setupClass() + def setUpClass(cls): + super(TestMongoModuleStore, cls).setUpClass() @classmethod - def teardownClass(cls): - super(TestMongoModuleStore, cls).teardownClass() + def tearDownClass(cls): + super(TestMongoModuleStore, cls).tearDownClass() def test_init(self): '''Make sure the db loads''' @@ -728,12 +728,12 @@ class TestMongoModuleStoreWithNoAssetCollection(TestMongoModuleStore): pass @classmethod - def setupClass(cls): - super(TestMongoModuleStoreWithNoAssetCollection, cls).setupClass() + def setUpClass(cls): + super(TestMongoModuleStoreWithNoAssetCollection, cls).setUpClass() @classmethod - def teardownClass(cls): - super(TestMongoModuleStoreWithNoAssetCollection, cls).teardownClass() + def tearDownClass(cls): + super(TestMongoModuleStoreWithNoAssetCollection, cls).tearDownClass() def test_no_asset_collection(self): courses = self.draft_store.get_courses() diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_factory.py b/openedx/core/djangoapps/content/block_structure/tests/test_factory.py index 88bb7b121d..77fbbd2513 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_factory.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_factory.py @@ -1,8 +1,8 @@ """ Tests for block_structure_factory.py """ +from django.test import TestCase from nose.plugins.attrib import attr -from unittest import TestCase from xmodule.modulestore.exceptions import ItemNotFoundError from ..store import BlockStructureStore diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_manager.py b/openedx/core/djangoapps/content/block_structure/tests/test_manager.py index 38174ec471..9c73af48c3 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_manager.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_manager.py @@ -2,8 +2,8 @@ Tests for manager.py """ import ddt +from django.test import TestCase from nose.plugins.attrib import attr -from unittest import TestCase from ..block_structure import BlockStructureBlockData from ..config import RAISE_ERROR_WHEN_NOT_FOUND, STORAGE_BACKING_FOR_CACHE, waffle diff --git a/openedx/core/djangoapps/user_api/tests/test_middleware.py b/openedx/core/djangoapps/user_api/tests/test_middleware.py index c44d575bd1..98d4c46d94 100644 --- a/openedx/core/djangoapps/user_api/tests/test_middleware.py +++ b/openedx/core/djangoapps/user_api/tests/test_middleware.py @@ -1,8 +1,8 @@ """Tests for user API middleware""" from mock import Mock, patch -from unittest import TestCase from django.http import HttpResponse +from django.test import TestCase from django.test.client import RequestFactory from student.tests.factories import UserFactory, AnonymousUserFactory 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 d12bc3f8c6..899603b341 100644 --- a/openedx/core/djangoapps/user_api/tests/test_partition_schemes.py +++ b/openedx/core/djangoapps/user_api/tests/test_partition_schemes.py @@ -2,8 +2,8 @@ Test the user api's partition extensions. """ from collections import defaultdict +from django.test import TestCase from mock import patch -from unittest import TestCase from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme, UserPartitionError from student.tests.factories import UserFactory diff --git a/openedx/core/djangoapps/util/tests/test_user_messages.py b/openedx/core/djangoapps/util/tests/test_user_messages.py index f4376c7b80..0f40f6b241 100644 --- a/openedx/core/djangoapps/util/tests/test_user_messages.py +++ b/openedx/core/djangoapps/util/tests/test_user_messages.py @@ -3,10 +3,9 @@ Unit tests for user messages. """ import ddt -from unittest import TestCase from django.contrib.messages.middleware import MessageMiddleware -from django.test import RequestFactory +from django.test import RequestFactory, TestCase from openedx.core.djangolib.markup import HTML, Text from student.tests.factories import UserFactory