From bc34d79dbf4f84b054b9088cbec9c46c6de17450 Mon Sep 17 00:00:00 2001 From: Jay Zoldak Date: Fri, 9 Nov 2012 12:14:11 -0500 Subject: [PATCH] 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')