예제 #1
0
 def test_repository_type_first(self):
     """
     If a project has repos, return the type of the repo created
     first.
     """
     project = ProjectFactory.create(repositories=[])
     RepositoryFactory.create(project=project, type=Repository.GIT)
     RepositoryFactory.create(project=project, type=Repository.HG)
     assert_equal(project.repository_type, Repository.GIT)
예제 #2
0
 def test_repository_type_first(self):
     """
     If a project has repos, return the type of the repo created
     first.
     """
     project = ProjectFactory.create(repositories=[])
     RepositoryFactory.create(project=project, type=Repository.GIT)
     RepositoryFactory.create(project=project, type=Repository.HG)
     assert_equal(project.repository_type, Repository.GIT)
예제 #3
0
    def test_pull_multi_locale(self):
        """
        If the repo is multi-locale, pull all of the repos for the
        active locales.
        """
        locale1 = LocaleFactory.create(code='locale1')
        locale2 = LocaleFactory.create(code='locale2')
        repo = RepositoryFactory.create(
            type=Repository.GIT,
            url='https://example.com/{locale_code}/',
            project__locales=[locale1, locale2])

        repo.locale_url = lambda locale: 'https://example.com/' + locale.code
        repo.locale_checkout_path = lambda locale: '/media/' + locale.code

        with patch('pontoon.base.models.update_from_vcs') as update_from_vcs, \
             patch('pontoon.base.models.get_revision') as mock_get_revision:
            # Return path as the revision so different locales return
            # different values.
            mock_get_revision.side_effect = lambda type, path: path

            assert_equal(repo.pull(), {
                'locale1': '/media/locale1',
                'locale2': '/media/locale2'
            })
            update_from_vcs.assert_has_calls([
                call(Repository.GIT, 'https://example.com/locale1',
                     '/media/locale1'),
                call(Repository.GIT, 'https://example.com/locale2',
                     '/media/locale2')
            ])
예제 #4
0
    def test_finished(self):
        sync_log = SyncLogFactory.create()

        # Create repo without existing log so sync is unfinished.
        repo = RepositoryFactory.create()
        project_sync_log = ProjectSyncLogFactory.create(
            sync_log=sync_log, project__repositories=[repo])

        # Sync isn't finished until all repos are finished.
        assert_false(sync_log.finished)

        repo_log = RepositorySyncLogFactory.create(
            repository=repo,
            project_sync_log=project_sync_log,
            start_time=aware_datetime(2015, 1, 1),
            end_time=None
        )
        del sync_log.finished
        assert_false(sync_log.finished)

        repo_log.end_time = aware_datetime(2015, 1, 2)
        repo_log.save()

        del sync_log.finished
        assert_true(sync_log.finished)
예제 #5
0
    def test_finished(self):
        sync_log = SyncLogFactory.create()

        # Create repo without existing log so sync is unfinished.
        repo = RepositoryFactory.create()
        project_sync_log = ProjectSyncLogFactory.create(
            sync_log=sync_log, project__repositories=[repo]
        )

        # Sync isn't finished until all repos are finished.
        assert not sync_log.finished

        repo_log = RepositorySyncLogFactory.create(
            repository=repo,
            project_sync_log=project_sync_log,
            start_time=aware_datetime(2015, 1, 1),
            end_time=None,
        )
        del sync_log.finished
        assert not sync_log.finished

        repo_log.end_time = aware_datetime(2015, 1, 2)
        repo_log.save()

        del sync_log.finished
        assert sync_log.finished
예제 #6
0
    def setUp(self):
        self.locale, _ = Locale.objects.get_or_create(code='fr')

        self.repository = RepositoryFactory()
        self.db_project = ProjectFactory.create(
            repositories=[self.repository],
        )

        checkout_path_patch = patch.object(
            Repository,
            'checkout_path',
            new_callable=PropertyMock,
            return_value=PROJECT_CONFIG_CHECKOUT_PATH
        )
        self.mock_checkout_path = checkout_path_patch.start()
        self.addCleanup(checkout_path_patch.stop)

        self.resource_strings = ResourceFactory.create(
            project=self.db_project,
            path='values/strings.properties',
        )
        self.resource_strings_reality = ResourceFactory.create(
            project=self.db_project,
            path='values/strings_reality.properties',
        )

        # Make sure VCSConfiguration instance is initialized
        self.db_project.configuration_file = 'l10n.toml'
        self.vcs_project = VCSProject(self.db_project)

        self.vcs_project.configuration.configuration_path = os.path.join(
            PROJECT_CONFIG_CHECKOUT_PATH,
            self.db_project.configuration_file,
        )
