| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 27e0742 commit 259668a
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,4 @@ | |||
| 1 | + import warnings | ||
| 1 | 2 | from typing import Any, Callable, cast, Dict, List, Optional, TYPE_CHECKING, Union | |
| 2 | 3 | ||
| 3 | 4 | import requests | |
@@ -526,7 +527,7 @@ def mirror_pull(self, **kwargs: Any) -> None: | |||
| 526 | 527 | ||
| 527 | 528 | @cli.register_custom_action("Project", ("to_namespace",)) | |
| 528 | 529 | @exc.on_http_error(exc.GitlabTransferProjectError) | |
| 529 | - def transfer_project(self, to_namespace: str, **kwargs: Any) -> None: | ||
| 530 | + def transfer(self, to_namespace: str, **kwargs: Any) -> None: | ||
| 530 | 531 | """Transfer a project to the given namespace ID | |
| 531 | 532 | ||
| 532 | 533 | Args: | |
@@ -543,6 +544,15 @@ def transfer_project(self, to_namespace: str, **kwargs: Any) -> None: | |||
| 543 | 544 | path, post_data={"namespace": to_namespace}, **kwargs | |
| 544 | 545 | ) | |
| 545 | 546 | ||
| 547 | + @cli.register_custom_action("Project", ("to_namespace",)) | ||
| 548 | + def transfer_project(self, *args: Any, **kwargs: Any) -> None: | ||
| 549 | + warnings.warn( | ||
| 550 | + "The project.transfer_project() method is deprecated and will be " | ||
| 551 | + "removed in a future version. Use project.transfer() instead.", | ||
| 552 | + DeprecationWarning, | ||
| 553 | + ) | ||
| 554 | + return self.transfer(*args, **kwargs) | ||
| 555 | + | ||
| 546 | 556 | @cli.register_custom_action("Project", ("ref_name", "job"), ("job_token",)) | |
| 547 | 557 | @exc.on_http_error(exc.GitlabGetError) | |
| 548 | 558 | def artifacts( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -231,3 +231,19 @@ def test_group_hooks(group): | |||
| 231 | 231 | hook = group.hooks.get(hook.id) | |
| 232 | 232 | assert hook.note_events is True | |
| 233 | 233 | hook.delete() | |
| 234 | + | ||
| 235 | + | ||
| 236 | + @pytest.mark.skip(reason="Pending #1807") | ||
| 237 | + def test_group_transfer(gl, group): | ||
| 238 | + transfer_group = gl.groups.create({"name": "transfer-test-group"}) | ||
| 239 | + assert group.namespace["path"] != group.full_path | ||
| 240 | + | ||
| 241 | + transfer_group.transfer(group.id) | ||
| 242 | + | ||
| 243 | + transferred_group = gl.projects.get(transfer_group.id) | ||
| 244 | + assert transferred_group.namespace["path"] == group.full_path | ||
| 245 | + | ||
| 246 | + transfer_group.transfer() | ||
| 247 | + | ||
| 248 | + transferred_group = gl.projects.get(transfer_group.id) | ||
| 249 | + assert transferred_group.path == transferred_group.full_path | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -329,3 +329,17 @@ def test_project_groups_list(gl, group): | |||
| 329 | 329 | groups = project.groups.list() | |
| 330 | 330 | group_ids = set([x.id for x in groups]) | |
| 331 | 331 | assert set((group.id, group2.id)) == group_ids | |
| 332 | + | ||
| 333 | + | ||
| 334 | + def test_project_transfer(gl, project, group): | ||
| 335 | + assert project.namespace["path"] != group.full_path | ||
| 336 | + project.transfer_project(group.id) | ||
| 337 | + | ||
| 338 | + project = gl.projects.get(project.id) | ||
| 339 | + assert project.namespace["path"] == group.full_path | ||
| 340 | + | ||
| 341 | + gl.auth() | ||
| 342 | + project.transfer_project(gl.user.username) | ||
| 343 | + | ||
| 344 | + project = gl.projects.get(project.id) | ||
| 345 | + assert project.namespace["path"] == gl.user.username | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ | |||
| 10 | 10 | import gitlab | |
| 11 | 11 | from gitlab.v4.objects import GroupDescendantGroup, GroupSubgroup | |
| 12 | 12 | ||
| 13 | + content = {"name": "name", "id": 1, "path": "path"} | ||
| 13 | 14 | subgroup_descgroup_content = [ | |
| 14 | 15 | { | |
| 15 | 16 | "id": 2, | |
@@ -41,8 +42,6 @@ | |||
| 41 | 42 | ||
| 42 | 43 | @pytest.fixture | |
| 43 | 44 | def resp_groups(): | |
| 44 | - content = {"name": "name", "id": 1, "path": "path"} | ||
| 45 | - | ||
| 46 | 45 | with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps: | |
| 47 | 46 | rsps.add( | |
| 48 | 47 | method=responses.GET, | |
@@ -96,6 +95,22 @@ def resp_create_import(accepted_content): | |||
| 96 | 95 | yield rsps | |
| 97 | 96 | ||
| 98 | 97 | ||
| 98 | + @pytest.fixture | ||
| 99 | + def resp_transfer_group(): | ||
| 100 | + with responses.RequestsMock() as rsps: | ||
| 101 | + rsps.add( | ||
| 102 | + method=responses.PUT, | ||
| 103 | + url="http://localhost/api/v4/groups/1/transfer", | ||
| 104 | + json=content, | ||
| 105 | + content_type="application/json", | ||
| 106 | + status=200, | ||
| 107 | + match=[ | ||
| 108 | + responses.matchers.json_params_matcher({"namespace": "test-namespace"}) | ||
| 109 | + ], | ||
| 110 | + ) | ||
| 111 | + yield rsps | ||
| 112 | + | ||
| 113 | + | ||
| 99 | 114 | def test_get_group(gl, resp_groups): | |
| 100 | 115 | data = gl.groups.get(1) | |
| 101 | 116 | assert isinstance(data, gitlab.v4.objects.Group) | |
@@ -153,3 +168,9 @@ def test_refresh_group_import_status(group, resp_groups): | |||
| 153 | 168 | group_import = group.imports.get() | |
| 154 | 169 | group_import.refresh() | |
| 155 | 170 | assert group_import.import_status == "finished" | |
| 171 | + | ||
| 172 | + | ||
| 173 | + @pytest.mark.skip("Pending #1807") | ||
| 174 | + def test_transfer_group(gl, resp_transfer_group): | ||
| 175 | + group = gl.groups.get(1, lazy=True) | ||
| 176 | + group.transfer("test-namespace") | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,6 +54,22 @@ def resp_import_bitbucket_server(): | |||
| 54 | 54 | yield rsps | |
| 55 | 55 | ||
| 56 | 56 | ||
| 57 | + @pytest.fixture | ||
| 58 | + def resp_transfer_project(): | ||
| 59 | + with responses.RequestsMock() as rsps: | ||
| 60 | + rsps.add( | ||
| 61 | + method=responses.PUT, | ||
| 62 | + url="http://localhost/api/v4/projects/1/transfer", | ||
| 63 | + json=project_content, | ||
| 64 | + content_type="application/json", | ||
| 65 | + status=200, | ||
| 66 | + match=[ | ||
| 67 | + responses.matchers.json_params_matcher({"namespace": "test-namespace"}) | ||
| 68 | + ], | ||
| 69 | + ) | ||
| 70 | + yield rsps | ||
| 71 | + | ||
| 72 | + | ||
| 57 | 73 | def test_get_project(gl, resp_get_project): | |
| 58 | 74 | data = gl.projects.get(1) | |
| 59 | 75 | assert isinstance(data, Project) | |
@@ -217,9 +233,15 @@ def test_delete_project_push_rule(gl): | |||
| 217 | 233 | pass | |
| 218 | 234 | ||
| 219 | 235 | ||
| 220 | - @pytest.mark.skip(reason="missing test") | ||
| 221 | - def test_transfer_project(gl): | ||
| 222 | - pass | ||
| 236 | + def test_transfer_project(gl, resp_transfer_project): | ||
| 237 | + project = gl.projects.get(1, lazy=True) | ||
| 238 | + project.transfer("test-namespace") | ||
| 239 | + | ||
| 240 | + | ||
| 241 | + def test_transfer_project_deprecated_warns(gl, resp_transfer_project): | ||
| 242 | + project = gl.projects.get(1, lazy=True) | ||
| 243 | + with pytest.warns(DeprecationWarning): | ||
| 244 | + project.transfer_project("test-namespace") | ||
| 223 | 245 | ||
| 224 | 246 | ||
| 225 | 247 | @pytest.mark.skip(reason="missing test") | |
| Back | FazBrowse Home | New Git URL |
0 commit comments