Exemplo n.º 1
0
 def test_out_of_order(self):
     self.assertTrue(
         TRANSLATIONS_OUT_OF_ORDER in compare_translations(
             [None, 'a', 'b', 'c'],
             ['a', 'b', 'c', None],
         ), )
     self.assertTrue(
         TRANSLATIONS_OUT_OF_ORDER in compare_translations(
             [None, 'a', 'b', 'c'],
             ['a', None, 'b', 'c'],
         ), )
Exemplo n.º 2
0
 def test_equality(self):
     self.assertTrue(
         TRANSLATIONS_EQUAL in compare_translations(
             ['a', 'b', 'c'],
             ['a', 'b', 'c'],
         ), )
     self.assertTrue(
         TRANSLATIONS_EQUAL in compare_translations(
             [None, 'a', 'b', 'c'],
             [None, 'a', 'b', 'c'],
         ), )
 def test_out_of_order(self):
     self.assertTrue(TRANSLATIONS_OUT_OF_ORDER in
                     compare_translations(
                         [None, 'a', 'b', 'c'],
                         ['a', 'b', 'c', None],
                     ),
                     )
     self.assertTrue(TRANSLATIONS_OUT_OF_ORDER in
                     compare_translations(
                         [None, 'a', 'b', 'c'],
                         ['a', None, 'b', 'c'],
                     ),
                     )
 def test_equality(self):
     self.assertTrue(TRANSLATIONS_EQUAL in
                     compare_translations(
                         ['a', 'b', 'c'],
                         ['a', 'b', 'c'],
                     ),
                     )
     self.assertTrue(TRANSLATIONS_EQUAL in
                     compare_translations(
                         [None, 'a', 'b', 'c'],
                         [None, 'a', 'b', 'c'],
                     ),
                     )
Exemplo n.º 5
0
 def update_translation_list(self, translation_list):
     existing_ts = self.content.get('translations', [])
     params = compare_translations(existing_ts, translation_list)
     if None in translation_list and translation_list[0] is not None:
         raise ValueError('Unnamed translation must be first in '
                          'list of translations')
     if TRANSLATIONS_OUT_OF_ORDER in params:
         self._reorder_translations(self.content, translation_list)
     elif TRANSLATION_RENAMED in params:
         _change = params[TRANSLATION_RENAMED]['changes'][0]
         self._rename_translation(self.content, _change['from'],
                                  _change['to'])
     elif TRANSLATION_ADDED in params:
         if None in existing_ts:
             raise ValueError(
                 'cannot add translation if an unnamed translation exists')
         self._prepend_translation(self.content, params[TRANSLATION_ADDED])
     elif TRANSLATION_DELETED in params:
         if params[TRANSLATION_DELETED] != existing_ts[-1]:
             raise ValueError(
                 'you can only delete the last translation of the asset')
         self._remove_last_translation(self.content)
     else:
         for chg in [
                 TRANSLATIONS_MULTIPLE_CHANGES,
                 TRANSLATION_CHANGE_UNSUPPORTED,
         ]:
             if chg in params:
                 raise ValueError('Unsupported change: "{}": {}'.format(
                     chg, params[chg]))
Exemplo n.º 6
0
    def test_translation_renamed(self):
        _renamed_params = compare_translations(
            [None, 'a', 'b', 'c'],
            [None, 'a', 'b', 'Z'],
        )

        self.assertTrue(TRANSLATION_RENAMED in _renamed_params)
        first_change = _renamed_params[TRANSLATION_RENAMED]['changes'][0]
        self.assertEqual(first_change['index'], 3)
        self.assertEqual(first_change['from'], 'c')
        self.assertEqual(first_change['to'], 'Z')
    def test_translation_renamed(self):
        _renamed_params = compare_translations(
            [None, 'a', 'b', 'c'],
            [None, 'a', 'b', 'Z'],
        )

        self.assertTrue(TRANSLATION_RENAMED in _renamed_params)
        first_change = _renamed_params[TRANSLATION_RENAMED]['changes'][0]
        self.assertEqual(first_change['index'], 3)
        self.assertEqual(first_change['from'], 'c')
        self.assertEqual(first_change['to'], 'Z')
Exemplo n.º 8
0
 def test_translations_too_changed(self):
     _params = compare_translations(
         [None, 'a', 'b', 'c'],
         [None, 'a', 'y', 'z'],
     )
     self.assertTrue(TRANSLATIONS_MULTIPLE_CHANGES in _params)
 def test_translations_too_changed(self):
     _params = compare_translations(
         [None, 'a', 'b', 'c'],
         [None, 'a', 'y', 'z'],
     )
     self.assertTrue(TRANSLATIONS_MULTIPLE_CHANGES in _params)