def test_default_identicon_data_url(self): identicon_filepath = os.path.join( 'static', 'images', 'avatar', 'user_blue_72px.png') identicon_data_url = utils.convert_png_to_data_url( identicon_filepath) self.assertEqual( identicon_data_url, user_services.DEFAULT_IDENTICON_DATA_URL)
def test_image_data_urls_for_rte_components(self): """Test the data urls for the RTE component icons.""" for (cpt_name, cpt_spec) in feconf.ALLOWED_RTE_EXTENSIONS.iteritems(): image_filepath = os.path.join( os.getcwd(), cpt_spec['dir'], '%s.png' % cpt_name) self.assertEqual( utils.convert_png_to_data_url(image_filepath), rte_component_registry.Registry.get_rte_component( cpt_name).icon_data_url)
def preview_url_template(self): """Returns a URL template which can be interpolated to a URL for the image that represents the component in the RTE. The interpolation dictionary used is the component's customization_args dict, extended with an additional 'explorationId' key whose value corresponds to the id of the containing exploration. """ return utils.convert_png_to_data_url(os.path.join( feconf.RTE_EXTENSIONS_DIR, self.id, '%sPreview.png' % self.id))
def test_fetch_gravatar_success(self): user_email = '*****@*****.**' expected_gravatar_filepath = os.path.join( 'static', 'images', 'avatar', 'gravatar_example.png') with open(expected_gravatar_filepath, 'r') as f: gravatar = f.read() with self.urlfetch_mock(content=gravatar): profile_picture = user_services.fetch_gravatar(user_email) gravatar_data_url = utils.convert_png_to_data_url( expected_gravatar_filepath) self.assertEqual(profile_picture, gravatar_data_url)
def test_image_data_urls_for_noninteractive_widgets(self): """Test the data urls for the noninteractive widget editor icons.""" widget_registry.Registry.refresh() widget_list = widget_registry.Registry.noninteractive_widgets allowed_widgets = feconf.ALLOWED_WIDGETS[feconf.NONINTERACTIVE_PREFIX] for widget_name in allowed_widgets: image_filepath = os.path.join( os.getcwd(), allowed_widgets[widget_name]['dir'], '%s.png' % widget_name) self.assertEqual( utils.convert_png_to_data_url(image_filepath), widget_list[widget_name].icon_data_url )
def to_dict(self): """Gets a dict representing this component. Only the default values for customization args are provided. """ return { 'backend_name': self.name, 'customization_arg_specs': [{ 'name': ca_spec.name, 'description': ca_spec.description, 'default_value': ca_spec.default_value, 'schema': ca_spec.schema, } for ca_spec in self.customization_arg_specs], 'frontend_name': self.frontend_name, 'icon_data_url': utils.convert_png_to_data_url(os.path.join( feconf.RTE_EXTENSIONS_DIR, self.id, '%s.png' % self.id)), 'is_complex': self.is_complex, 'requires_fs': self.requires_fs, 'tooltip': self.tooltip, }