예제 #7
0
    def test_pull_multi_locale(self):
        """
        If the repo is multi-locale, pull all of the repos for the
        active locales.
        """
        locale1 = LocaleFactory.create(code='locale1')
        locale2 = LocaleFactory.create(code='locale2')
        repo = RepositoryFactory.create(
            type=Repository.GIT,
            url='https://example.com/{locale_code}/',
            project__locales=[locale1, locale2]
        )

        repo.locale_url = lambda locale: 'https://example.com/' + locale.code
        repo.locale_checkout_path = lambda locale: '/media/' + locale.code

        with patch('pontoon.base.models.update_from_vcs') as update_from_vcs, \
             patch('pontoon.base.models.get_revision') as mock_get_revision:
            # Return path as the revision so different locales return
            # different values.
            mock_get_revision.side_effect = lambda type, path: path

            assert_equal(repo.pull(), {
                'locale1': '/media/locale1',
                'locale2': '/media/locale2'
            })
            update_from_vcs.assert_has_calls([
                call(Repository.GIT, 'https://example.com/locale1', '/media/locale1'),
                call(Repository.GIT, 'https://example.com/locale2', '/media/locale2')
            ])
예제 #8
0
    def test_status(self):
        repo = RepositoryFactory.create()
        project_sync_log = ProjectSyncLogFactory.create(
            project__repositories=[repo], skipped=False
        )

        # Repos aren't finished, status should be in-progress.
        assert project_sync_log.status == ProjectSyncLog.IN_PROGRESS

        # Once repo is finished, status should be synced.
        RepositorySyncLogFactory.create(
            repository=repo,
            project_sync_log=project_sync_log,
            start_time=aware_datetime(2015, 1, 1),
            end_time=aware_datetime(2015, 1, 1, 1),
        )

        del project_sync_log.finished
        del project_sync_log.status
        assert project_sync_log.status == ProjectSyncLog.SYNCED

        # Skipped projects are just "skipped".
        skipped_log = ProjectSyncLogFactory.create(
            project__repositories=[repo],
            skipped=True,
        )

        assert skipped_log.status == ProjectSyncLog.SKIPPED
예제 #9
0
    def test_locale_checkout_path(self):
        """Append the locale code the the project's checkout_path."""
        repo = RepositoryFactory.create(url="https://example.com/path/{locale_code}/", project__slug="test-project")
        locale = LocaleFactory.create(code="test-locale")

        with self.settings(MEDIA_ROOT="/media/root"):
            assert_equal(repo.locale_checkout_path(locale), "/media/root/projects/test-project/path/test-locale")
예제 #10
0
    def test_status(self):
        repo = RepositoryFactory.create()
        project_sync_log = ProjectSyncLogFactory.create(
            project__repositories=[repo],
            skipped=False
        )

        # Repos aren't finished, status should be in-progress.
        assert_equal(project_sync_log.status, ProjectSyncLog.IN_PROGRESS)

        # Once repo is finished, status should be synced.
        RepositorySyncLogFactory.create(
            repository=repo,
            project_sync_log=project_sync_log,
            start_time=aware_datetime(2015, 1, 1),
            end_time=aware_datetime(2015, 1, 1, 1),
        )

        del project_sync_log.finished
        del project_sync_log.status
        assert_equal(project_sync_log.status, ProjectSyncLog.SYNCED)

        # Skipped projects are just "skipped".
        skipped_log = ProjectSyncLogFactory.create(
            project__repositories=[repo],
            skipped=True,
        )

        assert_equal(skipped_log.status, ProjectSyncLog.SKIPPED)
