From 1759191370c2a3871ed91e0bc67e59558c7d6699 Mon Sep 17 00:00:00 2001 From: lapentab Date: Thu, 22 Aug 2013 08:43:28 -0400 Subject: [PATCH 1/2] Remove network calls in tests --- cms/djangoapps/contentstore/tests/test_contentstore.py | 10 ++++++++-- lms/djangoapps/courseware/tests/tests.py | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 7491e5ab4a59..f13edbd213f3 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -312,7 +312,10 @@ def test_no_static_link_rewrites_on_import(self): handouts = module_store.get_item(Location(['i4x', 'edX', 'toy', 'html', 'toyhtml', None])) self.assertIn('/static/', handouts.data) - def test_import_textbook_as_content_element(self): + @mock.patch('xmodule.course_module.requests.get') + def test_import_textbook_as_content_element(self, mock_get): + mock_get.return_value.text = u'\n\n \n' + module_store = modulestore('direct') import_from_xml(module_store, 'common/test/data/', ['toy']) @@ -845,7 +848,10 @@ def verify_content_existence(self, store, root_dir, location, dirname, category_ filesystem = OSFS(root_dir / ('test_export/' + dirname)) self.assertTrue(filesystem.exists(item.location.name + filename_suffix)) - def test_export_course(self): + @mock.patch('xmodule.course_module.requests.get') + def test_export_course(self, mock_get): + mock_get.return_value.text = u'\n\n \n' + module_store = modulestore('direct') draft_store = modulestore('draft') content_store = contentstore() diff --git a/lms/djangoapps/courseware/tests/tests.py b/lms/djangoapps/courseware/tests/tests.py index 68b06a1ba80d..5cf84d7088a3 100644 --- a/lms/djangoapps/courseware/tests/tests.py +++ b/lms/djangoapps/courseware/tests/tests.py @@ -2,6 +2,7 @@ Test for lms courseware app ''' import random +import mock from django.test import TestCase from django.core.urlresolvers import reverse @@ -162,7 +163,9 @@ def test_toy_course_loads(self): import_from_xml(module_store, TEST_DATA_DIR, ['toy']) self.check_random_page_loads(module_store) - def test_toy_textbooks_loads(self): + @mock.patch('xmodule.course_module.requests.get') + def test_toy_textbooks_loads(self, mock_get): + mock_get.return_value.text = u'\n\n \n' module_store = modulestore() import_from_xml(module_store, TEST_DATA_DIR, ['toy']) From d894a065dfaf649f30d65e7c4d95a5efa86b7e52 Mon Sep 17 00:00:00 2001 From: lapentab Date: Thu, 22 Aug 2013 09:28:37 -0400 Subject: [PATCH 2/2] Stylistic changes --- .../contentstore/tests/test_contentstore.py | 15 +++++++++++++-- lms/djangoapps/courseware/tests/tests.py | 10 +++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index f13edbd213f3..2afc26707a1c 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -3,6 +3,9 @@ import json import shutil import mock + +from textwrap import dedent + from django.test.client import Client from django.test.utils import override_settings from django.conf import settings @@ -314,7 +317,11 @@ def test_no_static_link_rewrites_on_import(self): @mock.patch('xmodule.course_module.requests.get') def test_import_textbook_as_content_element(self, mock_get): - mock_get.return_value.text = u'\n\n \n' + mock_get.return_value.text = dedent(""" + + + + """).strip() module_store = modulestore('direct') import_from_xml(module_store, 'common/test/data/', ['toy']) @@ -850,7 +857,11 @@ def verify_content_existence(self, store, root_dir, location, dirname, category_ @mock.patch('xmodule.course_module.requests.get') def test_export_course(self, mock_get): - mock_get.return_value.text = u'\n\n \n' + mock_get.return_value.text = dedent(""" + + + + """).strip() module_store = modulestore('direct') draft_store = modulestore('draft') diff --git a/lms/djangoapps/courseware/tests/tests.py b/lms/djangoapps/courseware/tests/tests.py index 5cf84d7088a3..21a7e392a03c 100644 --- a/lms/djangoapps/courseware/tests/tests.py +++ b/lms/djangoapps/courseware/tests/tests.py @@ -4,6 +4,8 @@ import random import mock +from textwrap import dedent + from django.test import TestCase from django.core.urlresolvers import reverse from django.test.utils import override_settings @@ -165,7 +167,12 @@ def test_toy_course_loads(self): @mock.patch('xmodule.course_module.requests.get') def test_toy_textbooks_loads(self, mock_get): - mock_get.return_value.text = u'\n\n \n' + mock_get.return_value.text = dedent(""" + + + + """).strip() + module_store = modulestore() import_from_xml(module_store, TEST_DATA_DIR, ['toy']) @@ -173,6 +180,7 @@ def test_toy_textbooks_loads(self, mock_get): self.assertGreater(len(course.textbooks), 0) + @override_settings(MODULESTORE=TEST_DATA_DRAFT_MONGO_MODULESTORE) class TestDraftModuleStore(TestCase): def test_get_items_with_course_items(self):