|
| 1 | +""" |
| 2 | +GitLab API: https://docs.gitlab.com/ee/api/user_service_accounts.html |
| 3 | +""" |
| 4 | + |
| 5 | +import pytest |
| 6 | +import responses |
| 7 | + |
| 8 | +create_service_account_defaults_content = { |
| 9 | + "id": 57, |
| 10 | + "username": "service_account_6018816a18e515214e0c34c2b33523fc", |
| 11 | + "name": "Service account user", |
| 12 | + "email": "service_account_6018816a18e515214e0c34c2b33523fc@noreply.gitlab.example.com", |
| 13 | +} |
| 14 | + |
| 15 | + |
| 16 | +create_service_account_content = { |
| 17 | + "id": 42, |
| 18 | + "username": "my_service_account", |
| 19 | + "name": "My Service account user", |
| 20 | + "email": "servicebot@example.com", |
| 21 | +} |
| 22 | + |
| 23 | + |
| 24 | +@pytest.fixture |
| 25 | +def resp_create_service_account_defaults(): |
| 26 | + with responses.RequestsMock() as rsps: |
| 27 | + rsps.add( |
| 28 | + method=responses.POST, |
| 29 | + url="http://localhost/api/v4/service_accounts", |
| 30 | + json=create_service_account_defaults_content, |
| 31 | + content_type="application/json", |
| 32 | + status=200, |
| 33 | + ) |
| 34 | + |
| 35 | + yield rsps |
| 36 | + |
| 37 | + |
| 38 | +@pytest.fixture |
| 39 | +def resp_create_service_account(): |
| 40 | + with responses.RequestsMock() as rsps: |
| 41 | + rsps.add( |
| 42 | + method=responses.POST, |
| 43 | + url="http://localhost/api/v4/service_accounts", |
| 44 | + json=create_service_account_content, |
| 45 | + content_type="application/json", |
| 46 | + status=200, |
| 47 | + ) |
| 48 | + |
| 49 | + yield rsps |
| 50 | + |
| 51 | + |
| 52 | +def test_create_service_account_defaults(gl, resp_create_service_account_defaults): |
| 53 | + service_account = gl.service_accounts.create() |
| 54 | + assert service_account.id == 57 |
| 55 | + assert ( |
| 56 | + service_account.username == "service_account_6018816a18e515214e0c34c2b33523fc" |
| 57 | + ) |
| 58 | + assert service_account.name == "Service account user" |
| 59 | + assert ( |
| 60 | + service_account.email |
| 61 | + == "service_account_6018816a18e515214e0c34c2b33523fc@noreply.gitlab.example.com" |
| 62 | + ) |
| 63 | + |
| 64 | + |
| 65 | +def test_create_service_account(gl, resp_create_service_account): |
| 66 | + service_account = gl.service_accounts.create( |
| 67 | + { |
| 68 | + "name": "My Service account user", |
| 69 | + "username": "my_service_account", |
| 70 | + "email": "servicebot@example.com", |
| 71 | + } |
| 72 | + ) |
| 73 | + assert service_account.id == 42 |
| 74 | + assert service_account.username == "my_service_account" |
| 75 | + assert service_account.name == "My Service account user" |
| 76 | + assert service_account.email == "servicebot@example.com" |
0 commit comments