Ejemplo n.º 1
0
    def test_handles_missing_master_branch(self):
        addon = addon_factory()
        addon_repo = AddonGitRepository(addon)
        # Create the git repo
        addon_repo.git_repository
        update_git_repo_creation_time(addon_repo,
                                      time=datetime.datetime(2019, 1, 1))
        assert addon_repo.is_extracted
        assert not addon_repo.is_recent
        # Simulate a git extraction in progress.
        GitExtractionEntry.objects.create(addon_id=addon.pk, in_progress=True)
        # This is the error raised by the task that extracts a version.
        exc = MissingMasterBranchError('cannot find master branch')

        on_extraction_error(request=None,
                            exc=exc,
                            traceback=None,
                            addon_pk=addon.pk)

        # The task should remove the git repository on
        # MissingMasterBranchError.
        assert not addon_repo.is_extracted
        # The task should remove the existing git extraction entry.
        assert GitExtractionEntry.objects.filter(in_progress=True).count() == 0
        # The task should re-add the add-on to the git extraction queue.
        assert GitExtractionEntry.objects.filter(in_progress=None).count() == 1
Ejemplo n.º 2
0
    def test_checks_creation_time_before_deleting_repo(self):
        addon = addon_factory()
        addon_repo = AddonGitRepository(addon)
        # Create the git repo
        addon_repo.git_repository
        # We do not update the creation time of the git repository here so that
        # it is less than 1 hour (because the git repository was created in
        # this test case).
        assert addon_repo.is_extracted
        assert addon_repo.is_recent
        # Simulate a git extraction in progress.
        GitExtractionEntry.objects.create(addon_id=addon.pk, in_progress=True)
        # This is the error raised by the task that extracts a version.
        exc = MissingMasterBranchError('cannot find master branch')

        on_extraction_error(request=None,
                            exc=exc,
                            traceback=None,
                            addon_pk=addon.pk)

        # When the creation time of an add-on git repository is too recent (< 1
        # hour ago), then we do not delete the repository because it might be
        # an "extraction loop" problem.
        assert addon_repo.is_extracted
        # The task should remove the existing git extraction entry.
        assert GitExtractionEntry.objects.filter(in_progress=None).count() == 0
        # The task should NOT re-add the add-on to the git extraction queue.
        assert GitExtractionEntry.objects.filter(in_progress=True).count() == 0