예제 #11
0
    def test_pull_multi_locale(self):
        """
        If the repo is multi-locale, pull all of the repos for the
        active locales.
        """
        locale1 = LocaleFactory.create(code="locale1")
        locale2 = LocaleFactory.create(code="locale2")
        repo = RepositoryFactory.create(
            type=Repository.GIT, url="https://example.com/{locale_code}/", project__locales=[locale1, locale2]
        )

        repo.locale_url = lambda locale: "https://example.com/" + locale.code
        repo.locale_checkout_path = lambda locale: "/media/" + locale.code

        with patch("pontoon.base.models.update_from_vcs") as update_from_vcs, patch(
            "pontoon.base.models.get_revision"
        ) as mock_get_revision:
            # Return path as the revision so different locales return
            # different values.
            mock_get_revision.side_effect = lambda type, path: path

            assert_equal(repo.pull(), {"locale1": "/media/locale1", "locale2": "/media/locale2"})
            update_from_vcs.assert_has_calls(
                [
                    call(Repository.GIT, "https://example.com/locale1", "/media/locale1"),
                    call(Repository.GIT, "https://example.com/locale2", "/media/locale2"),
                ]
            )
예제 #12
0
 def test_checkout_path_multi_locale(self):
     """
     The checkout_path for multi-locale repos should not include the
     locale_code variable.
     """
     repo = RepositoryFactory.create(url="https://example.com/path/to/{locale_code}/", project__slug="test-project")
     with self.settings(MEDIA_ROOT="/media/root"):
         assert_equal(repo.checkout_path, "/media/root/projects/test-project/path/to")
예제 #13
0
    def test_locale_url(self):
        """Fill in the {locale_code} variable in the URL."""
        repo = RepositoryFactory.create(
            url='https://example.com/path/to/{locale_code}/',
        )
        locale = LocaleFactory.create(code='test-locale')

        assert_equal(repo.locale_url(locale), 'https://example.com/path/to/test-locale/')
예제 #14
0
    def test_url_for_path_no_match(self):
        """
        If no active locale matches the given path, raise a ValueError.
        """
        repo = RepositoryFactory.create(project__locales=[], url="https://example.com/path/to/{locale_code}/")

        with assert_raises(ValueError):
            repo.url_for_path("/media/root/path/to/match/foo/bar.po")
예제 #15
0
 def test_pull(self):
     repo = RepositoryFactory.create(type=Repository.GIT, url="https://example.com")
     with patch("pontoon.base.models.update_from_vcs") as update_from_vcs, patch(
         "pontoon.base.models.get_revision"
     ) as mock_get_revision:
         mock_get_revision.return_value = "asdf"
         assert_equal(repo.pull(), {"single_locale": "asdf"})
         update_from_vcs.assert_called_with(Repository.GIT, "https://example.com", repo.checkout_path)
예제 #16
0
 def test_can_commit_false(self):
     """
     can_commit should be False if there are no repo that can be
     committed to.
     """
     repo = RepositoryFactory.build(type=Repository.FILE)
     project = ProjectFactory.create(repositories=[repo])
     assert_false(project.can_commit)
예제 #17
0
 def test_can_commit_false(self):
     """
     can_commit should be False if there are no repo that can be
     committed to.
     """
     repo = RepositoryFactory.build(type=Repository.FILE)
     project = ProjectFactory.create(repositories=[repo])
     assert_false(project.can_commit)
예제 #18
0
 def test_can_commit_true(self):
     """
     can_commit should be True if there is a repo that can be
     committed to.
     """
     repo = RepositoryFactory.build(type=Repository.GIT)
     project = ProjectFactory.create(repositories=[repo])
     assert_true(project.can_commit)
예제 #19
0
 def test_can_commit_true(self):
     """
     can_commit should be True if there is a repo that can be
     committed to.
     """
     repo = RepositoryFactory.build(type=Repository.GIT)
     project = ProjectFactory.create(repositories=[repo])
     assert_true(project.can_commit)
예제 #20
0
 def test_checkout_path(self):
     """checkout_path should be determined by the repo URL."""
     repo = RepositoryFactory.create(
         url='https://example.com/path/to/locale/',
         project__slug='test-project')
     with self.settings(MEDIA_ROOT='/media/root'):
         assert_equal(repo.checkout_path,
                      '/media/root/projects/test-project/path/to/locale')
예제 #21
0
    def test_locale_url(self):
        """Fill in the {locale_code} variable in the URL."""
        repo = RepositoryFactory.create(
            url='https://example.com/path/to/{locale_code}/', )
        locale = LocaleFactory.create(code='test-locale')

        assert_equal(repo.locale_url(locale),
                     'https://example.com/path/to/test-locale/')
예제 #22
0
 def test_pull(self):
     repo = RepositoryFactory.create(type=Repository.GIT, url='https://example.com')
     with patch('pontoon.base.models.update_from_vcs') as update_from_vcs:
         repo.pull()
         update_from_vcs.assert_called_with(
             Repository.GIT,
             'https://example.com',
             repo.checkout_path
         )
예제 #23
0
    def test_end_time_unfinished(self):
        """If a job is unfinished, it's end_time is None."""
        sync_log = SyncLogFactory.create()

        # Create repo without existing log so sync is unfinished.
        repo = RepositoryFactory.create()
        ProjectSyncLogFactory.create(sync_log=sync_log, project__repositories=[repo])

        assert_is_none(sync_log.end_time)
예제 #24
0
 def test_repository_for_path(self):
     """
     Return the first repo found with a checkout path that contains
     the given path.
     """
     repo1, repo2, repo3 = RepositoryFactory.build_batch(3)
     project = ProjectFactory.create(repositories=[repo1, repo2, repo3])
     path = os.path.join(repo2.checkout_path, 'foo', 'bar')
     assert_equal(project.repository_for_path(path), repo2)
예제 #25
0
    def test_end_time_unfinished(self):
        """If a job is unfinished, it's end_time is None."""
        sync_log = SyncLogFactory.create()

        # Create repo without existing log so sync is unfinished.
        repo = RepositoryFactory.create()
        ProjectSyncLogFactory.create(sync_log=sync_log, project__repositories=[repo])

        assert sync_log.end_time is None
예제 #26
0
 def test_repository_for_path(self):
     """
     Return the first repo found with a checkout path that contains
     the given path.
     """
     repo1, repo2, repo3 = RepositoryFactory.build_batch(3)
     project = ProjectFactory.create(repositories=[repo1, repo2, repo3])
     path = os.path.join(repo2.checkout_path, "foo", "bar")
     assert_equal(project.repository_for_path(path), repo2)
예제 #27
0
 def test_checkout_path_source_repo(self):
     """
     The checkout_path for a source repo should end with a templates
     directory.
     """
     repo = RepositoryFactory.create(
         url="https://example.com/path/to/locale/", project__slug="test-project", source_repo=True
     )
     with self.settings(MEDIA_ROOT="/media/root"):
         assert_equal(repo.checkout_path, "/media/root/projects/test-project/path/to/locale/templates")
예제 #28
0
 def test_pull(self):
     repo = RepositoryFactory.create(type=Repository.GIT,
                                     url='https://example.com')
     with patch('pontoon.base.models.update_from_vcs') as update_from_vcs, \
          patch('pontoon.base.models.get_revision') as mock_get_revision:
         mock_get_revision.return_value = 'asdf'
         assert_equal(repo.pull(), {'single_locale': 'asdf'})
         update_from_vcs.assert_called_with(Repository.GIT,
                                            'https://example.com',
                                            repo.checkout_path)
예제 #29
0
 def test_commit(self):
     repo = RepositoryFactory.create(type=Repository.GIT, url='https://example.com')
     with patch('pontoon.base.models.commit_to_vcs') as commit_to_vcs:
         repo.commit('message', 'author', 'path')
         commit_to_vcs.assert_called_with(
             Repository.GIT,
             'path',
             'message',
             'author',
             'https://example.com',
         )
