From 30f4ff36d4adb1f70a66c0959dad808d84cca472 Mon Sep 17 00:00:00 2001 From: shivam purohit Date: Sat, 30 Sep 2023 19:19:45 +0530 Subject: [PATCH 1/3] add volume_actions_list --- tests/mocked/test_block_storage.py | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/mocked/test_block_storage.py b/tests/mocked/test_block_storage.py index 4679b37f..1e2e7c98 100644 --- a/tests/mocked/test_block_storage.py +++ b/tests/mocked/test_block_storage.py @@ -329,3 +329,62 @@ def test_block_storage_snapshots_create(mock_client: Client, mock_client_url): ) assert create_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 From 2f0b84728aefd136a2863b6215492fbd65d5b74e Mon Sep 17 00:00:00 2001 From: shivam purohit Date: Sun, 1 Oct 2023 10:45:22 +0530 Subject: [PATCH 2/3] add volume tests --- tests/mocked/test_block_storage.py | 160 +++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/tests/mocked/test_block_storage.py b/tests/mocked/test_block_storage.py index 1e2e7c98..9fdd4ccb 100644 --- a/tests/mocked/test_block_storage.py +++ b/tests/mocked/test_block_storage.py @@ -330,6 +330,61 @@ 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""" @@ -388,3 +443,108 @@ def test_volume_actions_list(mock_client: Client, mock_client_url): 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 \ No newline at end of file From 1311a0fef016713e36409b835c181d365007eede Mon Sep 17 00:00:00 2001 From: shivam purohit Date: Mon, 2 Oct 2023 22:26:17 +0530 Subject: [PATCH 3/3] fix: lint --- tests/mocked/test_block_storage.py | 203 +++++++++++++---------------- 1 file changed, 91 insertions(+), 112 deletions(-) diff --git a/tests/mocked/test_block_storage.py b/tests/mocked/test_block_storage.py index 9fdd4ccb..c2b67707 100644 --- a/tests/mocked/test_block_storage.py +++ b/tests/mocked/test_block_storage.py @@ -335,14 +335,14 @@ def test_block_storage_snapshots_create(mock_client: Client, mock_client_url): 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": { + "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": [ @@ -359,19 +359,14 @@ def test_volume_actions_get(mock_client: Client, mock_client_url): "s-16vcpu-64gb", "s-20vcpu-96gb", "s-24vcpu-128gb", - "s-32vcpu-192gb" - ], - "features": [ - "private_networking", - "backups", - "ipv6", - "metadata" + "s-32vcpu-192gb", ], - "available": True - }, - "region_slug": "nyc1" - } + "features": ["private_networking", "backups", "ipv6", "metadata"], + "available": True, + }, + "region_slug": "nyc1", } + } responses.add( responses.GET, @@ -380,7 +375,9 @@ def test_volume_actions_get(mock_client: Client, mock_client_url): status=200, ) - get_resp = mock_client.volume_actions.get(volume_id="7724db7c", action_id="72531856") + get_resp = mock_client.volume_actions.get( + volume_id="7724db7c", action_id="72531856" + ) assert get_resp == expected @@ -389,8 +386,8 @@ def test_volume_actions_get(mock_client: Client, mock_client_url): def test_volume_actions_list(mock_client: Client, mock_client_url): """Tests retrieving all actions that have been executed on a volume""" expected = { - "actions": [ - { + "actions": [ + { "id": 72531856, "status": "completed", "type": "attach_volume", @@ -401,37 +398,30 @@ def test_volume_actions_list(mock_client: Client, mock_client_url): "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" + "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", ], - "available": True + "features": ["private_networking", "backups", "ipv6", "metadata"], + "available": True, }, - "region_slug": "nyc1" - } - ], - "links": {}, - "meta": { - "total": 1 + "region_slug": "nyc1", } - } + ], + "links": {}, + "meta": {"total": 1}, + } responses.add( responses.GET, @@ -449,52 +439,45 @@ def test_volume_actions_list(mock_client: Client, mock_client_url): 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" - ] + "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( @@ -504,9 +487,7 @@ def test_volume_actions_post(mock_client: Client, mock_client_url): status=202, ) - create_resp = mock_client.volume_actions.post( - body=post_body - ) + create_resp = mock_client.volume_actions.post(body=post_body) assert create_resp == expected @@ -516,24 +497,22 @@ 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" + "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" - ] + "tags": ["aninterestingtag"], } responses.add( @@ -547,4 +526,4 @@ def test_volume_actions_post_by_id(mock_client: Client, mock_client_url): volume_id="7724db7c", body=post_body ) - assert create_resp == expected \ No newline at end of file + assert create_resp == expected