|
| 1 | +""" |
| 2 | +GitLab API: https://docs.gitlab.com/ee/api/cluster_agents.html |
| 3 | +""" |
| 4 | + |
| 5 | +import pytest |
| 6 | +import responses |
| 7 | + |
| 8 | +from gitlab.v4.objects import ProjectClusterAgent |
| 9 | + |
| 10 | +agent_content = { |
| 11 | + "id": 1, |
| 12 | + "name": "agent-1", |
| 13 | + "config_project": { |
| 14 | + "id": 20, |
| 15 | + "description": "", |
| 16 | + "name": "test", |
| 17 | + "name_with_namespace": "Administrator / test", |
| 18 | + "path": "test", |
| 19 | + "path_with_namespace": "root/test", |
| 20 | + "created_at": "2022-03-20T20:42:40.221Z", |
| 21 | + }, |
| 22 | + "created_at": "2022-04-20T20:42:40.221Z", |
| 23 | + "created_by_user_id": 42, |
| 24 | +} |
| 25 | + |
| 26 | + |
| 27 | +@pytest.fixture |
| 28 | +def resp_list_project_cluster_agents(): |
| 29 | + with responses.RequestsMock() as rsps: |
| 30 | + rsps.add( |
| 31 | + method=responses.GET, |
| 32 | + url="http://localhost/api/v4/projects/1/cluster_agents", |
| 33 | + json=[agent_content], |
| 34 | + content_type="application/json", |
| 35 | + status=200, |
| 36 | + ) |
| 37 | + yield rsps |
| 38 | + |
| 39 | + |
| 40 | +@pytest.fixture |
| 41 | +def resp_get_project_cluster_agent(): |
| 42 | + with responses.RequestsMock() as rsps: |
| 43 | + rsps.add( |
| 44 | + method=responses.GET, |
| 45 | + url="http://localhost/api/v4/projects/1/cluster_agents/1", |
| 46 | + json=agent_content, |
| 47 | + content_type="application/json", |
| 48 | + status=200, |
| 49 | + ) |
| 50 | + yield rsps |
| 51 | + |
| 52 | + |
| 53 | +@pytest.fixture |
| 54 | +def resp_create_project_cluster_agent(): |
| 55 | + with responses.RequestsMock() as rsps: |
| 56 | + rsps.add( |
| 57 | + method=responses.POST, |
| 58 | + url="http://localhost/api/v4/projects/1/cluster_agents", |
| 59 | + json=agent_content, |
| 60 | + content_type="application/json", |
| 61 | + status=201, |
| 62 | + ) |
| 63 | + yield rsps |
| 64 | + |
| 65 | + |
| 66 | +@pytest.fixture |
| 67 | +def resp_delete_project_cluster_agent(): |
| 68 | + with responses.RequestsMock() as rsps: |
| 69 | + rsps.add( |
| 70 | + method=responses.DELETE, |
| 71 | + url="http://localhost/api/v4/projects/1/cluster_agents/1", |
| 72 | + status=204, |
| 73 | + ) |
| 74 | + yield rsps |
| 75 | + |
| 76 | + |
| 77 | +def test_list_project_cluster_agents(project, resp_list_project_cluster_agents): |
| 78 | + agent = project.cluster_agents.list()[0] |
| 79 | + assert isinstance(agent, ProjectClusterAgent) |
| 80 | + assert agent.name == "agent-1" |
| 81 | + |
| 82 | + |
| 83 | +def test_get_project_cluster_agent(project, resp_get_project_cluster_agent): |
| 84 | + agent = project.cluster_agents.get(1) |
| 85 | + assert isinstance(agent, ProjectClusterAgent) |
| 86 | + assert agent.name == "agent-1" |
| 87 | + |
| 88 | + |
| 89 | +def test_create_project_cluster_agent(project, resp_create_project_cluster_agent): |
| 90 | + agent = project.cluster_agents.create({"name": "agent-1"}) |
| 91 | + assert isinstance(agent, ProjectClusterAgent) |
| 92 | + assert agent.name == "agent-1" |
| 93 | + |
| 94 | + |
| 95 | +def test_delete_project_cluster_agent(project, resp_delete_project_cluster_agent): |
| 96 | + agent = project.cluster_agents.get(1, lazy=True) |
| 97 | + agent.delete() |
0 commit comments