From 50a8cf4aea42000fefb1f71910ee70db6922b0ba Mon Sep 17 00:00:00 2001 From: Jay Zoldak Date: Thu, 8 Nov 2012 10:59:09 -0500 Subject: [PATCH 1/9] Add test for course creation --- cms/djangoapps/contentstore/tests/tests.py | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/cms/djangoapps/contentstore/tests/tests.py b/cms/djangoapps/contentstore/tests/tests.py index b5dfc3c4fe..c731815b55 100644 --- a/cms/djangoapps/contentstore/tests/tests.py +++ b/cms/djangoapps/contentstore/tests/tests.py @@ -208,3 +208,61 @@ class EditTestCase(ContentStoreTestCase): def test_edit_unit_full(self): self.check_edit_unit('full') + +@override_settings(MODULESTORE=TEST_DATA_MODULESTORE) +class CourseCreationTest(ContentStoreTestCase): + """Test new course creation code""" + + def setUp(self): + uname = 'testuser' + email = 'edit@test.com' + password = 'foo' + + # Create the use so we can log them in. + # Note that we do not actually need to do anything + # for registration if we directly mark them active. + u = User.objects.create_user(uname, email, password) + u.is_active = True + u.save() + + # Flush and initialize the module store + # It needs a course template because it creates a new course + # by cloning from the template. + xmodule.modulestore.django._MODULESTORES = {} + xmodule.modulestore.django.modulestore().collection.drop() + template_item = {'_id': {'tag': 'i4x', 'org': 'edx', 'course': 'templates', + 'category': 'course', 'name': 'Empty', 'revision': None}} + xmodule.modulestore.django.modulestore().collection.insert(template_item) + + self.client = Client() + self.client.login(username=uname, password=password) + + self.post_data = { + 'template': 'i4x://edx/templates/course/Empty', + 'org': 'MITx', + 'number': '999', + 'display_name': 'Robot Super Course', + } + + def test_create_course(self): + resp = self.client.post(reverse('create_new_course'), self.post_data) + self.assertEqual(resp.status_code, 200) + data = parse_json(resp) + self.assertEqual(data['id'], 'i4x://MITx/999/course/Robot_Super_Course') + + def test_create_course_duplicate_course(self): + resp = self.client.post(reverse('create_new_course'), self.post_data) + resp = self.client.post(reverse('create_new_course'), self.post_data) + data = parse_json(resp) + self.assertEqual(resp.status_code, 200) + self.assertEqual(data['ErrMsg'], 'There is already a course defined with this name.') + + def test_create_course_duplicate_number(self): + resp = self.client.post(reverse('create_new_course'), self.post_data) + self.post_data['display_name'] = 'Robot Super Course Two' + + resp = self.client.post(reverse('create_new_course'), self.post_data) + data = parse_json(resp) + + self.assertEqual(resp.status_code, 200) + self.assertEqual(data['ErrMsg'], 'There is already a course defined with the same organization and course number.') \ No newline at end of file From 2077f62dd5431d2898e6c6056b5712cecbf68115 Mon Sep 17 00:00:00 2001 From: Jay Zoldak Date: Thu, 8 Nov 2012 14:16:51 -0500 Subject: [PATCH 2/9] Add test for index page, plus SOUTH migrations for faster test execution. --- cms/djangoapps/contentstore/tests/tests.py | 83 ++++++++++++---------- cms/envs/test.py | 3 + 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/tests.py b/cms/djangoapps/contentstore/tests/tests.py index c731815b55..87fc5eac57 100644 --- a/cms/djangoapps/contentstore/tests/tests.py +++ b/cms/djangoapps/contentstore/tests/tests.py @@ -182,56 +182,31 @@ TEST_DATA_MODULESTORE['default']['OPTIONS']['fs_root'] = path('common/test/data' TEST_DATA_MODULESTORE['direct']['OPTIONS']['fs_root'] = path('common/test/data') @override_settings(MODULESTORE=TEST_DATA_MODULESTORE) -class EditTestCase(ContentStoreTestCase): - """Check that editing functionality works on example courses""" - - def setUp(self): - email = 'edit@test.com' - password = 'foo' - self.create_account('edittest', email, password) - self.activate_user(email) - self.login(email, password) - xmodule.modulestore.django._MODULESTORES = {} - xmodule.modulestore.django.modulestore().collection.drop() - - def check_edit_unit(self, test_course_name): - import_from_xml(modulestore(), 'common/test/data/', [test_course_name]) - - for descriptor in modulestore().get_items(Location(None, None, 'vertical', None, None)): - print "Checking ", descriptor.location.url() - print descriptor.__class__, descriptor.location - resp = self.client.get(reverse('edit_unit', kwargs={'location': descriptor.location.url()})) - self.assertEqual(resp.status_code, 200) - - def test_edit_unit_toy(self): - self.check_edit_unit('toy') - - def test_edit_unit_full(self): - self.check_edit_unit('full') - -@override_settings(MODULESTORE=TEST_DATA_MODULESTORE) -class CourseCreationTest(ContentStoreTestCase): - """Test new course creation code""" +class ContentStoreTest(TestCase): def setUp(self): uname = 'testuser' - email = 'edit@test.com' + email = 'test+courses@edx.org' password = 'foo' # Create the use so we can log them in. # Note that we do not actually need to do anything # for registration if we directly mark them active. - u = User.objects.create_user(uname, email, password) - u.is_active = True - u.save() + self.user = User.objects.create_user(uname, email, password) + self.user.is_active = True + self.user.save() # Flush and initialize the module store # It needs a course template because it creates a new course # by cloning from the template. xmodule.modulestore.django._MODULESTORES = {} xmodule.modulestore.django.modulestore().collection.drop() - template_item = {'_id': {'tag': 'i4x', 'org': 'edx', 'course': 'templates', - 'category': 'course', 'name': 'Empty', 'revision': None}} + template_item = { "_id" : { "tag" : "i4x", "org" : "edx", "course" : "templates", + "category" : "course", "name" : "Empty", "revision" : None }, + "definition" : { "children" : [ ], "data" : { "textbooks" : [ ], + "wiki_slug" : None } }, "metadata" : { "start" : "2020-10-10T10:00", + "display_name" : "Empty" } } + xmodule.modulestore.django.modulestore().collection.insert(template_item) self.client = Client() @@ -245,12 +220,14 @@ class CourseCreationTest(ContentStoreTestCase): } def test_create_course(self): + """Test new course creation - happy path""" resp = self.client.post(reverse('create_new_course'), self.post_data) self.assertEqual(resp.status_code, 200) data = parse_json(resp) self.assertEqual(data['id'], 'i4x://MITx/999/course/Robot_Super_Course') def test_create_course_duplicate_course(self): + """Test new course creation - error path""" resp = self.client.post(reverse('create_new_course'), self.post_data) resp = self.client.post(reverse('create_new_course'), self.post_data) data = parse_json(resp) @@ -258,6 +235,7 @@ class CourseCreationTest(ContentStoreTestCase): self.assertEqual(data['ErrMsg'], 'There is already a course defined with this name.') def test_create_course_duplicate_number(self): + """Test new course creation - error path""" resp = self.client.post(reverse('create_new_course'), self.post_data) self.post_data['display_name'] = 'Robot Super Course Two' @@ -265,4 +243,35 @@ class CourseCreationTest(ContentStoreTestCase): data = parse_json(resp) self.assertEqual(resp.status_code, 200) - self.assertEqual(data['ErrMsg'], 'There is already a course defined with the same organization and course number.') \ No newline at end of file + self.assertEqual(data['ErrMsg'], 'There is already a course defined with the same organization and course number.') + + def test_index(self): + """Test viewing the existing courses""" + # Staff has access to view all courses + self.user.is_staff = True + self.user.save() + + # Create a course so there is something to view + resp = self.client.post(reverse('create_new_course'), self.post_data) + resp = self.client.get(reverse('index')) + + # Right now there may be a bug in cms/templates/widgets/header.html + # because there is an unexpected ending ul tag in the header. + # When this is fixed, change html=True below. JZ 11/08/2012 + self.assertContains(resp, 'Robot Super Course', html=False) + + def check_edit_unit(self, test_course_name): + """Check that editing functionality works on example courses""" + import_from_xml(modulestore(), 'common/test/data/', [test_course_name]) + + for descriptor in modulestore().get_items(Location(None, None, 'vertical', None, None)): + print "Checking ", descriptor.location.url() + print descriptor.__class__, descriptor.location + resp = self.client.get(reverse('edit_unit', kwargs={'location': descriptor.location.url()})) + self.assertEqual(resp.status_code, 200) + + def test_edit_unit_toy(self): + self.check_edit_unit('toy') + + def test_edit_unit_full(self): + self.check_edit_unit('full') \ No newline at end of file diff --git a/cms/envs/test.py b/cms/envs/test.py index 217ed0e573..235993f5ac 100644 --- a/cms/envs/test.py +++ b/cms/envs/test.py @@ -21,6 +21,9 @@ TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' TEST_ROOT = path('test_root') +# Makes the tests run much faster... +SOUTH_TESTS_MIGRATE = False # To disable migrations and use syncdb instead + # Want static files in the same dir for running on jenkins. STATIC_ROOT = TEST_ROOT / "staticfiles" From ddfbf3b678d7cbde5fa9fbc480b9fc21a428b206 Mon Sep 17 00:00:00 2001 From: Jay Zoldak Date: Thu, 8 Nov 2012 17:16:25 -0500 Subject: [PATCH 3/9] Add test for course overview page --- cms/djangoapps/contentstore/tests/tests.py | 42 ++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/tests.py b/cms/djangoapps/contentstore/tests/tests.py index 87fc5eac57..902c061648 100644 --- a/cms/djangoapps/contentstore/tests/tests.py +++ b/cms/djangoapps/contentstore/tests/tests.py @@ -190,12 +190,16 @@ class ContentStoreTest(TestCase): password = 'foo' # Create the use so we can log them in. + self.user = User.objects.create_user(uname, email, password) + # Note that we do not actually need to do anything # for registration if we directly mark them active. - self.user = User.objects.create_user(uname, email, password) self.user.is_active = True + # Staff has access to view all courses + self.user.is_staff = True self.user.save() + # Flush and initialize the module store # It needs a course template because it creates a new course # by cloning from the template. @@ -245,12 +249,20 @@ class ContentStoreTest(TestCase): self.assertEqual(resp.status_code, 200) self.assertEqual(data['ErrMsg'], 'There is already a course defined with the same organization and course number.') - def test_index(self): - """Test viewing the existing courses""" - # Staff has access to view all courses - self.user.is_staff = True - self.user.save() + def test_course_index_view_with_no_courses(self): + """Test viewing the index page with no courses""" + # Create a course so there is something to view + resp = self.client.get(reverse('index')) + # Right now there may be a bug in cms/templates/widgets/header.html + # because there is an unexpected ending ul tag in the header. + # When this is fixed, make a better matcher below. JZ 11/08/2012 + self.assertContains(resp, + ' New Course', + html=False) + + def test_course_index_view_with_course(self): + """Test viewing the index page with an existing course""" # Create a course so there is something to view resp = self.client.post(reverse('create_new_course'), self.post_data) resp = self.client.get(reverse('index')) @@ -260,6 +272,24 @@ class ContentStoreTest(TestCase): # When this is fixed, change html=True below. JZ 11/08/2012 self.assertContains(resp, 'Robot Super Course', html=False) + def test_course_overview_view_with_course(self): + """Test viewing the course overview page with an existing course""" + # Create a course so there is something to view + resp = self.client.post(reverse('create_new_course'), self.post_data) + + data = { + 'org': 'MITx', + 'course': '999', + 'name': Location.clean('Robot Super Course'),} + + resp = self.client.get(reverse('course_index', kwargs=data)) + # Right now there may be a bug in cms/templates/widgets/header.html + # because there is an unexpected ending ul tag in the header. + # When this is fixed, change html=True below. JZ 11/08/2012 + self.assertContains(resp, + 'Robot Super Course', + html=False) + def check_edit_unit(self, test_course_name): """Check that editing functionality works on example courses""" import_from_xml(modulestore(), 'common/test/data/', [test_course_name]) From 7efaa87c19c15b61711053e6378d0e324738c946 Mon Sep 17 00:00:00 2001 From: Jay Zoldak Date: Fri, 9 Nov 2012 10:54:50 -0500 Subject: [PATCH 4/9] Add test for clone item. Also change password hashing for faster tests. --- cms/djangoapps/contentstore/tests/tests.py | 71 +++++++++++++++------- cms/envs/test.py | 7 +++ 2 files changed, 56 insertions(+), 22 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/tests.py b/cms/djangoapps/contentstore/tests/tests.py index 902c061648..b82b88d29c 100644 --- a/cms/djangoapps/contentstore/tests/tests.py +++ b/cms/djangoapps/contentstore/tests/tests.py @@ -201,53 +201,69 @@ class ContentStoreTest(TestCase): # Flush and initialize the module store - # It needs a course template because it creates a new course + # It needs the templates because it creates new records # by cloning from the template. xmodule.modulestore.django._MODULESTORES = {} xmodule.modulestore.django.modulestore().collection.drop() - template_item = { "_id" : { "tag" : "i4x", "org" : "edx", "course" : "templates", - "category" : "course", "name" : "Empty", "revision" : None }, - "definition" : { "children" : [ ], "data" : { "textbooks" : [ ], - "wiki_slug" : None } }, "metadata" : { "start" : "2020-10-10T10:00", - "display_name" : "Empty" } } - - xmodule.modulestore.django.modulestore().collection.insert(template_item) + course_template = { "_id" : { "tag" : "i4x", "org" : "edx", "course" : "templates", + "category" : "course", "name" : "Empty", "revision" : None }, + "definition" : { "children" : [ ], "data" : { "textbooks" : [ ], + "wiki_slug" : None } }, + "metadata" : { "start" : "2020-10-10T10:00", "display_name" : "Empty" } } + section_template = { "_id" : { "tag" : "i4x", "org" : "edx", "course" : "templates", + "category" : "section", "name" : "Empty", "revision" : None }, + "definition" : { "children" : [ ], "data" : "" }, + "metadata" : { "display_name" : "Empty" } } + chapter_template = { "_id" : { "tag" : "i4x", "org" : "edx", "course" : "templates", + "category" : "chapter", "name" : "Empty", "revision" : None }, + "definition" : { "children" : [ ], "data" : "" }, + "metadata" : { "display_name" : "Empty" } } + xmodule.modulestore.django.modulestore().collection.insert(course_template) + xmodule.modulestore.django.modulestore().collection.insert(section_template) + xmodule.modulestore.django.modulestore().collection.insert(chapter_template) self.client = Client() self.client.login(username=uname, password=password) - self.post_data = { + self.course_data = { 'template': 'i4x://edx/templates/course/Empty', 'org': 'MITx', 'number': '999', 'display_name': 'Robot Super Course', - } + } + + self.section_data = { + 'parent_location' : 'i4x://MITx/999/course/Robot_Super_Course', + 'template' : 'i4x://edx/templates/chapter/Empty', + 'display_name': 'Section One', + } def test_create_course(self): """Test new course creation - happy path""" - resp = self.client.post(reverse('create_new_course'), self.post_data) + resp = self.client.post(reverse('create_new_course'), self.course_data) self.assertEqual(resp.status_code, 200) data = parse_json(resp) self.assertEqual(data['id'], 'i4x://MITx/999/course/Robot_Super_Course') def test_create_course_duplicate_course(self): """Test new course creation - error path""" - resp = self.client.post(reverse('create_new_course'), self.post_data) - resp = self.client.post(reverse('create_new_course'), self.post_data) + resp = self.client.post(reverse('create_new_course'), self.course_data) + resp = self.client.post(reverse('create_new_course'), self.course_data) data = parse_json(resp) self.assertEqual(resp.status_code, 200) self.assertEqual(data['ErrMsg'], 'There is already a course defined with this name.') def test_create_course_duplicate_number(self): """Test new course creation - error path""" - resp = self.client.post(reverse('create_new_course'), self.post_data) - self.post_data['display_name'] = 'Robot Super Course Two' + resp = self.client.post(reverse('create_new_course'), self.course_data) + self.course_data['display_name'] = 'Robot Super Course Two' - resp = self.client.post(reverse('create_new_course'), self.post_data) + resp = self.client.post(reverse('create_new_course'), self.course_data) data = parse_json(resp) self.assertEqual(resp.status_code, 200) - self.assertEqual(data['ErrMsg'], 'There is already a course defined with the same organization and course number.') + self.assertEqual(data['ErrMsg'], + 'There is already a course defined with the same organization and course number.') def test_course_index_view_with_no_courses(self): """Test viewing the index page with no courses""" @@ -264,7 +280,7 @@ class ContentStoreTest(TestCase): def test_course_index_view_with_course(self): """Test viewing the index page with an existing course""" # Create a course so there is something to view - resp = self.client.post(reverse('create_new_course'), self.post_data) + resp = self.client.post(reverse('create_new_course'), self.course_data) resp = self.client.get(reverse('index')) # Right now there may be a bug in cms/templates/widgets/header.html @@ -275,12 +291,13 @@ class ContentStoreTest(TestCase): def test_course_overview_view_with_course(self): """Test viewing the course overview page with an existing course""" # Create a course so there is something to view - resp = self.client.post(reverse('create_new_course'), self.post_data) + resp = self.client.post(reverse('create_new_course'), self.course_data) data = { - 'org': 'MITx', - 'course': '999', - 'name': Location.clean('Robot Super Course'),} + 'org': 'MITx', + 'course': '999', + 'name': Location.clean('Robot Super Course'), + } resp = self.client.get(reverse('course_index', kwargs=data)) # Right now there may be a bug in cms/templates/widgets/header.html @@ -290,6 +307,16 @@ class ContentStoreTest(TestCase): 'Robot Super Course', html=False) + def test_clone_item(self): + """Test cloning an item. E.g. creating a new section""" + resp = self.client.post(reverse('create_new_course'), self.course_data) + resp = self.client.post(reverse('clone_item'), self.section_data) + + self.assertEqual(resp.status_code, 200) + data = parse_json(resp) + self.assertRegexpMatches(data['id'], + '^i4x:\/\/MITx\/999\/chapter\/([0-9]|[a-f]){32}$') + def check_edit_unit(self, test_course_name): """Check that editing functionality works on example courses""" import_from_xml(modulestore(), 'common/test/data/', [test_course_name]) diff --git a/cms/envs/test.py b/cms/envs/test.py index 0f69ab682e..cb84f32ff1 100644 --- a/cms/envs/test.py +++ b/cms/envs/test.py @@ -99,3 +99,10 @@ CACHES = { 'KEY_FUNCTION': 'util.memcache.safe_key', } } + +################### Make tests faster +#http://slacy.com/blog/2012/04/make-your-tests-faster-in-django-1-4/ +PASSWORD_HASHERS = ( + 'django.contrib.auth.hashers.SHA1PasswordHasher', + 'django.contrib.auth.hashers.MD5PasswordHasher', +) \ No newline at end of file From f249c227a5ac2b42b264dfe42d1bfaa33393d5e8 Mon Sep 17 00:00:00 2001 From: Jay Zoldak Date: Fri, 9 Nov 2012 11:05:37 -0500 Subject: [PATCH 5/9] Fix typo in close tag in header --- cms/templates/widgets/header.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cms/templates/widgets/header.html b/cms/templates/widgets/header.html index 0f5780a5d2..877f03533c 100644 --- a/cms/templates/widgets/header.html +++ b/cms/templates/widgets/header.html @@ -24,6 +24,6 @@ % else: Log in % endif - + From 58eea1bc8088c74727bfe5fb1ac4afe3c52d800c Mon Sep 17 00:00:00 2001 From: Jay Zoldak Date: Fri, 9 Nov 2012 11:40:23 -0500 Subject: [PATCH 6/9] Remove section close tag that had no open tag. --- cms/templates/index.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/cms/templates/index.html b/cms/templates/index.html index e195daaed0..652acfa0ea 100644 --- a/cms/templates/index.html +++ b/cms/templates/index.html @@ -61,7 +61,4 @@ - - - From bc34d79dbf4f84b054b9088cbec9c46c6de17450 Mon Sep 17 00:00:00 2001 From: Jay Zoldak Date: Fri, 9 Nov 2012 12:14:11 -0500 Subject: [PATCH 7/9] Improve assertions by using HTML matchers. --- cms/djangoapps/contentstore/tests/tests.py | 39 +++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/tests.py b/cms/djangoapps/contentstore/tests/tests.py index b82b88d29c..832feae8be 100644 --- a/cms/djangoapps/contentstore/tests/tests.py +++ b/cms/djangoapps/contentstore/tests/tests.py @@ -199,7 +199,6 @@ class ContentStoreTest(TestCase): self.user.is_staff = True self.user.save() - # Flush and initialize the module store # It needs the templates because it creates new records # by cloning from the template. @@ -238,6 +237,17 @@ class ContentStoreTest(TestCase): 'display_name': 'Section One', } + def tearDown(self): + # Make sure you flush out the test modulestore after the end + # of the last test otherwise cms/djangoapps/contentstore/__init__.py + # update_templates() is complaining that there are duplicate + # templates. + # If your test module gets in some weird state, do this manually + # from the bash shell to drop it. + # $ mongo test_xmodule --eval "db.dropDatabase()" + xmodule.modulestore.django._MODULESTORES = {} + xmodule.modulestore.django.modulestore().collection.drop() + def test_create_course(self): """Test new course creation - happy path""" resp = self.client.post(reverse('create_new_course'), self.course_data) @@ -269,24 +279,20 @@ class ContentStoreTest(TestCase): """Test viewing the index page with no courses""" # Create a course so there is something to view resp = self.client.get(reverse('index')) - - # Right now there may be a bug in cms/templates/widgets/header.html - # because there is an unexpected ending ul tag in the header. - # When this is fixed, make a better matcher below. JZ 11/08/2012 self.assertContains(resp, - ' New Course', - html=False) + '

