From c53684629140ee66705e1dad828ae87ce61c8fa7 Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Thu, 22 May 2014 11:51:38 -0400 Subject: [PATCH] Add tests for has_course and negative tests for get_course. --- .../xmodule/modulestore/tests/test_mongo.py | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py index ad2f121aa7..1d91409769 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py @@ -1,7 +1,6 @@ # pylint: disable=E0611 from nose.tools import assert_equals, assert_raises, \ - assert_not_equals, assert_false, assert_true, assert_greater, assert_is_instance -from itertools import ifilter + assert_not_equals, assert_false, assert_true, assert_greater, assert_is_instance, assert_is_none # pylint: enable=E0611 from path import path import pymongo @@ -157,6 +156,33 @@ class TestMongoModuleStore(unittest.TestCase): assert_in(course_key, course_ids) course = self.store.get_course(course_key) assert_not_none(course) + assert_true(self.store.has_course(course_key)) + mix_cased = SlashSeparatedCourseKey( + course_key.org.upper(), course_key.course.upper(), course_key.run.lower() + ) + assert_false(self.store.has_course(mix_cased)) + assert_true(self.store.has_course(mix_cased, ignore_case=True)) + + def test_no_such_course(self): + """ + Test get_course and has_course with ids which don't exist + """ + for course_key in [ + + SlashSeparatedCourseKey(*fields) + for fields in [ + ['edX', 'simple', 'no_such_course'], ['edX', 'no_such_course', '2012_Fall'], + ['NO_SUCH_COURSE', 'Test_iMport_courSe', '2012_Fall'], + ] + ]: + course = self.store.get_course(course_key) + assert_is_none(course) + assert_false(self.store.has_course(course_key)) + mix_cased = SlashSeparatedCourseKey( + course_key.org.lower(), course_key.course.upper(), course_key.run.upper() + ) + assert_false(self.store.has_course(mix_cased)) + assert_false(self.store.has_course(mix_cased, ignore_case=True)) def test_loads(self): assert_not_none(