def test_handle_legalcodes_with_updated_translations(self):
        helper = TransifexHelper()
        dummy_repo = DummyRepo("/trans/repo")

        # No legalcodes, shouldn't call anything or return anything
        result = helper.handle_legalcodes_with_updated_translations(
            dummy_repo, []
        )
        self.assertEqual([], result)

        # legalcodes for two branches
        legalcode1 = LegalCodeFactory(
            license__version="4.0",
            license__license_code="by-nc",
            language_code="fr",
        )
        legalcode2 = LegalCodeFactory(
            license__version="4.0",
            license__license_code="by-nd",
            language_code="de",
        )
        with mpo(helper, "handle_updated_translation_branch") as mock_handle:
            result = helper.handle_legalcodes_with_updated_translations(
                dummy_repo, [legalcode1, legalcode2]
            )
        self.assertEqual(
            [legalcode1.branch_name(), legalcode2.branch_name()], result
        )
        self.assertEqual(
            [
                mock.call(dummy_repo, [legalcode1]),
                mock.call(dummy_repo, [legalcode2]),
            ],
            mock_handle.call_args_list,
        )
示例#2
0
 def test_branch_name(self):
     legalcode = LegalCodeFactory(license__version="4.0",
                                  license__license_code="by-sa",
                                  language_code="de")
     self.assertEqual("cc4-de", legalcode.branch_name())
     legalcode = LegalCodeFactory(license__version="3.5",
                                  license__license_code="other",
                                  language_code="de")
     self.assertEqual("other-35-de", legalcode.branch_name())
     legalcode = LegalCodeFactory(
         license__version="3.5",
         license__license_code="other",
         language_code="de",
         license__jurisdiction_code="xyz",
     )
     self.assertEqual("other-35-de-xyz", legalcode.branch_name())
 def test_handle_updated_translation_branch(self):
     helper = TransifexHelper()
     dummy_repo = DummyRepo("/trans/repo")
     result = helper.handle_updated_translation_branch(dummy_repo, [])
     self.assertIsNone(result)
     legalcode1 = LegalCodeFactory(
         license__version="4.0",
         license__license_code="by-nc",
         language_code="fr",
     )
     legalcode2 = LegalCodeFactory(
         license__version="4.0",
         license__license_code="by-nd",
         language_code="fr",
     )
     with mp("licenses.transifex.setup_local_branch") as mock_setup, mpo(
         helper, "update_branch_for_legalcode"
     ) as mock_update_branch, mp(
         "licenses.transifex.call_command"
     ) as mock_call_command, mp(
         "licenses.transifex.commit_and_push_changes"
     ) as mock_commit:
         # setup_local_branch
         # update_branch_for_legalcode
         # commit_and_push_changes
         # branch_object.save()
         result = helper.handle_updated_translation_branch(
             dummy_repo, [legalcode1, legalcode2]
         )
     self.assertIsNone(result)
     mock_setup.assert_called_with(dummy_repo, legalcode1.branch_name())
     # Should have published static files for this branch
     expected = [
         mock.call("publish", branch_name=legalcode1.branch_name()),
     ]
     self.assertEqual(expected, mock_call_command.call_args_list)
     trb = TranslationBranch.objects.get()
     expected = [
         mock.call(dummy_repo, legalcode1, trb),
         mock.call(dummy_repo, legalcode2, trb),
     ]
     self.assertEqual(expected, mock_update_branch.call_args_list)
     mock_commit.assert_called_with(
         dummy_repo, "Translation changes from Transifex.", "", push=True
     )
 def test_update_branch_for_legalcode(self):
     helper = TransifexHelper()
     dummy_repo = DummyRepo("/trans/repo")
     legalcode = LegalCodeFactory(
         license__version="4.0",
         license__license_code="by-nc",
         language_code="fr",
     )
     helper._stats = {
         legalcode.license.resource_slug: {
             legalcode.language_code: {
                 "translated": {
                     "last_activity": now().isoformat(),
                 }
             }
         }
     }
     trb = TranslationBranch.objects.create(
         branch_name=legalcode.branch_name(),
         version=legalcode.license.version,
         language_code=legalcode.language_code,
         complete=False,
     )
     content = b"wxyz"
     # transifex_get_pofile_content
     # save_content_as_pofile_and_mofile
     with mpo(
         helper, "transifex_get_pofile_content"
     ) as mock_get_content, mp(
         "licenses.transifex.save_content_as_pofile_and_mofile"
     ) as mock_save:
         mock_get_content.return_value = content
         mock_save.return_value = [legalcode.translation_filename()]
         result = helper.update_branch_for_legalcode(
             dummy_repo, legalcode, trb
         )
     self.assertIsNone(result)
     mock_get_content.assert_called_with(
         legalcode.license.resource_slug, legalcode.language_code
     )
     mock_save.assert_called_with(legalcode.translation_filename(), content)
     self.assertEqual({legalcode}, set(trb.legalcodes.all()))
     relpath = os.path.relpath(
         legalcode.translation_filename(),
         settings.TRANSLATION_REPOSITORY_DIRECTORY,
     )
     dummy_repo.index.add.assert_called_with([relpath])