예제 #1
0
    def test_get_courses_for_wiki(self):
        """
        Test the get_courses_for_wiki method
        """
        for course_number in self.courses:
            course_locations = self.store.get_courses_for_wiki(course_number)
            assert_equals(len(course_locations), 1)
            assert_equals(Location('i4x', 'edX', course_number, 'course', '2012_Fall'), course_locations[0])

        course_locations = self.store.get_courses_for_wiki('no_such_wiki')
        assert_equals(len(course_locations), 0)

        # set toy course to share the wiki with simple course
        toy_course = self.store.get_course('edX/toy/2012_Fall')
        toy_course.wiki_slug = 'simple'
        self.store.update_item(toy_course)

        # now toy_course should not be retrievable with old wiki_slug
        course_locations = self.store.get_courses_for_wiki('toy')
        assert_equals(len(course_locations), 0)

        # but there should be two courses with wiki_slug 'simple'
        course_locations = self.store.get_courses_for_wiki('simple')
        assert_equals(len(course_locations), 2)
        for course_number in ['toy', 'simple']:
            assert_in(Location('i4x', 'edX', course_number, 'course', '2012_Fall'), course_locations)

        # configure simple course to use unique wiki_slug.
        simple_course = self.store.get_course('edX/simple/2012_Fall')
        simple_course.wiki_slug = 'edX.simple.2012_Fall'
        self.store.update_item(simple_course)
        # it should be retrievable with its new wiki_slug
        course_locations = self.store.get_courses_for_wiki('edX.simple.2012_Fall')
        assert_equals(len(course_locations), 1)
        assert_in(Location('i4x', 'edX', 'simple', 'course', '2012_Fall'), course_locations)
예제 #2
0
 def test_contentstore_attrs(self):
     """
     Test getting, setting, and defaulting the locked attr and arbitrary attrs.
     """
     location = Location('i4x', 'edX', 'toy', 'course', '2012_Fall')
     course_content, __ = TestMongoModuleStore.content_store.get_all_content_for_course(
         location)
     assert len(course_content) > 0
     # a bit overkill, could just do for content[0]
     for content in course_content:
         assert not content.get('locked', False)
         assert not TestMongoModuleStore.content_store.get_attr(
             content['_id'], 'locked', False)
         attrs = TestMongoModuleStore.content_store.get_attrs(
             content['_id'])
         assert_in('uploadDate', attrs)
         assert not attrs.get('locked', False)
         TestMongoModuleStore.content_store.set_attr(
             content['_id'], 'locked', True)
         assert TestMongoModuleStore.content_store.get_attr(
             content['_id'], 'locked', False)
         attrs = TestMongoModuleStore.content_store.get_attrs(
             content['_id'])
         assert_in('locked', attrs)
         assert attrs['locked'] is True
         TestMongoModuleStore.content_store.set_attrs(
             content['_id'], {'miscel': 99})
         assert_equals(
             TestMongoModuleStore.content_store.get_attr(
                 content['_id'], 'miscel'), 99)
     assert_raises(AttributeError,
                   TestMongoModuleStore.content_store.set_attr,
                   course_content[0]['_id'], 'md5',
                   'ff1532598830e3feac91c2449eaa60d6')
     assert_raises(AttributeError,
                   TestMongoModuleStore.content_store.set_attrs,
                   course_content[0]['_id'], {
                       'foo': 9,
                       'md5': 'ff1532598830e3feac91c2449eaa60d6'
                   })
     assert_raises(NotFoundError,
                   TestMongoModuleStore.content_store.get_attr,
                   Location('bogus', 'bogus', 'bogus', 'asset',
                            'bogus'), 'displayname')
     assert_raises(NotFoundError,
                   TestMongoModuleStore.content_store.set_attr,
                   Location('bogus', 'bogus', 'bogus', 'asset',
                            'bogus'), 'displayname', 'hello')
     assert_raises(NotFoundError,
                   TestMongoModuleStore.content_store.get_attrs,
                   Location('bogus', 'bogus', 'bogus', 'asset', 'bogus'))
     assert_raises(NotFoundError,
                   TestMongoModuleStore.content_store.set_attrs,
                   Location('bogus', 'bogus', 'bogus', 'asset',
                            'bogus'), {'displayname': 'hello'})
     assert_raises(InsufficientSpecificationError,
                   TestMongoModuleStore.content_store.set_attrs,
                   Location('bogus', 'bogus', 'bogus', 'asset',
                            None), {'displayname': 'hello'})
예제 #3
0
 def test_contentstore_attrs(self):
     """
     Test getting, setting, and defaulting the locked attr and arbitrary attrs.
     """
     location = Location('i4x', 'edX', 'toy', 'course', '2012_Fall')
     course_content = TestMongoModuleStore.content_store.get_all_content_for_course(location)
     assert len(course_content) > 0
     # a bit overkill, could just do for content[0]
     for content in course_content:
         assert not content.get('locked', False)
         assert not TestMongoModuleStore.content_store.get_attr(content['_id'], 'locked', False)
         attrs = TestMongoModuleStore.content_store.get_attrs(content['_id'])
         assert_in('uploadDate', attrs)
         assert not attrs.get('locked', False)
         TestMongoModuleStore.content_store.set_attr(content['_id'], 'locked', True)
         assert TestMongoModuleStore.content_store.get_attr(content['_id'], 'locked', False)
         attrs = TestMongoModuleStore.content_store.get_attrs(content['_id'])
         assert_in('locked', attrs)
         assert attrs['locked'] is True
         TestMongoModuleStore.content_store.set_attrs(content['_id'], {'miscel': 99})
         assert_equals(TestMongoModuleStore.content_store.get_attr(content['_id'], 'miscel'), 99)
     assert_raises(
         AttributeError, TestMongoModuleStore.content_store.set_attr, course_content[0]['_id'],
         'md5', 'ff1532598830e3feac91c2449eaa60d6'
     )
     assert_raises(
         AttributeError, TestMongoModuleStore.content_store.set_attrs, course_content[0]['_id'],
         {'foo': 9, 'md5': 'ff1532598830e3feac91c2449eaa60d6'}
     )
     assert_raises(
         NotFoundError, TestMongoModuleStore.content_store.get_attr,
         Location('bogus', 'bogus', 'bogus', 'asset', 'bogus'),
         'displayname'
     )
     assert_raises(
         NotFoundError, TestMongoModuleStore.content_store.set_attr,
         Location('bogus', 'bogus', 'bogus', 'asset', 'bogus'),
         'displayname', 'hello'
     )
     assert_raises(
         NotFoundError, TestMongoModuleStore.content_store.get_attrs,
         Location('bogus', 'bogus', 'bogus', 'asset', 'bogus')
     )
     assert_raises(
         NotFoundError, TestMongoModuleStore.content_store.set_attrs,
         Location('bogus', 'bogus', 'bogus', 'asset', 'bogus'),
         {'displayname': 'hello'}
     )
     assert_raises(
         InsufficientSpecificationError, TestMongoModuleStore.content_store.set_attrs,
         Location('bogus', 'bogus', 'bogus', 'asset', None),
         {'displayname': 'hello'}
     )