Commit 3a6a9ee0 by Don Mitchell

tighten case-insensitive test to require full string match

parent 9042a0a8
......@@ -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'
......
......@@ -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'))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment