|
2 | 2 | GitLab API: https://docs.gitlab.com/ce/api/groups.html |
3 | 3 | """ |
4 | 4 |
|
| 5 | +import re |
| 6 | + |
5 | 7 | import pytest |
6 | 8 | import responses |
7 | 9 |
|
8 | 10 | import gitlab |
| 11 | +from gitlab.v4.objects import GroupDescendantGroup, GroupSubgroup |
| 12 | + |
| 13 | +subgroup_descgroup_content = [ |
| 14 | + { |
| 15 | + "id": 2, |
| 16 | + "name": "Bar Group", |
| 17 | + "path": "foo/bar", |
| 18 | + "description": "A subgroup of Foo Group", |
| 19 | + "visibility": "public", |
| 20 | + "share_with_group_lock": False, |
| 21 | + "require_two_factor_authentication": False, |
| 22 | + "two_factor_grace_period": 48, |
| 23 | + "project_creation_level": "developer", |
| 24 | + "auto_devops_enabled": None, |
| 25 | + "subgroup_creation_level": "owner", |
| 26 | + "emails_disabled": None, |
| 27 | + "mentions_disabled": None, |
| 28 | + "lfs_enabled": True, |
| 29 | + "default_branch_protection": 2, |
| 30 | + "avatar_url": "http://gitlab.example.com/uploads/group/avatar/1/bar.jpg", |
| 31 | + "web_url": "http://gitlab.example.com/groups/foo/bar", |
| 32 | + "request_access_enabled": False, |
| 33 | + "full_name": "Bar Group", |
| 34 | + "full_path": "foo/bar", |
| 35 | + "file_template_project_id": 1, |
| 36 | + "parent_id": 123, |
| 37 | + "created_at": "2020-01-15T12:36:29.590Z", |
| 38 | + }, |
| 39 | +] |
9 | 40 |
|
10 | 41 |
|
11 | 42 | @pytest.fixture |
@@ -37,6 +68,21 @@ def resp_groups(): |
37 | 68 | yield rsps |
38 | 69 |
|
39 | 70 |
|
| 71 | +@pytest.fixture |
| 72 | +def resp_list_subgroups_descendant_groups(): |
| 73 | + with responses.RequestsMock() as rsps: |
| 74 | + rsps.add( |
| 75 | + method=responses.GET, |
| 76 | + url=re.compile( |
| 77 | + r"http://localhost/api/v4/groups/1/(subgroups|descendant_groups)" |
| 78 | + ), |
| 79 | + json=subgroup_descgroup_content, |
| 80 | + content_type="application/json", |
| 81 | + status=200, |
| 82 | + ) |
| 83 | + yield rsps |
| 84 | + |
| 85 | + |
40 | 86 | @pytest.fixture |
41 | 87 | def resp_create_import(accepted_content): |
42 | 88 | with responses.RequestsMock() as rsps: |
@@ -71,6 +117,18 @@ def test_create_group_export(group, resp_export): |
71 | 117 | assert export.message == "202 Accepted" |
72 | 118 |
|
73 | 119 |
|
| 120 | +def test_list_group_subgroups(group, resp_list_subgroups_descendant_groups): |
| 121 | + subgroups = group.subgroups.list() |
| 122 | + assert isinstance(subgroups[0], GroupSubgroup) |
| 123 | + assert subgroups[0].path == subgroup_descgroup_content[0]["path"] |
| 124 | + |
| 125 | + |
| 126 | +def test_list_group_descendant_groups(group, resp_list_subgroups_descendant_groups): |
| 127 | + descendant_groups = group.descendant_groups.list() |
| 128 | + assert isinstance(descendant_groups[0], GroupDescendantGroup) |
| 129 | + assert descendant_groups[0].path == subgroup_descgroup_content[0]["path"] |
| 130 | + |
| 131 | + |
74 | 132 | @pytest.mark.skip("GitLab API endpoint not implemented") |
75 | 133 | def test_refresh_group_export_status(group, resp_export): |
76 | 134 | export = group.exports.create() |
|
0 commit comments