Example #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)
Example #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)
Example #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')
            ])
Example #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)
Example #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
Example #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,
        )
Example #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')
            ])
Example #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
Example #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")
Example #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)
Example #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"),
                ]
            )
Example #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")
Example #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/')
Example #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")
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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')
Example #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/')
Example #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
         )
Example #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)
Example #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)
Example #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
Example #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)
Example #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")
Example #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)
Example #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',
         )
Example #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))
Example #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)
Example #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
         )
Example #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')
Example #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')
Example #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))
Example #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'
         )
Example #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')
Example #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)
Example #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',
         )
Example #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)
Example #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')
Example #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))
Example #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))
Example #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'
            )
Example #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")
Example #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)
Example #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'
         )
Example #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
Example #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)
Example #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/")
Example #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")])
Example #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')])
Example #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/')
Example #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/')
Example #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)
Example #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)
Example #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')
Example #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')])
Example #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)