From 3a6a9ee009f99ca56271e1c369d0d00a49f1689a Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Thu, 24 Oct 2013 11:24:37 -0400 Subject: [PATCH] tighten case-insensitive test to require full string match --- .../contentstore/tests/test_contentstore.py | 14 ++++++++++++++ cms/djangoapps/contentstore/views/course.py | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 94bf4a8f4d..533a6ffdc1 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -1450,6 +1450,20 @@ class ContentStoreTest(ModuleStoreTestCase): self.course_data['number'] = self.course_data['number'].upper() self.assert_course_creation_failed('There is already a course defined with the same organization and course number. Please change at least one field to be unique.') + def test_course_substring(self): + """ + Test that a new course can be created whose name is a substring of an existing course + """ + self.client.post(reverse('create_new_course'), self.course_data) + cache_current = self.course_data['number'] + self.course_data['number'] = '{}a'.format(self.course_data['number']) + resp = self.client.post(reverse('create_new_course'), self.course_data) + self.assertEqual(resp.status_code, 200) + self.course_data['number'] = cache_current + self.course_data['org'] = 'a{}'.format(self.course_data['org']) + resp = self.client.post(reverse('create_new_course'), self.course_data) + self.assertEqual(resp.status_code, 200) + def test_create_course_with_bad_organization(self): """Test new course creation - error path for bad organization name""" self.course_data['org'] = 'University of California, Berkeley' diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index c088e97d29..b0cc4b9343 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -204,8 +204,8 @@ def create_new_course(request): course_search_location = bson.son.SON({ '_id.tag': 'i4x', # cannot pass regex to Location constructor; thus this hack - '_id.org': re.compile(dest_location.org, re.IGNORECASE), - '_id.course': re.compile(dest_location.course, re.IGNORECASE), + '_id.org': re.compile('^{}$'.format(dest_location.org), re.IGNORECASE), + '_id.course': re.compile('^{}$'.format(dest_location.course), re.IGNORECASE), '_id.category': 'course', }) courses = modulestore().collection.find(course_search_location, fields=('_id'))