示例#1
0
    def setUp(self):
        super().setUp()
        print(PersistentObjectStorage().storage_file)
        self.github_token = os.environ.get("GITHUB_TOKEN")
        self.pagure_token = os.environ.get("PAGURE_TOKEN")
        self.gitlab_token = os.environ.get("GITLAB_TOKEN") or "some_token"

        if PersistentObjectStorage().mode == StorageMode.write:
            if not self.github_token:
                raise EnvironmentError(
                    "You are in requre write mode, please set GITHUB_TOKEN env variables"
                )
            if not self.pagure_token:
                raise EnvironmentError(
                    "You are in requre write mode, please set PAGURE_TOKEN env variables"
                )
            if not os.environ.get("GITLAB_TOKEN"):
                raise EnvironmentError(
                    "You are in requre write mode, please set GITLAB_TOKEN env variables"
                )

        self.github_service = GithubService(token=self.github_token)
        self.pagure_service = PagureService(token=self.pagure_token)
        self.gitlab_service = GitlabService(
            token=self.gitlab_token, instance_url="https://gitlab.com"
        )
        self.custom_instances = [
            self.github_service,
            self.pagure_service,
            self.gitlab_service,
        ]
示例#2
0
    def setUp(self):
        self.github_token = os.environ.get("GITHUB_TOKEN")
        self.pagure_token = os.environ.get("PAGURE_TOKEN")
        self.gitlab_token = os.environ.get("GITLAB_TOKEN") or "some_token"

        test_name = self.id() or "all"

        persistent_data_file = os.path.join(
            PERSISTENT_DATA_PREFIX, f"test_factory_data_{test_name}.yaml")
        PersistentObjectStorage().storage_file = persistent_data_file

        if PersistentObjectStorage().is_write_mode and not self.github_token:
            raise EnvironmentError("please set GITHUB_TOKEN env variables")

        if PersistentObjectStorage().is_write_mode and not self.pagure_token:
            raise EnvironmentError("please set PAGURE_TOKEN env variables")

        if PersistentObjectStorage(
        ).is_write_mode and not os.environ.get("GITLAB_TOKEN"):
            raise EnvironmentError("please set GITLAB_TOKEN env variables")

        self.github_service = GithubService(token=self.github_token)
        self.pagure_service = PagureService(token=self.pagure_token)
        self.gitlab_service = GitlabService(token=self.gitlab_token,
                                            instance_url="https://gitlab.com")
        self.custom_instances = [
            self.github_service,
            self.pagure_service,
            self.gitlab_service,
        ]
示例#3
0
 def src_git_svc(self) -> GitlabService:
     if self._src_git_svc is None:
         self._src_git_svc = GitlabService(
             instance_url=f"https://{self.src_git_host}",
             token=self.src_git_token,
             max_retries=self._retries,
         )
     return self._src_git_svc
