Beispiel #1
0
    def test_retranslate_already_translated_with_list_reordered_matched(self):
        binding = schema_fields.ValueToTypeBinding.bind_entity_to_schema(
            self.question, self.schema)
        desired = _filter(binding)
        translation = xcontent.SourceToTargetMapping('choices:[0]:feedback',
                                                     'Feedback', 'html',
                                                     'Correct (old)!',
                                                     'CORRECT!')
        try:
            mappings = xcontent.SourceToTargetDiffMapping.map_source_to_target(
                binding,
                existing_mappings=[translation],
                allowed_names=desired,
                allow_list_reorder=True)

            mapping = xcontent.SourceToTargetMapping.find_mapping(
                mappings, 'choices:[0]:feedback')
            self.assertEqual(mapping.verb,
                             xcontent.SourceToTargetDiffMapping.VERB_CHANGED)
            self.assertEqual('Correct!', mapping.source_value)
            self.assertEqual('CORRECT!', mapping.target_value)

            raise Exception('Must have failed.')
            # TODO(psimakov): fix allow_list_reorder=True to stop this failure
        except NotImplementedError:
            pass
Beispiel #2
0
    def test_retranslate_already_translated_verb_same(self):
        binding = schema_fields.ValueToTypeBinding.bind_entity_to_schema(
            self.question, self.schema)
        desired = _filter(binding)
        translation = xcontent.SourceToTargetMapping('choices:[1]:feedback',
                                                     'Feedback', 'html',
                                                     'Correct!', 'CORRECT!')
        mappings = xcontent.SourceToTargetDiffMapping.map_source_to_target(
            binding, existing_mappings=[translation], allowed_names=desired)

        expected_mappings = [
            (None, xcontent.SourceToTargetDiffMapping.VERB_NEW),
            (None, xcontent.SourceToTargetDiffMapping.VERB_NEW),
            (None, xcontent.SourceToTargetDiffMapping.VERB_NEW),
            (None, xcontent.SourceToTargetDiffMapping.VERB_NEW),
            (None, xcontent.SourceToTargetDiffMapping.VERB_NEW),
            ('CORRECT!', xcontent.SourceToTargetDiffMapping.VERB_CURRENT),
            (None, xcontent.SourceToTargetDiffMapping.VERB_NEW),
            (None, xcontent.SourceToTargetDiffMapping.VERB_NEW)
        ]
        self.assertEqual(expected_mappings,
                         [(mapping.target_value, mapping.verb)
                          for mapping in mappings])

        mapping = xcontent.SourceToTargetMapping.find_mapping(
            mappings, 'choices:[1]:feedback')
        self.assertEqual(mapping.verb,
                         xcontent.SourceToTargetDiffMapping.VERB_CURRENT)
        self.assertEqual('Correct!', mapping.source_value)
        self.assertEqual('CORRECT!', translation.target_value)
Beispiel #3
0
    def test_retranslate_already_translated_verb_same(self):
        translation = xcontent.SourceToTargetMapping(
            'course:title',
            'Title',
            'string',
            'Power Searching with Google',
            'POWER SEARCHING WITH Google',
        )
        translations = [translation]

        _, mappings = self._build_mapping(translations)

        mapping = xcontent.SourceToTargetMapping.find_mapping(
            mappings, 'course:title')
        self.assertEqual(mapping.verb,
                         xcontent.SourceToTargetDiffMapping.VERB_CURRENT)
        self.assertEqual('Power Searching with Google', mapping.source_value)
        self.assertEqual('POWER SEARCHING WITH Google', mapping.target_value)

        mapping = xcontent.SourceToTargetMapping.find_mapping(
            mappings, 'course:forum_url')
        self.assertEqual(mapping.verb,
                         xcontent.SourceToTargetDiffMapping.VERB_NEW)
        self.assertEqual(None, mapping.target_value)

        mapping = xcontent.SourceToTargetMapping.find_mapping(
            mappings, 'course:locale')
        self.assertEqual(None, mapping)
Beispiel #4
0
    def test_retranslate_already_translated_verb_changed(self):
        translation = xcontent.SourceToTargetMapping(
            'course:title', 'Title', 'string',
            'Power Searching with Google (old)',
            'POWER SEARCHING WITH Google (old)')
        translations = [translation]

        _, mappings = self._build_mapping(translations)

        mapping = xcontent.SourceToTargetMapping.find_mapping(
            mappings, 'course:title')
        self.assertEqual(mapping.verb,
                         xcontent.SourceToTargetDiffMapping.VERB_CHANGED)
        self.assertEqual('Power Searching with Google', mapping.source_value)
        self.assertEqual('POWER SEARCHING WITH Google (old)',
                         mapping.target_value)
Beispiel #5
0
    def test_retranslate_already_translated_with_list_reordered(self):
        binding = schema_fields.ValueToTypeBinding.bind_entity_to_schema(
            self.question, self.schema)
        desired = _filter(binding)
        translation = xcontent.SourceToTargetMapping('choices:[0]:feedback',
                                                     'Feedback', 'html',
                                                     'Correct (old)!',
                                                     'CORRECT!')
        mappings = xcontent.SourceToTargetDiffMapping.map_source_to_target(
            binding, existing_mappings=[translation], allowed_names=desired)

        mapping = xcontent.SourceToTargetMapping.find_mapping(
            mappings, 'choices:[0]:feedback')
        self.assertEqual(mapping.verb,
                         xcontent.SourceToTargetDiffMapping.VERB_CHANGED)
        self.assertEqual('Wrong!', mapping.source_value)
        self.assertEqual('CORRECT!', mapping.target_value)
Beispiel #6
0
 def test_translations_must_have_same_type(self):
     translation = xcontent.SourceToTargetMapping(
         'course:title', 'Title', 'unknown_type',
         'Power Searching with Google', 'POWER SEARCHING WITH Google')
     errors = []
     binding, _ = self._build_mapping(translations=[translation],
                                      errors=errors)
     error_at_index = None
     for index, value_field in enumerate(binding.value_list):
         if 'course:title' == value_field.name:
             error_at_index = index
             break
     self.assertTrue(error_at_index is not None)
     self.assertEqual(error_at_index, errors[0].index)
     self.assertEqual(
         'Source and target types don\'t match: '
         'string, unknown_type.', errors[0].original_exception.message)