|
| 1 | +""" |
| 2 | +GitLab API: https://docs.gitlab.com/ee/api/project_job_token_scopes.html |
| 3 | +""" |
| 4 | + |
| 5 | +import pytest |
| 6 | +import responses |
| 7 | + |
| 8 | +from gitlab.v4.objects import ProjectJobTokenScope |
| 9 | + |
| 10 | +job_token_scope_content = { |
| 11 | + "inbound_enabled": True, |
| 12 | + "outbound_enabled": False, |
| 13 | +} |
| 14 | + |
| 15 | + |
| 16 | +@pytest.fixture |
| 17 | +def resp_get_job_token_scope(): |
| 18 | + with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps: |
| 19 | + rsps.add( |
| 20 | + method=responses.GET, |
| 21 | + url="http://localhost/api/v4/projects/1/job_token_scope", |
| 22 | + json=job_token_scope_content, |
| 23 | + content_type="application/json", |
| 24 | + status=200, |
| 25 | + ) |
| 26 | + yield rsps |
| 27 | + |
| 28 | + |
| 29 | +@pytest.fixture |
| 30 | +def resp_patch_job_token_scope(): |
| 31 | + with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps: |
| 32 | + rsps.add( |
| 33 | + method=responses.PATCH, |
| 34 | + url="http://localhost/api/v4/projects/1/job_token_scope", |
| 35 | + status=204, |
| 36 | + match=[responses.matchers.json_params_matcher({"enabled": False})], |
| 37 | + ) |
| 38 | + yield rsps |
| 39 | + |
| 40 | + |
| 41 | +@pytest.fixture |
| 42 | +def job_token_scope(project, resp_get_job_token_scope): |
| 43 | + return project.job_token_scope.get() |
| 44 | + |
| 45 | + |
| 46 | +def test_get_job_token_scope(project, resp_get_job_token_scope): |
| 47 | + scope = project.job_token_scope.get() |
| 48 | + assert isinstance(scope, ProjectJobTokenScope) |
| 49 | + assert scope.inbound_enabled is True |
| 50 | + |
| 51 | + |
| 52 | +def test_refresh_job_token_scope(job_token_scope, resp_get_job_token_scope): |
| 53 | + job_token_scope.refresh() |
| 54 | + assert job_token_scope.inbound_enabled is True |
| 55 | + |
| 56 | + |
| 57 | +def test_save_job_token_scope(job_token_scope, resp_patch_job_token_scope): |
| 58 | + job_token_scope.enabled = False |
| 59 | + job_token_scope.save() |
| 60 | + |
| 61 | + |
| 62 | +def test_update_job_token_scope(project, resp_patch_job_token_scope): |
| 63 | + project.job_token_scope.update(new_data={"enabled": False}) |
0 commit comments