My Courses

', + status_code=200, + html=True) def test_course_index_view_with_course(self): """Test viewing the index page with an existing course""" # Create a course so there is something to view resp = self.client.post(reverse('create_new_course'), self.course_data) resp = self.client.get(reverse('index')) - - # Right now there may be a bug in cms/templates/widgets/header.html - # because there is an unexpected ending ul tag in the header. - # When this is fixed, change html=True below. JZ 11/08/2012 - self.assertContains(resp, 'Robot Super Course', html=False) + self.assertContains(resp, + 'Robot Super Course', + status_code=200, + html=True) def test_course_overview_view_with_course(self): """Test viewing the course overview page with an existing course""" @@ -300,12 +306,10 @@ class ContentStoreTest(TestCase): } resp = self.client.get(reverse('course_index', kwargs=data)) - # Right now there may be a bug in cms/templates/widgets/header.html - # because there is an unexpected ending ul tag in the header. - # When this is fixed, change html=True below. JZ 11/08/2012 self.assertContains(resp, 'Robot Super Course', - html=False) + status_code=200, + html=True) def test_clone_item(self): """Test cloning an item. E.g. creating a new section""" @@ -327,6 +331,9 @@ class ContentStoreTest(TestCase): resp = self.client.get(reverse('edit_unit', kwargs={'location': descriptor.location.url()})) self.assertEqual(resp.status_code, 200) + xmodule.modulestore.django._MODULESTORES = {} + xmodule.modulestore.django.modulestore().collection.drop() + def test_edit_unit_toy(self): self.check_edit_unit('toy') From 5f926ebad07390caa0f007322ad357a208efe644 Mon Sep 17 00:00:00 2001 From: Jay Zoldak Date: Fri, 9 Nov 2012 14:34:04 -0500 Subject: [PATCH 8/9] Add better comments and modulestore cleanup. --- cms/djangoapps/contentstore/tests/tests.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/tests.py b/cms/djangoapps/contentstore/tests/tests.py index 832feae8be..34b47503d1 100644 --- a/cms/djangoapps/contentstore/tests/tests.py +++ b/cms/djangoapps/contentstore/tests/tests.py @@ -239,9 +239,10 @@ class ContentStoreTest(TestCase): def tearDown(self): # Make sure you flush out the test modulestore after the end - # of the last test otherwise cms/djangoapps/contentstore/__init__.py - # update_templates() is complaining that there are duplicate - # templates. + # of the last test because otherwise on the next run + # cms/djangoapps/contentstore/__init__.py + # update_templates() will try to update the templates + # via upsert and it seems to be messing things up. # If your test module gets in some weird state, do this manually # from the bash shell to drop it. # $ mongo test_xmodule --eval "db.dropDatabase()" @@ -322,7 +323,6 @@ class ContentStoreTest(TestCase): '^i4x:\/\/MITx\/999\/chapter\/([0-9]|[a-f]){32}$') def check_edit_unit(self, test_course_name): - """Check that editing functionality works on example courses""" import_from_xml(modulestore(), 'common/test/data/', [test_course_name]) for descriptor in modulestore().get_items(Location(None, None, 'vertical', None, None)): @@ -331,11 +331,9 @@ class ContentStoreTest(TestCase): resp = self.client.get(reverse('edit_unit', kwargs={'location': descriptor.location.url()})) self.assertEqual(resp.status_code, 200) - xmodule.modulestore.django._MODULESTORES = {} - xmodule.modulestore.django.modulestore().collection.drop() - def test_edit_unit_toy(self): self.check_edit_unit('toy') def test_edit_unit_full(self): - self.check_edit_unit('full') \ No newline at end of file + self.check_edit_unit('full') + From a060b8de9c6791f7471efde171f507c9ed3e0d63 Mon Sep 17 00:00:00 2001 From: Jay Zoldak Date: Tue, 13 Nov 2012 08:35:22 -0500 Subject: [PATCH 9/9] Use xmodule.templates instead of hard coding them in the test --- cms/djangoapps/contentstore/tests/tests.py | 26 +++++----------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/tests.py b/cms/djangoapps/contentstore/tests/tests.py index 34b47503d1..b0bb6c86a1 100644 --- a/cms/djangoapps/contentstore/tests/tests.py +++ b/cms/djangoapps/contentstore/tests/tests.py @@ -202,24 +202,13 @@ class ContentStoreTest(TestCase): # Flush and initialize the module store # It needs the templates because it creates new records # by cloning from the template. + # Note that if your test module gets in some weird state + # (though it shouldn't), do this manually + # from the bash shell to drop it: + # $ mongo test_xmodule --eval "db.dropDatabase()" xmodule.modulestore.django._MODULESTORES = {} xmodule.modulestore.django.modulestore().collection.drop() - course_template = { "_id" : { "tag" : "i4x", "org" : "edx", "course" : "templates", - "category" : "course", "name" : "Empty", "revision" : None }, - "definition" : { "children" : [ ], "data" : { "textbooks" : [ ], - "wiki_slug" : None } }, - "metadata" : { "start" : "2020-10-10T10:00", "display_name" : "Empty" } } - section_template = { "_id" : { "tag" : "i4x", "org" : "edx", "course" : "templates", - "category" : "section", "name" : "Empty", "revision" : None }, - "definition" : { "children" : [ ], "data" : "" }, - "metadata" : { "display_name" : "Empty" } } - chapter_template = { "_id" : { "tag" : "i4x", "org" : "edx", "course" : "templates", - "category" : "chapter", "name" : "Empty", "revision" : None }, - "definition" : { "children" : [ ], "data" : "" }, - "metadata" : { "display_name" : "Empty" } } - xmodule.modulestore.django.modulestore().collection.insert(course_template) - xmodule.modulestore.django.modulestore().collection.insert(section_template) - xmodule.modulestore.django.modulestore().collection.insert(chapter_template) + xmodule.templates.update_templates() self.client = Client() self.client.login(username=uname, password=password) @@ -242,10 +231,7 @@ class ContentStoreTest(TestCase): # of the last test because otherwise on the next run # cms/djangoapps/contentstore/__init__.py # update_templates() will try to update the templates - # via upsert and it seems to be messing things up. - # If your test module gets in some weird state, do this manually - # from the bash shell to drop it. - # $ mongo test_xmodule --eval "db.dropDatabase()" + # via upsert and it sometimes seems to be messing things up. xmodule.modulestore.django._MODULESTORES = {} xmodule.modulestore.django.modulestore().collection.drop()