Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mocked Tests: Volume Actions #214

Merged
merged 3 commits into from
Oct 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 198 additions & 0 deletions tests/mocked/test_block_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,201 @@ def test_block_storage_snapshots_create(mock_client: Client, mock_client_url):
)

assert create_resp == expected


@responses.activate
def test_volume_actions_get(mock_client: Client, mock_client_url):
"""Tests to retrieve the status of a volume action"""
expected = {
"action": {
"id": 72531856,
"status": "completed",
"type": "attach_volume",
"started_at": "2020-11-12T17:51:03Z",
"completed_at": "2020-11-12T17:51:14Z",
"resource_type": "volume",
"region": {
"name": "New York 1",
"slug": "nyc1",
"sizes": [
"s-1vcpu-1gb",
"s-1vcpu-2gb",
"s-1vcpu-3gb",
"s-2vcpu-2gb",
"s-3vcpu-1gb",
"s-2vcpu-4gb",
"s-4vcpu-8gb",
"s-6vcpu-16gb",
"s-8vcpu-32gb",
"s-12vcpu-48gb",
"s-16vcpu-64gb",
"s-20vcpu-96gb",
"s-24vcpu-128gb",
"s-32vcpu-192gb",
],
"features": ["private_networking", "backups", "ipv6", "metadata"],
"available": True,
},
"region_slug": "nyc1",
}
}

responses.add(
responses.GET,
f"{mock_client_url}/v2/volumes/7724db7c/actions/72531856",
json=expected,
status=200,
)

get_resp = mock_client.volume_actions.get(
volume_id="7724db7c", action_id="72531856"
)

assert get_resp == expected


@responses.activate
def test_volume_actions_list(mock_client: Client, mock_client_url):
"""Tests retrieving all actions that have been executed on a volume"""
expected = {
"actions": [
{
"id": 72531856,
"status": "completed",
"type": "attach_volume",
"started_at": "2020-11-21T21:51:09Z",
"completed_at": "2020-11-21T21:51:09Z",
"resource_type": "volume",
"region": {
"name": "New York 1",
"slug": "nyc1",
"sizes": [
"s-1vcpu-1gb",
"s-1vcpu-2gb",
"s-1vcpu-3gb",
"s-2vcpu-2gb",
"s-3vcpu-1gb",
"s-2vcpu-4gb",
"s-4vcpu-8gb",
"s-6vcpu-16gb",
"s-8vcpu-32gb",
"s-12vcpu-48gb",
"s-16vcpu-64gb",
"s-20vcpu-96gb",
"s-24vcpu-128gb",
"s-32vcpu-192gb",
],
"features": ["private_networking", "backups", "ipv6", "metadata"],
"available": True,
},
"region_slug": "nyc1",
}
],
"links": {},
"meta": {"total": 1},
}

responses.add(
responses.GET,
f"{mock_client_url}/v2/volumes/7724db7c/actions",
json=expected,
status=200,
)

get_resp = mock_client.volume_actions.list(volume_id="7724db7c")

assert get_resp == expected


@responses.activate
def test_volume_actions_post(mock_client: Client, mock_client_url):
"""Tests to initiate an action on a block storage volume by Name"""
expected = {
"action": {
"id": 72531856,
"status": "completed",
"type": "attach_volume",
"started_at": "2020-11-12T17:51:03Z",
"completed_at": "2020-11-12T17:51:14Z",
"resource_type": "volume",
"region": {
"name": "New York 1",
"slug": "nyc1",
"sizes": [
"s-1vcpu-1gb",
"s-1vcpu-2gb",
"s-1vcpu-3gb",
"s-2vcpu-2gb",
"s-3vcpu-1gb",
"s-2vcpu-4gb",
"s-4vcpu-8gb",
"s-6vcpu-16gb",
"s-8vcpu-32gb",
"s-12vcpu-48gb",
"s-16vcpu-64gb",
"s-20vcpu-96gb",
"s-24vcpu-128gb",
"s-32vcpu-192gb",
],
"features": ["private_networking", "backups", "ipv6", "metadata"],
"available": True,
},
"region_slug": "nyc1",
}
}

post_body = {
"type": "attach",
"volume_name": "example",
"droplet_id": 11612190,
"region": "nyc1",
"tags": ["aninterestingtag"],
}

responses.add(
responses.POST,
f"{mock_client_url}/v2/volumes/actions",
json=expected,
status=202,
)

create_resp = mock_client.volume_actions.post(body=post_body)

assert create_resp == expected


@responses.activate
def test_volume_actions_post_by_id(mock_client: Client, mock_client_url):
"""Tests to initiate an action on a block storage volume by Id"""
expected = {
"action": {
"id": 72531856,
"status": "completed",
"type": "attach_volume",
"started_at": "2020-11-12T17:51:03Z",
"completed_at": "2020-11-12T17:51:14Z",
"resource_type": "volume",
"region": {},
"region_slug": "nyc1",
}
}

post_body = {
"type": "attach",
"droplet_id": 11612190,
"region": "nyc1",
"tags": ["aninterestingtag"],
}

responses.add(
responses.POST,
f"{mock_client_url}/v2/volumes/7724db7c/actions",
json=expected,
status=202,
)

create_resp = mock_client.volume_actions.post_by_id(
volume_id="7724db7c", body=post_body
)

assert create_resp == expected
Loading