def test_get_plugin(self): """ Verify that get_plugin works as expected. """ tab_type = CourseTabPluginManager.get_plugin("instructor") self.assertEqual(tab_type.title, "Instructor") with self.assertRaises(PluginError): CourseTabPluginManager.get_plugin("no_such_type")
def test_get_plugin(self): """ Verify that get_plugin works as expected. """ tab_type = CourseTabPluginManager.get_plugin("instructor") self.assertEqual(tab_type.title, "Instructor") with self.assertRaises(PluginError): CourseTabPluginManager.get_plugin("no_such_type")
def test_get_plugin(self): """ Verify that get_plugin works as expected. """ tab_type = CourseTabPluginManager.get_plugin("instructor") assert tab_type.title == 'Instructor' with pytest.raises(PluginError): CourseTabPluginManager.get_plugin("no_such_type")
def from_json(tab_dict): """ Deserializes a CourseTab from a json-like representation. The subclass that is instantiated is determined by the value of the 'type' key in the given dict-type tab. The given dict-type tab is validated before instantiating the CourseTab object. If the tab_type is not recognized, then an exception is logged and None is returned. The intention is that the user should still be able to use the course even if a particular tab is not found for some reason. Args: tab: a dictionary with keys for the properties of the tab. Raises: InvalidTabsException if the given tab doesn't have the right keys. """ # TODO: don't import openedx capabilities from common from openedx.core.lib.course_tabs import CourseTabPluginManager tab_type_name = tab_dict.get('type') if tab_type_name is None: log.error('No type included in tab_dict: %r', tab_dict) return None try: tab_type = CourseTabPluginManager.get_plugin(tab_type_name) except PluginError: log.exception( "Unknown tab type %r Known types: %r.", tab_type_name, CourseTabPluginManager.get_tab_types() ) return None tab_type.validate(tab_dict) return tab_type(tab_dict=tab_dict)
def from_json(tab_dict): """ Deserializes a CourseTab from a json-like representation. The subclass that is instantiated is determined by the value of the 'type' key in the given dict-type tab. The given dict-type tab is validated before instantiating the CourseTab object. If the tab_type is not recognized, then an exception is logged and None is returned. The intention is that the user should still be able to use the course even if a particular tab is not found for some reason. Args: tab: a dictionary with keys for the properties of the tab. Raises: InvalidTabsException if the given tab doesn't have the right keys. """ # TODO: don't import openedx capabilities from common from openedx.core.lib.course_tabs import CourseTabPluginManager tab_type_name = tab_dict.get('type') if tab_type_name is None: log.error('No type included in tab_dict: %r', tab_dict) return None try: tab_type = CourseTabPluginManager.get_plugin(tab_type_name) except PluginError: log.exception("Unknown tab type %r Known types: %r.", tab_type_name, CourseTabPluginManager.get_tab_types()) return None tab_type.validate(tab_dict) return tab_type(tab_dict=tab_dict)