Exemple #1
0
    def test_convert_png_to_data_url_with_non_png_image_raises_error(self):
        favicon_filepath = os.path.join(self.get_static_asset_filepath(),
                                        'assets', 'favicon.ico')

        with self.assertRaisesRegexp(
                Exception, 'The given string does not represent a PNG image.'):
            utils.convert_png_to_data_url(favicon_filepath)
Exemple #2
0
    def test_convert_png_to_data_url_with_non_png_image_raises_error(self):
        # type: () -> None
        favicon_filepath = os.path.join(
            self.get_static_asset_filepath(), 'assets', 'favicon.ico') # type: ignore[no-untyped-call]

        with self.assertRaisesRegexp( # type: ignore[no-untyped-call]
            Exception, 'The given string does not represent a PNG image.'):
            utils.convert_png_to_data_url(favicon_filepath)
Exemple #3
0
 def test_default_identicon_data_url(self):
     identicon_filepath = os.path.join(self.get_static_asset_filepath(),
                                       'assets', '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_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)
Exemple #5
0
 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,
         'is_block_element':
         self.is_block_element,
         'preview_url_template':
         self.preview_url_template
     }
 def test_image_data_urls_for_rte_components(self):
     """Test the data urls for the RTE component icons."""
     component_list = rte_component_registry.Registry._rte_components
     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),
                          component_list[cpt_name].icon_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)
Exemple #8
0
 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))
Exemple #9
0
 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))
Exemple #10
0
 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)
Exemple #11
0
 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 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 test_fetch_gravatar_with_headers(self):
        user_email = '*****@*****.**'
        expected_gravatar_filepath = os.path.join(
            self.get_static_asset_filepath(), 'assets', 'images', 'avatar',
            'gravatar_example.png')
        with python_utils.open_file(expected_gravatar_filepath,
                                    'rb',
                                    encoding=None) as f:
            gravatar = f.read()

        headers_dict = {'content_type': 'application/json; charset=utf-8'}
        with self.urlfetch_mock(content=gravatar, headers=headers_dict):
            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)
Exemple #15
0
 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,
     }