Commit f15a6867 by Jeremy Bowman Committed by GitHub

Merge pull request #15965 from edx/jmbowman/pytest_compatibility

pytest compatibility fixes
parents 804dc361 ded294c4
......@@ -171,8 +171,21 @@ class TestSaveSubsToStore(SharedModuleStoreTestCase):
contentstore().find(self.content_location_unjsonable)
class TestYoutubeSubsBase(SharedModuleStoreTestCase):
"""
Base class for tests of Youtube subs. Using override_settings and
a setUpClass() override in a test class which is inherited by another
test class doesn't work well with pytest-django.
"""
@classmethod
def setUpClass(cls):
super(TestYoutubeSubsBase, cls).setUpClass()
cls.course = CourseFactory.create(
org=cls.org, number=cls.number, display_name=cls.display_name)
@override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE)
class TestDownloadYoutubeSubs(SharedModuleStoreTestCase):
class TestDownloadYoutubeSubs(TestYoutubeSubsBase):
"""Tests for `download_youtube_subs` function."""
org = 'MITx'
......@@ -200,12 +213,6 @@ class TestDownloadYoutubeSubs(SharedModuleStoreTestCase):
for subs_id in youtube_subs.values():
self.clear_sub_content(subs_id)
@classmethod
def setUpClass(cls):
super(TestDownloadYoutubeSubs, cls).setUpClass()
cls.course = CourseFactory.create(
org=cls.org, number=cls.number, display_name=cls.display_name)
def test_success_downloading_subs(self):
response = textwrap.dedent("""<?xml version="1.0" encoding="utf-8" ?>
......
......@@ -6,6 +6,7 @@ Group Configuration Tests.
import json
import ddt
from mock import patch
from operator import itemgetter
from contentstore.utils import reverse_course_url, reverse_usage_url
from contentstore.course_group_config import GroupConfiguration, CONTENT_GROUP_CONFIGURATION_NAME
......@@ -857,6 +858,8 @@ class GroupConfigurationsUsageInfoTestCase(CourseTestCase, HelperMethods):
)
actual = self._get_user_partition('cohort')
# order of usage list is arbitrary, sort for reliable comparison
actual['groups'][0]['usage'].sort(key=itemgetter('label'))
expected = {
'id': 0,
'name': 'User Partition',
......@@ -881,7 +884,7 @@ class GroupConfigurationsUsageInfoTestCase(CourseTestCase, HelperMethods):
self.maxDiff = None
self.assertEqual(actual, expected)
assert actual == expected
def test_can_get_correct_usage_info(self):
"""
......
# -*- coding: utf-8 -*-
""" Test settings for Docker-based devstack. """
import os
os.environ['EDXAPP_TEST_MONGO_HOST'] = os.environ.get('EDXAPP_TEST_MONGO_HOST', 'edx.devstack.mongo')
# noinspection PyUnresolvedReferences
from .test import * # pylint: disable=wildcard-import
......@@ -393,7 +393,7 @@ class TestDeserialize(unittest.TestCase):
"""
Asserts the result of deserialize_field.
"""
assert_equals(expected, deserialize_field(self.test_field(), arg))
assert_equals(expected, deserialize_field(self.field_type(), arg))
def assertDeserializeNonString(self):
"""
......@@ -412,7 +412,7 @@ class TestDeserialize(unittest.TestCase):
class TestDeserializeInteger(TestDeserialize):
""" Tests deserialize as related to Integer type. """
test_field = Integer
field_type = Integer
def test_deserialize(self):
self.assertDeserializeEqual(-2, '-2')
......@@ -437,7 +437,7 @@ class TestDeserializeInteger(TestDeserialize):
class TestDeserializeFloat(TestDeserialize):
""" Tests deserialize as related to Float type. """
test_field = Float
field_type = Float
def test_deserialize(self):
self.assertDeserializeEqual(-2, '-2')
......@@ -460,7 +460,7 @@ class TestDeserializeFloat(TestDeserialize):
class TestDeserializeBoolean(TestDeserialize):
""" Tests deserialize as related to Boolean type. """
test_field = Boolean
field_type = Boolean
def test_deserialize(self):
# json.loads converts the value to Python bool
......@@ -485,7 +485,7 @@ class TestDeserializeBoolean(TestDeserialize):
class TestDeserializeString(TestDeserialize):
""" Tests deserialize as related to String type. """
test_field = String
field_type = String
def test_deserialize(self):
self.assertDeserializeEqual('hAlf', '"hAlf"')
......@@ -503,7 +503,7 @@ class TestDeserializeString(TestDeserialize):
class TestDeserializeAny(TestDeserialize):
""" Tests deserialize as related to Any type. """
test_field = Any
field_type = Any
def test_deserialize(self):
self.assertDeserializeEqual('hAlf', '"hAlf"')
......@@ -519,7 +519,7 @@ class TestDeserializeAny(TestDeserialize):
class TestDeserializeList(TestDeserialize):
""" Tests deserialize as related to List type. """
test_field = List
field_type = List
def test_deserialize(self):
self.assertDeserializeEqual(['foo', 'bar'], '["foo", "bar"]')
......@@ -536,7 +536,7 @@ class TestDeserializeList(TestDeserialize):
class TestDeserializeDate(TestDeserialize):
""" Tests deserialize as related to Date type. """
test_field = Date
field_type = Date
def test_deserialize(self):
self.assertDeserializeEqual('2012-12-31T23:59:59Z', "2012-12-31T23:59:59Z")
......@@ -547,7 +547,7 @@ class TestDeserializeDate(TestDeserialize):
class TestDeserializeTimedelta(TestDeserialize):
""" Tests deserialize as related to Timedelta type. """
test_field = Timedelta
field_type = Timedelta
def test_deserialize(self):
self.assertDeserializeEqual(
......@@ -564,7 +564,7 @@ class TestDeserializeTimedelta(TestDeserialize):
class TestDeserializeRelativeTime(TestDeserialize):
""" Tests deserialize as related to Timedelta type. """
test_field = RelativeTime
field_type = RelativeTime
def test_deserialize(self):
"""
......
......@@ -45,22 +45,29 @@ class TestOverrideProvider(FieldOverrideProvider):
return True
@attr(shard=1)
@override_settings(FIELD_OVERRIDE_PROVIDERS=(
'courseware.tests.test_field_overrides.TestOverrideProvider',))
class OverrideFieldDataTests(SharedModuleStoreTestCase):
class OverrideFieldBase(SharedModuleStoreTestCase):
"""
Tests for `OverrideFieldData`.
Base class for field data override tests. Using override_settings and
a setUpClass() override in a test class which is inherited by another
test class doesn't work well with pytest-django.
"""
@classmethod
def setUpClass(cls):
"""
Course is created here and shared by all the class's tests.
"""
super(OverrideFieldDataTests, cls).setUpClass()
super(OverrideFieldBase, cls).setUpClass()
cls.course = CourseFactory.create(enable_ccx=True)
@attr(shard=1)
@override_settings(FIELD_OVERRIDE_PROVIDERS=(
'courseware.tests.test_field_overrides.TestOverrideProvider',))
class OverrideFieldDataTests(OverrideFieldBase):
"""
Tests for `OverrideFieldData`.
"""
def setUp(self):
super(OverrideFieldDataTests, self).setUp()
OverrideFieldData.provider_classes = None
......
......@@ -794,7 +794,7 @@ class ViewsTestCase(
)
]
assert_equal(call_list, mock_request.call_args_list)
assert mock_request.call_args_list == call_list
assert_equal(response.status_code, 200)
......@@ -872,7 +872,7 @@ class ViewsTestCase(
)
]
assert_equal(call_list, mock_request.call_args_list)
assert mock_request.call_args_list == call_list
assert_equal(response.status_code, 200)
......@@ -944,7 +944,7 @@ class ViewsTestCase(
)
]
assert_equal(call_list, mock_request.call_args_list)
assert mock_request.call_args_list == call_list
assert_equal(response.status_code, 200)
......@@ -1016,7 +1016,7 @@ class ViewsTestCase(
)
]
assert_equal(call_list, mock_request.call_args_list)
assert mock_request.call_args_list == call_list
assert_equal(response.status_code, 200)
......
# -*- coding: utf-8 -*-
""" Test settings for Docker-based devstack. """
import os
os.environ['EDXAPP_TEST_MONGO_HOST'] = os.environ.get('EDXAPP_TEST_MONGO_HOST', 'edx.devstack.mongo')
# noinspection PyUnresolvedReferences
from .test import * # pylint: disable=wildcard-import
......@@ -98,7 +98,7 @@ class Env(object):
USING_DOCKER = SERVER_HOST != '0.0.0.0'
SETTINGS = 'bok_choy_docker' if USING_DOCKER else 'bok_choy'
DEVSTACK_SETTINGS = 'devstack_docker' if USING_DOCKER else 'devstack'
TEST_SETTINGS = 'test_docker' if USING_DOCKER else 'test'
TEST_SETTINGS = 'test'
BOK_CHOY_SERVERS = {
'lms': {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment