Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit259668a

Browse files
nejchJohnVillalovos
authored andcommitted
feat(api): addproject.transfer() and deprecatetransfer_project()
1 parent27e0742 commit259668a

File tree

5 files changed

+89
-6
lines changed

5 files changed

+89
-6
lines changed

‎gitlab/v4/objects/projects.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
importwarnings
12
fromtypingimportAny,Callable,cast,Dict,List,Optional,TYPE_CHECKING,Union
23

34
importrequests
@@ -526,7 +527,7 @@ def mirror_pull(self, **kwargs: Any) -> None:
526527

527528
@cli.register_custom_action("Project", ("to_namespace",))
528529
@exc.on_http_error(exc.GitlabTransferProjectError)
529-
deftransfer_project(self,to_namespace:str,**kwargs:Any)->None:
530+
deftransfer(self,to_namespace:str,**kwargs:Any)->None:
530531
"""Transfer a project to the given namespace ID
531532
532533
Args:
@@ -543,6 +544,15 @@ def transfer_project(self, to_namespace: str, **kwargs: Any) -> None:
543544
path,post_data={"namespace":to_namespace},**kwargs
544545
)
545546

547+
@cli.register_custom_action("Project", ("to_namespace",))
548+
deftransfer_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+
returnself.transfer(*args,**kwargs)
555+
546556
@cli.register_custom_action("Project", ("ref_name","job"), ("job_token",))
547557
@exc.on_http_error(exc.GitlabGetError)
548558
defartifacts(

‎tests/functional/api/test_groups.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,19 @@ def test_group_hooks(group):
231231
hook=group.hooks.get(hook.id)
232232
asserthook.note_eventsisTrue
233233
hook.delete()
234+
235+
236+
@pytest.mark.skip(reason="Pending #1807")
237+
deftest_group_transfer(gl,group):
238+
transfer_group=gl.groups.create({"name":"transfer-test-group"})
239+
assertgroup.namespace["path"]!=group.full_path
240+
241+
transfer_group.transfer(group.id)
242+
243+
transferred_group=gl.projects.get(transfer_group.id)
244+
asserttransferred_group.namespace["path"]==group.full_path
245+
246+
transfer_group.transfer()
247+
248+
transferred_group=gl.projects.get(transfer_group.id)
249+
asserttransferred_group.path==transferred_group.full_path

‎tests/functional/api/test_projects.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,17 @@ def test_project_groups_list(gl, group):
329329
groups=project.groups.list()
330330
group_ids=set([x.idforxingroups])
331331
assertset((group.id,group2.id))==group_ids
332+
333+
334+
deftest_project_transfer(gl,project,group):
335+
assertproject.namespace["path"]!=group.full_path
336+
project.transfer_project(group.id)
337+
338+
project=gl.projects.get(project.id)
339+
assertproject.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+
assertproject.namespace["path"]==gl.user.username

‎tests/unit/objects/test_groups.py‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
importgitlab
1111
fromgitlab.v4.objectsimportGroupDescendantGroup,GroupSubgroup
1212

13+
content= {"name":"name","id":1,"path":"path"}
1314
subgroup_descgroup_content= [
1415
{
1516
"id":2,
@@ -41,8 +42,6 @@
4142

4243
@pytest.fixture
4344
defresp_groups():
44-
content= {"name":"name","id":1,"path":"path"}
45-
4645
withresponses.RequestsMock(assert_all_requests_are_fired=False)asrsps:
4746
rsps.add(
4847
method=responses.GET,
@@ -96,6 +95,22 @@ def resp_create_import(accepted_content):
9695
yieldrsps
9796

9897

98+
@pytest.fixture
99+
defresp_transfer_group():
100+
withresponses.RequestsMock()asrsps:
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+
yieldrsps
112+
113+
99114
deftest_get_group(gl,resp_groups):
100115
data=gl.groups.get(1)
101116
assertisinstance(data,gitlab.v4.objects.Group)
@@ -153,3 +168,9 @@ def test_refresh_group_import_status(group, resp_groups):
153168
group_import=group.imports.get()
154169
group_import.refresh()
155170
assertgroup_import.import_status=="finished"
171+
172+
173+
@pytest.mark.skip("Pending #1807")
174+
deftest_transfer_group(gl,resp_transfer_group):
175+
group=gl.groups.get(1,lazy=True)
176+
group.transfer("test-namespace")

‎tests/unit/objects/test_projects.py‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ def resp_import_bitbucket_server():
5454
yieldrsps
5555

5656

57+
@pytest.fixture
58+
defresp_transfer_project():
59+
withresponses.RequestsMock()asrsps:
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+
yieldrsps
71+
72+
5773
deftest_get_project(gl,resp_get_project):
5874
data=gl.projects.get(1)
5975
assertisinstance(data,Project)
@@ -217,9 +233,15 @@ def test_delete_project_push_rule(gl):
217233
pass
218234

219235

220-
@pytest.mark.skip(reason="missing test")
221-
deftest_transfer_project(gl):
222-
pass
236+
deftest_transfer_project(gl,resp_transfer_project):
237+
project=gl.projects.get(1,lazy=True)
238+
project.transfer("test-namespace")
239+
240+
241+
deftest_transfer_project_deprecated_warns(gl,resp_transfer_project):
242+
project=gl.projects.get(1,lazy=True)
243+
withpytest.warns(DeprecationWarning):
244+
project.transfer_project("test-namespace")
223245

224246

225247
@pytest.mark.skip(reason="missing test")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp