示例#1
0
    def get_all(cls, course):
        """Returns key/value pairs of resource.Key -> <html-hook resource>"""

        ret = {}
        for name, content in HtmlHooks.get_all(course).iteritems():
            key = resource.Key(cls.TYPE, name, course)
            value = {cls.NAME: name, cls.CONTENT: content}
            ret[key] = value
        return ret
示例#2
0
 def key_for_unit(cls, unit, course=None):
     if unit.type == verify.UNIT_TYPE_ASSESSMENT:
         unit_type = cls.ASSESSMENT_TYPE
     elif unit.type == verify.UNIT_TYPE_LINK:
         unit_type = cls.LINK_TYPE
     elif unit.type == verify.UNIT_TYPE_UNIT:
         unit_type = cls.UNIT_TYPE
     else:
         raise ValueError('Unknown unit type: %s' % unit.type)
     return resource.Key(unit_type, unit.unit_id, course=course)
    def test_change_base_announcment_updates_i18n_progress(self):
        LOCALE = 'de'
        with actions.OverriddenConfig(models.CAN_USE_MEMCACHE.name, True):
            with actions.OverriddenEnvironment({
                    'course': {
                        'locale': 'en_US',
                    },
                    'extra_locales': [{
                        'locale': LOCALE,
                        'availability': 'true'
                    }]
            }):

                key = self._add_announcement()
                data = {
                    'key': key,
                    'date': utc.to_text(seconds=0),
                    'html': 'Unsafe for operation',
                    'title': 'Attention',
                    'is_draft': False,
                }
                self._put_announcement(data)
                self._put_translation(data, LOCALE, 'Achtung', 'Gefahrlich!')

                # Verify that having saved the translation, we are in progress
                # state DONE.
                resource_key = str(
                    resource.Key(
                        announcements.ResourceHandlerAnnouncement.TYPE,
                        db.Key(encoded=data['key']).id()))
                progress = i18n_dashboard.I18nProgressDAO.load(resource_key)
                self.assertEquals(progress.get_progress(LOCALE),
                                  i18n_dashboard.I18nProgressDTO.DONE)

                # Modify the announcement in the base language.
                data['title'] = 'Informational'
                data['html'] = 'Now safe for operation again'
                self._put_announcement(data)
                self.execute_all_deferred_tasks()

                # Verify that saving the base version of the announcement
                # moves the progress state back.
                progress = i18n_dashboard.I18nProgressDAO.load(resource_key)
                self.assertEquals(progress.get_progress(LOCALE),
                                  i18n_dashboard.I18nProgressDTO.IN_PROGRESS)
示例#4
0
 def test_reject_bad_type(self):
     with self.assertRaises(AssertionError):
         resource.Key('BAD_TYPE', '23')
     with self.assertRaises(AssertionError):
         resource.Key.fromstring('BAD_TYPE:23')
示例#5
0
 def test_roundtrip_data(self):
     key1 = resource.Key(resources_display.ResourceAssessment.TYPE, '23')
     key2 = resource.Key.fromstring(str(key1))
     self.assertEquals(key1.type, key2.type)
     self.assertEquals(key1.key, key2.key)
示例#6
0
 def key_for_entity(cls, announcement, course=None):
     return resource.Key(ResourceHandlerAnnouncement.TYPE,
                         announcement.key().id(), course)
示例#7
0
 def get_key(cls, lesson):
     return resource.Key(cls.TYPE, lesson.lesson_id)