Commit f9216656 by Brian Mesick Committed by GitHub

Merge pull request #15393 from edx/bmedx/django_1.11_upgrade_mock_django_PLAT_1494

Remove mock-django dependency
parents 7b439d02 41def5c9
"""
Tests for celery tasks defined in tasks module
"""
import contextlib
import mock
from ccx_keys.locator import CCXLocator
from mock_django import mock_signal_receiver
from lms.djangoapps.ccx.tasks import send_ccx_course_published
from lms.djangoapps.ccx.tests.factories import CcxFactory
......@@ -16,8 +17,17 @@ from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE,
from xmodule.modulestore.tests.factories import CourseFactory
@contextlib.contextmanager
def mock_signal_receiver(signal):
receiver = mock.Mock()
signal.connect(receiver)
yield receiver
signal.disconnect(receiver)
class TestSendCCXCoursePublished(ModuleStoreTestCase):
"""unit tests for the send ccx course published task
"""
Unit tests for the send ccx course published task
"""
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
......@@ -39,12 +49,14 @@ class TestSendCCXCoursePublished(ModuleStoreTestCase):
self.ccx4 = CcxFactory(course_id=course2.id, coach=coach)
def call_fut(self, course_key):
"""Call the function under test
"""
Call the function under test
"""
send_ccx_course_published(unicode(course_key))
def test_signal_not_sent_for_ccx(self):
"""Check that course published signal is not sent when course key is for a ccx
"""
Check that course published signal is not sent when course key is for a ccx
"""
course_key = CCXLocator.from_course_locator(self.course.id, self.ccx.id)
with mock_signal_receiver(SignalHandler.course_published) as receiver:
......@@ -52,7 +64,8 @@ class TestSendCCXCoursePublished(ModuleStoreTestCase):
self.assertEqual(receiver.call_count, 0)
def test_signal_sent_for_ccx(self):
"""Check that course published signal is sent when course key is not for a ccx.
"""
Check that course published signal is sent when course key is not for a ccx.
We have 4 ccx's, but only 3 are derived from the course id used here, so call
count must be 3 to confirm that all derived courses and no more got the signal.
"""
......@@ -61,7 +74,8 @@ class TestSendCCXCoursePublished(ModuleStoreTestCase):
self.assertEqual(receiver.call_count, 3)
def test_course_structure_generated(self):
"""Check that course structure is generated after course published signal is sent
"""
Check that course structure is generated after course published signal is sent
"""
ccx_structure = {
u"blocks": {
......@@ -88,7 +102,8 @@ class TestSendCCXCoursePublished(ModuleStoreTestCase):
self.assertEqual(structure.structure, ccx_structure)
def test_course_overview_cached(self):
"""Check that course overview is cached after course published signal is sent
"""
Check that course overview is cached after course published signal is sent
"""
course_key = CCXLocator.from_course_locator(self.course.id, self.ccx.id)
overview = CourseOverview.objects.filter(id=course_key)
......
......@@ -162,7 +162,6 @@ django_nose==1.4.1
factory_boy==2.8.1
flaky==3.3.0
freezegun==0.3.8
mock-django==0.6.9
mock==1.0.1
moto==0.3.1
needle==0.5.0
......
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