示例#4
0
def test_pr_id_and_ref_gitlab(tmp_path: Path):
    """p-s passes both ref and pr_id, we want to check out PR"""
    remote = tmp_path / "remote"
    remote.mkdir()
    create_new_repo(remote, ["--bare"])
    upstream_git = tmp_path / "upstream_git"
    upstream_git.mkdir()
    initiate_git_repo(upstream_git, push=True, upstream_remote=str(remote))
    # mimic gitlab MR
    pr_id = "123"
    ref = (
        subprocess.check_output(["git", "rev-parse", "HEAD^"], cwd=upstream_git)
        .strip()
        .decode()
    )
    local_tmp_branch = "asdqwe"
    subprocess.check_call(["git", "branch", local_tmp_branch, ref], cwd=upstream_git)
    subprocess.check_call(
        [
            "git",
            "push",
            "origin",
            f"{local_tmp_branch}:refs/merge-requests/{pr_id}/head",
        ],
        cwd=upstream_git,
    )
    subprocess.check_call(["git", "branch", "-D", local_tmp_branch], cwd=upstream_git)

    git_project = flexmock(repo="random_name", namespace="random_namespace")
    git_project.should_receive("get_pr").and_return(flexmock(target_branch="main"))

    LocalProject(
        working_dir=upstream_git,
        offline=True,
        pr_id=pr_id,
        ref=ref,
        git_service=GitlabService(token="12345"),
        git_project=git_project,
    )

    assert (
        subprocess.check_output(
            ["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd=upstream_git
        )
        .strip()
        .decode()
        == f"pr/{pr_id}"
    )
示例#5
0
def global_service_config():
    """
    This config will be used instead of the one loaded from the local config file.

    You can still mock/overwrite the service config content in your tests
    but this one will be used by default.
    """
    service_config = ServiceConfig()
    service_config.services = {
        GithubService(token="token"),
        GitlabService(token="token"),
    }
    service_config.dry_run = False
    service_config.github_requests_log_path = "/path"
    service_config.server_name = "localhost"
    ServiceConfig.service_config = service_config
示例#6
0
             hostname="host2.name",
             get_project_from_url=lambda url: "right-project",
         ),
     ],
     True,
     "right-project",
 ),
 (
     "https://gitlab.gnome.org/lbarcziova/testing-ogr-repo",
     None,
     None,
     True,
     GitlabProject(
         repo="testing-ogr-repo",
         namespace="lbarcziova",
         service=GitlabService(instance_url="https://gitlab.gnome.org"),
     ),
 ),
 (
     "https://src.stg.fedoraproject.org/rpms/python-dockerpty.git",
     None,
     [PagureService(instance_url="https://src.stg.fedoraproject.org")],
     True,
     PagureProject(
         repo="python-dockerpty",
         namespace="rpms",
         service=PagureService(instance_url="https://src.stg.fedoraproject.org"),
     ),
 ),
 (
     "https://src.fedoraproject.org/rpms/python-dockerpty.git",
示例#7
0
                ),
                flexmock(
                    instance_url="https://host2.name",
                    get_project_from_url=lambda url: "right-project",
                ),
            ],
            "right-project",
        ),
        (
            "https://gitlab.gnome.org/lbarcziova/testing-ogr-repo",
            None,
            None,
            GitlabProject(
                repo="testing-ogr-repo",
                namespace="lbarcziova",
                service=GitlabService(instance_url="https://gitlab.gnome.org"),
            ),
        ),
    ],
)
def test_get_project(url, mapping, instances, result):
    project = get_project(url=url,
                          service_mapping_update=mapping,
                          custom_instances=instances)
    assert project == result


@pytest.mark.parametrize(
    "url,mapping,instances,exc_str",
    [
        (
示例#8
0
 def gitlab_service(self):
     if not self._gitlab_service:
         self._gitlab_service = GitlabService(
             token=self.gitlab_token, instance_url="https://gitlab.com"
         )
     return self._gitlab_service
示例#9
0
 def test_service_without_auth(self):
     service = GitlabService()
     assert service.gitlab_instance
     assert service.get_project(namespace="gnachman", repo="iterm2").exists()
示例#10
0
             hostname="host2.name",
             get_project_from_url=lambda url: "right-project",
         ),
     ],
     True,
     "right-project",
 ),
 (
     "https://gitlab.gnome.org/lbarcziova/testing-ogr-repo",
     None,
     None,
     True,
     GitlabProject(
         repo="testing-ogr-repo",
         namespace="lbarcziova",
         service=GitlabService(instance_url="https://gitlab.gnome.org"),
     ),
 ),
 (
     "https://src.stg.fedoraproject.org/rpms/python-dockerpty.git",
     None,
     [PagureService(instance_url="https://src.stg.fedoraproject.org")],
     True,
     PagureProject(
         repo="python-dockerpty",
         namespace="rpms",
         service=PagureService(
             instance_url="https://src.stg.fedoraproject.org"),
     ),
 ),
 (
示例#11
0
文件: test_gitlab.py 项目: packit/ogr
 def test_hostname(self):
     assert GitlabService().hostname == "gitlab.com"
     assert (GitlabService(instance_url="https://gitlab.gnome.org").hostname
             == "gitlab.gnome.org")