Commit 41def5c9 by bmedx

Remove mock-django dependency

- PLAT-1494 since mock-django only seems to support up to Django 1.9a1, and is only used in one file we're opting to try to simplify and remove the dependency.
parent 4622b24a
""" """
Tests for celery tasks defined in tasks module Tests for celery tasks defined in tasks module
""" """
import contextlib
import mock
from ccx_keys.locator import CCXLocator 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.tasks import send_ccx_course_published
from lms.djangoapps.ccx.tests.factories import CcxFactory from lms.djangoapps.ccx.tests.factories import CcxFactory
...@@ -16,8 +17,17 @@ from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ...@@ -16,8 +17,17 @@ from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE,
from xmodule.modulestore.tests.factories import CourseFactory 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): 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 MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
...@@ -39,12 +49,14 @@ class TestSendCCXCoursePublished(ModuleStoreTestCase): ...@@ -39,12 +49,14 @@ class TestSendCCXCoursePublished(ModuleStoreTestCase):
self.ccx4 = CcxFactory(course_id=course2.id, coach=coach) self.ccx4 = CcxFactory(course_id=course2.id, coach=coach)
def call_fut(self, course_key): def call_fut(self, course_key):
"""Call the function under test """
Call the function under test
""" """
send_ccx_course_published(unicode(course_key)) send_ccx_course_published(unicode(course_key))
def test_signal_not_sent_for_ccx(self): 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) course_key = CCXLocator.from_course_locator(self.course.id, self.ccx.id)
with mock_signal_receiver(SignalHandler.course_published) as receiver: with mock_signal_receiver(SignalHandler.course_published) as receiver:
...@@ -52,7 +64,8 @@ class TestSendCCXCoursePublished(ModuleStoreTestCase): ...@@ -52,7 +64,8 @@ class TestSendCCXCoursePublished(ModuleStoreTestCase):
self.assertEqual(receiver.call_count, 0) self.assertEqual(receiver.call_count, 0)
def test_signal_sent_for_ccx(self): 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 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. count must be 3 to confirm that all derived courses and no more got the signal.
""" """
...@@ -61,7 +74,8 @@ class TestSendCCXCoursePublished(ModuleStoreTestCase): ...@@ -61,7 +74,8 @@ class TestSendCCXCoursePublished(ModuleStoreTestCase):
self.assertEqual(receiver.call_count, 3) self.assertEqual(receiver.call_count, 3)
def test_course_structure_generated(self): 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 = { ccx_structure = {
u"blocks": { u"blocks": {
...@@ -88,7 +102,8 @@ class TestSendCCXCoursePublished(ModuleStoreTestCase): ...@@ -88,7 +102,8 @@ class TestSendCCXCoursePublished(ModuleStoreTestCase):
self.assertEqual(structure.structure, ccx_structure) self.assertEqual(structure.structure, ccx_structure)
def test_course_overview_cached(self): 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) course_key = CCXLocator.from_course_locator(self.course.id, self.ccx.id)
overview = CourseOverview.objects.filter(id=course_key) overview = CourseOverview.objects.filter(id=course_key)
......
...@@ -162,7 +162,6 @@ django_nose==1.4.1 ...@@ -162,7 +162,6 @@ django_nose==1.4.1
factory_boy==2.8.1 factory_boy==2.8.1
flaky==3.3.0 flaky==3.3.0
freezegun==0.3.8 freezegun==0.3.8
mock-django==0.6.9
mock==1.0.1 mock==1.0.1
moto==0.3.1 moto==0.3.1
needle==0.5.0 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