|
8 | 8 | import responses
|
9 | 9 |
|
10 | 10 | import gitlab
|
11 |
| -from gitlab.v4.objects import GroupDescendantGroup, GroupLDAPGroupLink, GroupSubgroup |
| 11 | +from gitlab.v4.objects import ( |
| 12 | + GroupDescendantGroup, |
| 13 | + GroupLDAPGroupLink, |
| 14 | + GroupSAMLGroupLink, |
| 15 | + GroupSubgroup, |
| 16 | +) |
12 | 17 | from gitlab.v4.objects.projects import GroupProject, SharedProject
|
13 | 18 |
|
14 | 19 | content = {"name": "name", "id": 1, "path": "path"}
|
|
20 | 25 | "filter": "(memberOf=cn=some_group,ou=groups,ou=fake_ou,dc=sub_dc,dc=example,dc=tld)",
|
21 | 26 | }
|
22 | 27 | ]
|
| 28 | +saml_group_links_content = [{"name": "saml-group-1", "access_level": 10}] |
| 29 | +create_saml_group_link_request_body = { |
| 30 | + "saml_group_name": "saml-group-1", |
| 31 | + "access_level": 10, |
| 32 | +} |
23 | 33 | projects_content = [
|
24 | 34 | {
|
25 | 35 | "id": 9,
|
@@ -237,6 +247,75 @@ def resp_list_ldap_group_links(no_content):
|
237 | 247 | yield rsps
|
238 | 248 |
|
239 | 249 |
|
| 250 | +@pytest.fixture |
| 251 | +def resp_list_saml_group_links(): |
| 252 | + with responses.RequestsMock() as rsps: |
| 253 | + rsps.add( |
| 254 | + method=responses.GET, |
| 255 | + url="http://localhost/api/v4/groups/1/saml_group_links", |
| 256 | + json=saml_group_links_content, |
| 257 | + content_type="application/json", |
| 258 | + status=200, |
| 259 | + ) |
| 260 | + yield rsps |
| 261 | + |
| 262 | + |
| 263 | +@pytest.fixture |
| 264 | +def resp_get_saml_group_link(): |
| 265 | + with responses.RequestsMock() as rsps: |
| 266 | + rsps.add( |
| 267 | + method=responses.GET, |
| 268 | + url="http://localhost/api/v4/groups/1/saml_group_links/saml-group-1", |
| 269 | + json=saml_group_links_content[0], |
| 270 | + content_type="application/json", |
| 271 | + status=200, |
| 272 | + ) |
| 273 | + yield rsps |
| 274 | + |
| 275 | + |
| 276 | +@pytest.fixture |
| 277 | +def resp_create_saml_group_link(): |
| 278 | + with responses.RequestsMock() as rsps: |
| 279 | + rsps.add( |
| 280 | + method=responses.POST, |
| 281 | + url="http://localhost/api/v4/groups/1/saml_group_links", |
| 282 | + match=[ |
| 283 | + responses.matchers.json_params_matcher( |
| 284 | + create_saml_group_link_request_body |
| 285 | + ) |
| 286 | + ], |
| 287 | + json=saml_group_links_content[0], |
| 288 | + content_type="application/json", |
| 289 | + status=200, |
| 290 | + ) |
| 291 | + yield rsps |
| 292 | + |
| 293 | + |
| 294 | +@pytest.fixture |
| 295 | +def resp_delete_saml_group_link(no_content): |
| 296 | + with responses.RequestsMock() as rsps: |
| 297 | + rsps.add( |
| 298 | + method=responses.POST, |
| 299 | + url="http://localhost/api/v4/groups/1/saml_group_links", |
| 300 | + match=[ |
| 301 | + responses.matchers.json_params_matcher( |
| 302 | + create_saml_group_link_request_body |
| 303 | + ) |
| 304 | + ], |
| 305 | + json=saml_group_links_content[0], |
| 306 | + content_type="application/json", |
| 307 | + status=200, |
| 308 | + ) |
| 309 | + rsps.add( |
| 310 | + method=responses.DELETE, |
| 311 | + url="http://localhost/api/v4/groups/1/saml_group_links/saml-group-1", |
| 312 | + json=no_content, |
| 313 | + content_type="application/json", |
| 314 | + status=204, |
| 315 | + ) |
| 316 | + yield rsps |
| 317 | + |
| 318 | + |
240 | 319 | def test_get_group(gl, resp_groups):
|
241 | 320 | data = gl.groups.get(1)
|
242 | 321 | assert isinstance(data, gitlab.v4.objects.Group)
|
@@ -341,3 +420,36 @@ def test_update_group_push_rule(
|
341 | 420 | def test_delete_group_push_rule(group, resp_delete_push_rules_group):
|
342 | 421 | pr = group.pushrules.get()
|
343 | 422 | pr.delete()
|
| 423 | + |
| 424 | + |
| 425 | +def test_list_saml_group_links(group, resp_list_saml_group_links): |
| 426 | + saml_group_links = group.saml_group_links.list() |
| 427 | + assert isinstance(saml_group_links[0], GroupSAMLGroupLink) |
| 428 | + assert saml_group_links[0].name == saml_group_links_content[0]["name"] |
| 429 | + assert ( |
| 430 | + saml_group_links[0].access_level == saml_group_links_content[0]["access_level"] |
| 431 | + ) |
| 432 | + |
| 433 | + |
| 434 | +def test_get_saml_group_link(group, resp_get_saml_group_link): |
| 435 | + saml_group_link = group.saml_group_links.get("saml-group-1") |
| 436 | + assert isinstance(saml_group_link, GroupSAMLGroupLink) |
| 437 | + assert saml_group_link.name == saml_group_links_content[0]["name"] |
| 438 | + assert saml_group_link.access_level == saml_group_links_content[0]["access_level"] |
| 439 | + |
| 440 | + |
| 441 | +def test_create_saml_group_link(group, resp_create_saml_group_link): |
| 442 | + saml_group_link = group.saml_group_links.create(create_saml_group_link_request_body) |
| 443 | + assert isinstance(saml_group_link, GroupSAMLGroupLink) |
| 444 | + assert ( |
| 445 | + saml_group_link.name == create_saml_group_link_request_body["saml_group_name"] |
| 446 | + ) |
| 447 | + assert ( |
| 448 | + saml_group_link.access_level |
| 449 | + == create_saml_group_link_request_body["access_level"] |
| 450 | + ) |
| 451 | + |
| 452 | + |
| 453 | +def test_delete_saml_group_link(group, resp_delete_saml_group_link): |
| 454 | + saml_group_link = group.saml_group_links.create(create_saml_group_link_request_body) |
| 455 | + saml_group_link.delete() |
0 commit comments