예제 #30
0
 def test_end_time_skipped(self):
     """
     If a sync is skipped, it's end_time is self.skipped_end_time.
     """
     repo = RepositoryFactory.create()
     project_sync_log = ProjectSyncLogFactory.create(
         project__repositories=[repo],
         skipped=True,
         skipped_end_time=aware_datetime(2015, 1, 1),
     )
     assert_equal(project_sync_log.end_time, aware_datetime(2015, 1, 1))
예제 #31
0
    def test_create_project_log(self):
        assert_false(ProjectSyncLog.objects.exists())

        repo = RepositoryFactory.create()
        self.db_project.repositories = [repo]
        self.db_project.save()
        sync_project(self.db_project.pk, self.sync_log.pk)

        log = ProjectSyncLog.objects.get(project=self.db_project)
        assert_equal(self.mock_sync_translations.delay.call_args[0][1], repo.pk)
        assert_equal(self.mock_sync_translations.delay.call_args[0][2], log.pk)
예제 #32
0
 def test_pull(self):
     repo = RepositoryFactory.create(type=Repository.GIT, url='https://example.com')
     with patch('pontoon.base.models.update_from_vcs') as update_from_vcs, \
          patch('pontoon.base.models.get_revision') as mock_get_revision:
         mock_get_revision.return_value = 'asdf'
         assert_equal(repo.pull(), {'single_locale': 'asdf'})
         update_from_vcs.assert_called_with(
             Repository.GIT,
             'https://example.com',
             repo.checkout_path
         )
예제 #33
0
    def test_locale_checkout_path(self):
        """Append the locale code the the project's checkout_path."""
        repo = RepositoryFactory.create(
            url='https://example.com/path/{locale_code}/',
            project__slug='test-project',
        )
        locale = LocaleFactory.create(code='test-locale')

        with self.settings(MEDIA_ROOT='/media/root'):
            assert_equal(repo.locale_checkout_path(locale),
                         '/media/root/projects/test-project/path/test-locale')
예제 #34
0
    def test_url_for_path_no_match(self):
        """
        If no active locale matches the given path, raise a ValueError.
        """
        repo = RepositoryFactory.create(
            project__locales=[],
            url='https://example.com/path/to/{locale_code}/',
        )

        with assert_raises(ValueError):
            repo.url_for_path('/media/root/path/to/match/foo/bar.po')
예제 #35
0
 def test_end_time_skipped(self):
     """
     If a sync is skipped, it's end_time is self.skipped_end_time.
     """
     repo = RepositoryFactory.create()
     project_sync_log = ProjectSyncLogFactory.create(
         project__repositories=[repo],
         skipped=True,
         skipped_end_time=aware_datetime(2015, 1, 1),
     )
     assert_equal(project_sync_log.end_time, aware_datetime(2015, 1, 1))
예제 #36
0
 def test_checkout_path(self):
     """checkout_path should be determined by the repo URL."""
     repo = RepositoryFactory.create(
         url='https://example.com/path/to/locale/',
         project__slug='test-project'
     )
     with self.settings(MEDIA_ROOT='/media/root'):
         assert_equal(
             repo.checkout_path,
             '/media/root/projects/test-project/path/to/locale'
         )
예제 #37
0
 def test_checkout_path_multi_locale(self):
     """
     The checkout_path for multi-locale repos should not include the
     locale_code variable.
     """
     repo = RepositoryFactory.create(
         url='https://example.com/path/to/{locale_code}/',
         project__slug='test-project',
     )
     with self.settings(MEDIA_ROOT='/media/root'):
         assert_equal(repo.checkout_path,
                      '/media/root/projects/test-project/path/to')
예제 #38
0
    def test_create_project_log(self):
        assert_false(RepositorySyncLog.objects.exists())

        repo = RepositoryFactory.create()
        self.db_project.repositories = [repo]
        self.db_project.save()

        sync_project_repo(self.db_project.pk, self.repository.pk,
                          self.project_sync_log.pk, self.now)

        log = RepositorySyncLog.objects.get(repository=self.repository)
        assert_equal(log.repository, self.repository)
예제 #39
0
 def test_commit(self):
     repo = RepositoryFactory.create(type=Repository.GIT,
                                     url='https://example.com')
     with patch('pontoon.base.models.commit_to_vcs') as commit_to_vcs:
         repo.commit('message', 'author', 'path')
         commit_to_vcs.assert_called_with(
             Repository.GIT,
             'path',
             'message',
             'author',
             'https://example.com',
         )
예제 #40
0
    def test_create_project_log(self):
        assert_false(RepositorySyncLog.objects.exists())

        repo = RepositoryFactory.create()
        self.db_project.repositories = [repo]
        self.db_project.save()

        sync_project_repo(self.db_project.pk, self.repository.pk,
                          self.project_sync_log.pk, self.now)

        log = RepositorySyncLog.objects.get(repository=self.repository)
        assert_equal(log.repository, self.repository)
예제 #41
0
 def test_checkout_path_source_repo(self):
     """
     The checkout_path for a source repo should end with a templates
     directory.
     """
     repo = RepositoryFactory.create(
         url='https://example.com/path/to/locale/',
         project__slug='test-project',
         source_repo=True)
     with self.settings(MEDIA_ROOT='/media/root'):
         assert_equal(
             repo.checkout_path,
             '/media/root/projects/test-project/path/to/locale/templates')
예제 #42
0
    def test_end_time(self):
        """
        Return the latest end time among repo sync logs for this log.
        """
        project = ProjectFactory.create(repositories=[])
        source_repo, repo1, repo2 = RepositoryFactory.create_batch(3, project=project)
        project_sync_log = ProjectSyncLogFactory.create(project=project)

        RepositorySyncLogFactory.create(project_sync_log=project_sync_log,
                                        repository=repo1,
                                        end_time=aware_datetime(2015, 1, 1))

        assert_equal(project_sync_log.end_time, aware_datetime(2015, 1, 1))
예제 #43
0
    def test_end_time(self):
        """
        Return the latest end time among repo sync logs for this log.
        """
        project = ProjectFactory.create(repositories=[])
        source_repo, repo1, repo2 = RepositoryFactory.create_batch(3, project=project)
        project_sync_log = ProjectSyncLogFactory.create(project=project)

        RepositorySyncLogFactory.create(project_sync_log=project_sync_log,
                                        repository=repo1,
                                        end_time=aware_datetime(2015, 1, 1))

        assert_equal(project_sync_log.end_time, aware_datetime(2015, 1, 1))
예제 #44
0
    def test_locale_checkout_path(self):
        """Append the locale code the the project's checkout_path."""
        repo = RepositoryFactory.create(
            url='https://example.com/path/',
            project__slug='test-project',
            multi_locale=True
        )
        locale = LocaleFactory.create(code='test-locale')

        with self.settings(MEDIA_ROOT='/media/root'):
            assert_equal(
                repo.locale_checkout_path(locale),
                '/media/root/projects/test-project/path/test-locale'
            )
예제 #45
0
    def test_commit_multi_locale(self):
        """
        If the repo is multi-locale, use the url from url_for_path for
        committing.
        """
        repo = RepositoryFactory.create(type=Repository.GIT, url="https://example.com/{locale_code}/")

        repo.url_for_path = Mock(return_value="https://example.com/for_path")
        with patch("pontoon.base.models.commit_to_vcs") as commit_to_vcs:
            repo.commit("message", "author", "path")
            commit_to_vcs.assert_called_with(
                Repository.GIT, "path", "message", "author", "https://example.com/for_path"
            )
            repo.url_for_path.assert_called_with("path")
예제 #46
0
    def test_create_repository_log(self):
        assert_false(RepositorySyncLog.objects.exists())

        repo = RepositoryFactory.create()
        self.db_project.repositories = [repo]
        self.db_project.save()
        self.mock_pull_changes.return_value = [True, {
            repo.pk: Locale.objects.filter(pk=self.translated_locale.pk)
        }]

        sync_translations(self.db_project.pk, self.project_sync_log.pk,
                          self.now, self.mock_changes)

        log = RepositorySyncLog.objects.get(repository=repo.pk)
        assert_equal(log.repository, repo)
