From 7efaa87c19c15b61711053e6378d0e324738c946 Mon Sep 17 00:00:00 2001 From: Jay Zoldak Date: Fri, 9 Nov 2012 10:54:50 -0500 Subject: [PATCH] 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