コード例 #1
0
    def test_validate_when_raw_image_not_string(self):
        latex_string_svg_image_dimensions = (
            html_domain.LatexStringSvgImageDimensions('1d345', '2d345',
                                                      '0d241'))

        with self.assertRaisesRegexp(
                Exception, 'Expected raw_image to be a str, received 0'):
            html_domain.LatexStringSvgImageData(
                0, latex_string_svg_image_dimensions)
コード例 #2
0
    def test_create_latex_string_svg_image_dimensions(self):
        latex_string_svg_image_dimensions = (
            html_domain.LatexStringSvgImageDimensions('1d345', '2d345',
                                                      '0d241'))

        self.assertEqual(
            latex_string_svg_image_dimensions.to_dict(), {
                'encoded_height_string': '1d345',
                'encoded_width_string': '2d345',
                'encoded_vertical_padding_string': '0d241'
            })
コード例 #3
0
    def test_create_latex_string_svg_image_dimensions(self):
        latex_string_svg_image_dimensions = (
            html_domain.LatexStringSvgImageDimensions('1d345', '2d345',
                                                      '0d241'))

        raw_image = '<svg><path d="0" /></svg>'
        latex_string_svg_image_data = (html_domain.LatexStringSvgImageData(
            raw_image, latex_string_svg_image_dimensions))

        expected_dict = {
            'raw_image': raw_image,
            'latex_string_svg_image_dimensions': {
                'encoded_height_string': '1d345',
                'encoded_width_string': '2d345',
                'encoded_vertical_padding_string': '0d241'
            }
        }
        self.assertEqual(latex_string_svg_image_data.to_dict(), expected_dict)
コード例 #4
0
    def post(self):
        latex_to_svg_mappings = self.payload.get('latexMapping')
        for exp_id, latex_to_svg_mapping_dict in latex_to_svg_mappings.items():
            for latex_string in latex_to_svg_mapping_dict.keys():
                svg_image = self.request.get(
                    latex_to_svg_mappings[exp_id][latex_string]['latexId'])
                if not svg_image:
                    raise self.InvalidInputException(
                        'SVG for LaTeX string %s in exploration %s is not '
                        'supplied.' % (latex_string, exp_id))

                dimensions = (
                    latex_to_svg_mappings[exp_id][latex_string]['dimensions'])
                latex_string_svg_image_dimensions = (
                    html_domain.LatexStringSvgImageDimensions(
                        dimensions['encoded_height_string'],
                        dimensions['encoded_width_string'],
                        dimensions['encoded_vertical_padding_string']))
                latex_string_svg_image_data = (
                    html_domain.LatexStringSvgImageData(
                        svg_image, latex_string_svg_image_dimensions))
                latex_to_svg_mappings[exp_id][latex_string] = (
                    latex_string_svg_image_data)

        for exp_id in latex_to_svg_mappings.keys():
            exp_services.update_exploration_with_math_svgs(
                exp_id, latex_to_svg_mappings[exp_id])
            logging.info('Successfully updated exploration %s' % (exp_id))
        number_of_explorations_left_to_update = (
            exp_services.
            get_number_explorations_having_latex_strings_without_svgs())
        self.render_json({
            'number_of_explorations_updated':
            '%d' % (len(latex_to_svg_mappings.keys())),
            'number_of_explorations_left_to_update':
            '%d' % (number_of_explorations_left_to_update)
        })
コード例 #5
0
    def post(self):
        latex_to_svg_mappings = self.payload.get('latexMapping')
        if not isinstance(latex_to_svg_mappings, dict):
            raise self.InvalidInputException(
                'Expected latex_to_svg_mappings to be a dict.')

        for suggestion_id, latex_to_svg_mapping_dict in (
                latex_to_svg_mappings.items()):
            for latex_string in latex_to_svg_mapping_dict.keys():
                svg_image = self.request.get(
                    latex_to_svg_mappings[suggestion_id][latex_string]
                    ['latexId'])
                if not svg_image:
                    raise self.InvalidInputException(
                        'SVG for LaTeX string %s in suggestion %s is not '
                        'supplied.' % (latex_string, suggestion_id))

                dimensions = (latex_to_svg_mappings[suggestion_id]
                              [latex_string]['dimensions'])
                latex_string_svg_image_dimensions = (
                    html_domain.LatexStringSvgImageDimensions(
                        dimensions['encoded_height_string'],
                        dimensions['encoded_width_string'],
                        dimensions['encoded_vertical_padding_string']))
                latex_string_svg_image_data = (
                    html_domain.LatexStringSvgImageData(
                        svg_image, latex_string_svg_image_dimensions))
                latex_to_svg_mappings[suggestion_id][latex_string] = (
                    latex_string_svg_image_data)

        suggestion_services.update_suggestions_with_math_svgs(
            latex_to_svg_mappings)
        self.render_json({
            'number_of_suggestions_updated':
            '%d' % (len(latex_to_svg_mappings.keys()))
        })
コード例 #6
0
 def test_validate_when_encoded_vertical_padding_string_not_string(self):
     with self.assertRaisesRegexp(
             Exception,
             'Expected encoded_vertical_padding_string to be a str, received '
             '0'):
         html_domain.LatexStringSvgImageDimensions('1d245', '4d345', 0)
コード例 #7
0
 def test_validate_when_encoded_width_string_not_string(self):
     with self.assertRaisesRegexp(
             Exception,
             'Expected encoded_width_string to be a str, received '
             '34'):
         html_domain.LatexStringSvgImageDimensions('1d245', 34, '0d124')