|
89 | 89 | "username": "gitlab-service-account",
|
90 | 90 | }
|
91 | 91 |
|
| 92 | +service_account_access_token_content = { |
| 93 | + "id": 1, |
| 94 | + "name": "service_account_access_token", |
| 95 | + "revoked": False, |
| 96 | + "scopes": ["api"], |
| 97 | + "user_id": 42, |
| 98 | + "last_used": None, |
| 99 | + "active": True, |
| 100 | + "expires_at": None, |
| 101 | + "token": "abcdefg12345", |
| 102 | +} |
| 103 | + |
92 | 104 |
|
93 | 105 | @pytest.fixture
|
94 | 106 | def resp_groups():
|
@@ -362,6 +374,26 @@ def resp_delete_group_service_account():
|
362 | 374 | yield rsps
|
363 | 375 |
|
364 | 376 |
|
| 377 | +@pytest.fixture |
| 378 | +def resp_create_group_service_account_access_token(): |
| 379 | + with responses.RequestsMock() as rsps: |
| 380 | + rsps.add( |
| 381 | + method=responses.POST, |
| 382 | + url="http://localhost/api/v4/groups/1/service_accounts", |
| 383 | + json=service_account_content, |
| 384 | + content_type="application/json", |
| 385 | + status=200, |
| 386 | + ) |
| 387 | + rsps.add( |
| 388 | + method=responses.POST, |
| 389 | + url="http://localhost/api/v4/groups/1/service_accounts/42/personal_access_tokens", |
| 390 | + json=service_account_access_token_content, |
| 391 | + content_type="application/json", |
| 392 | + status=200, |
| 393 | + ) |
| 394 | + yield rsps |
| 395 | + |
| 396 | + |
365 | 397 | def test_get_group(gl, resp_groups):
|
366 | 398 | data = gl.groups.get(1)
|
367 | 399 | assert isinstance(data, gitlab.v4.objects.Group)
|
@@ -515,3 +547,17 @@ def test_delete_group_service_account(group, resp_delete_group_service_account):
|
515 | 547 | {"name": "gitlab-service-account", "username": "gitlab-service-account"}
|
516 | 548 | )
|
517 | 549 | service_account.delete()
|
| 550 | + |
| 551 | + |
| 552 | +def test_create_group_service_account_access_token( |
| 553 | + group, resp_create_group_service_account_access_token |
| 554 | +): |
| 555 | + service_account = group.service_accounts.create( |
| 556 | + {"name": "gitlab-service-account", "username": "gitlab-service-account"} |
| 557 | + ) |
| 558 | + access_token = service_account.access_tokens.create( |
| 559 | + {"name": "service_account_access_token", "scopes": ["api"]} |
| 560 | + ) |
| 561 | + assert service_account.id == 42 |
| 562 | + assert access_token.name == "service_account_access_token" |
| 563 | + assert access_token.scopes == ["api"] |
0 commit comments