예제 #47
0
 def test_checkout_path_source_repo(self):
     """
     The checkout_path for a source repo should end with an en-US
     directory.
     """
     repo = RepositoryFactory.create(
         url='https://example.com/path/to/locale/',
         project__slug='test-project',
         source_repo=True
     )
     with self.settings(MEDIA_ROOT='/media/root'):
         assert_equal(
             repo.checkout_path,
             '/media/root/projects/test-project/path/to/locale/en-US'
         )
예제 #48
0
    def test_create_repository_log(self):
        assert not RepositorySyncLog.objects.exists()

        repo = RepositoryFactory.create()
        self.db_project.repositories.set([repo])
        self.db_project.save()
        self.mock_pull_locale_repo_changes.return_value = [
            True,
            {repo.pk: Locale.objects.filter(pk=self.translated_locale.pk)},
        ]

        sync_translations(self.db_project, self.project_sync_log, self.now, True)

        log = RepositorySyncLog.objects.get(repository=repo.pk)
        assert log.repository == repo
예제 #49
0
    def test_create_repository_log(self):
        assert_false(RepositorySyncLog.objects.exists())

        repo = RepositoryFactory.create()
        self.db_project.repositories = [repo]
        self.db_project.save()
        self.mock_pull_changes.return_value = [
            True,
            {repo.pk: Locale.objects.filter(pk=self.translated_locale.pk)},
        ]

        sync_translations(self.db_project.pk, self.project_sync_log.pk, self.now)

        log = RepositorySyncLog.objects.get(repository=repo.pk)
        assert_equal(log.repository, repo)
예제 #50
0
    def test_url_for_path(self):
        """
        Return the first locale_checkout_path for locales active for the
        repo's project that matches the given path.
        """
        matching_locale = LocaleFactory.create(code="match")
        non_matching_locale = LocaleFactory.create(code="nomatch")
        repo = RepositoryFactory.create(
            project__locales=[matching_locale, non_matching_locale],
            project__slug="test-project",
            url="https://example.com/path/to/{locale_code}/",
        )

        with self.settings(MEDIA_ROOT="/media/root"):
            test_path = "/media/root/projects/test-project/path/to/match/foo/bar.po"
            assert_equal(repo.url_for_path(test_path), "https://example.com/path/to/match/")
예제 #51
0
    def test_resource_for_path_region_properties(self):
        """
        If a project has a repository_url in pontoon.base.MOZILLA_REPOS,
        resources_for_path should ignore files named
        "region.properties".
        """
        url = "https://moz.example.com"
        self.project.repositories.all().delete()
        self.project.repositories.add(RepositoryFactory.build(url=url))

        with patch("pontoon.sync.vcs_models.os", wraps=os) as mock_os, patch(
            "pontoon.sync.vcs_models.MOZILLA_REPOS", [url]
        ):
            mock_os.walk.return_value = [("/root", [], ["foo.pot", "region.properties"])]

            assert_equal(list(self.vcs_project.resources_for_path("/root")), [os.path.join("/root", "foo.pot")])
예제 #52
0
    def test_resource_for_path_region_properties(self):
        """
        If a project has a repository_url in pontoon.base.MOZILLA_REPOS,
        resources_for_path should ignore files named
        "region.properties".
        """
        url = 'https://moz.example.com'
        self.project.repositories.all().delete()
        self.project.repositories.add(RepositoryFactory.build(url=url))

        with patch('pontoon.sync.vcs_models.os', wraps=os) as mock_os, \
             patch('pontoon.sync.vcs_models.MOZILLA_REPOS', [url]):
            mock_os.walk.return_value = [('/root', [],
                                          ['foo.pot', 'region.properties'])]

            assert_equal(list(self.vcs_project.resources_for_path('/root')),
                         [os.path.join('/root', 'foo.pot')])
예제 #53
0
    def test_url_for_path(self):
        """
        Return the first locale_checkout_path for locales active for the
        repo's project that matches the given path.
        """
        matching_locale = LocaleFactory.create(code='match')
        non_matching_locale = LocaleFactory.create(code='nomatch')
        repo = RepositoryFactory.create(
            project__locales=[matching_locale, non_matching_locale],
            project__slug='test-project',
            url='https://example.com/path/to/{locale_code}/',
        )

        with self.settings(MEDIA_ROOT='/media/root'):
            test_path = '/media/root/projects/test-project/path/to/match/foo/bar.po'
            assert_equal(repo.url_for_path(test_path),
                         'https://example.com/path/to/match/')
예제 #54
0
    def test_url_for_path(self):
        """
        Return the first locale_checkout_path for locales active for the
        repo's project that matches the given path.
        """
        matching_locale = LocaleFactory.create(code='match')
        non_matching_locale = LocaleFactory.create(code='nomatch')
        repo = RepositoryFactory.create(
            project__locales=[matching_locale, non_matching_locale],
            project__slug='test-project',
            url='https://example.com/path/to/{locale_code}/',
            multi_locale=True
        )

        with self.settings(MEDIA_ROOT='/media/root'):
            test_path = '/media/root/projects/test-project/path/to/match/foo/bar.po'
            assert_equal(repo.url_for_path(test_path), 'https://example.com/path/to/match/')
예제 #55
0
    def test_finished(self):
        repo = RepositoryFactory.create()
        project_sync_log = ProjectSyncLogFactory.create(
            project__repositories=[repo])

        # Sync isn't finished until all repos are finished.
        assert_false(project_sync_log.finished)

        repo_log = RepositorySyncLogFactory.create(
            repository=repo,
            project_sync_log=project_sync_log,
            start_time=aware_datetime(2015, 1, 1),
            end_time=None)
        assert_false(project_sync_log.finished)

        repo_log.end_time = aware_datetime(2015, 1, 2)
        repo_log.save()
        assert_true(project_sync_log.finished)
예제 #56
0
    def setUp(self):
        self.locale, _ = Locale.objects.get_or_create(code='fr')

        self.repository = RepositoryFactory()
        self.db_project = ProjectFactory.create(repositories=[self.repository
                                                              ], )

        self.resource_strings = ResourceFactory.create(
            project=self.db_project,
            path='strings.properties',
        )
        self.resource_strings_reality = ResourceFactory.create(
            project=self.db_project,
            path='strings_reality.properties',
        )

        # Make sure VCSConfiguration instance is initialized
        self.db_project.configuration_file = 'l10n.toml'
        self.vcs_project = VCSProject(self.db_project)
예제 #57
0
    def test_commit_multi_locale(self):
        """
        If the repo is multi-locale, use the url from url_for_path for
        committing.
        """
        repo = RepositoryFactory.create(
            type=Repository.GIT,
            url='https://example.com/{locale_code}/',
        )

        repo.url_for_path = Mock(return_value='https://example.com/for_path')
        with patch('pontoon.base.models.commit_to_vcs') as commit_to_vcs:
            repo.commit('message', 'author', 'path')
            commit_to_vcs.assert_called_with(
                Repository.GIT,
                'path',
                'message',
                'author',
                'https://example.com/for_path',
            )
            repo.url_for_path.assert_called_with('path')
예제 #58
0
    def test_resource_paths_without_pc_region_properties(
            self, source_directory_path_mock):
        """
        If a project has a repository_url in pontoon.base.MOZILLA_REPOS,
        resource_paths_without_pc should ignore files named
        "region.properties".
        """
        source_directory_path_mock.return_value = '/root'
        url = 'https://moz.example.com'
        self.project.repositories.all().delete()
        self.project.repositories.add(RepositoryFactory.create(url=url))

        with patch('pontoon.sync.vcs.models.scandir', wraps=scandir) as mock_scandir, \
            patch(
                'pontoon.sync.vcs.models.MOZILLA_REPOS', [url]
        ):
            mock_scandir.walk.return_value = [
                ('/root', [], ['foo.pot', 'region.properties'])
            ]

            assert_equal(list(self.vcs_project.resource_paths_without_pc()),
                         [os.path.join('/root', 'foo.pot')])
예제 #59
0
 def test_locale_url_non_multi_locale(self):
     """If the repo isn't multi-locale, throw a ValueError."""
     repo = RepositoryFactory.create()
     locale = LocaleFactory.create()
     with assert_raises(ValueError):
         repo.locale_url(locale)