Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_bound_volume_init(self, volume_response):
bound_volume = BoundVolume(
client=mock.MagicMock(),
data=volume_response['volume']
)
assert bound_volume.id == 1
assert bound_volume.created == isoparse("2016-01-30T23:50:11+00:00")
assert bound_volume.name == "database-storage"
assert isinstance(bound_volume.server, BoundServer)
assert bound_volume.server.id == 12
assert bound_volume.size == 42
assert bound_volume.linux_device == "/dev/disk/by-id/scsi-0HC_Volume_4711"
assert bound_volume.protection == {"delete": False}
assert bound_volume.labels == {}
assert bound_volume.status == "available"
assert isinstance(bound_volume.location, BoundLocation)
@pytest.mark.parametrize("volume", [Volume(id=1), BoundVolume(mock.MagicMock(), dict(id=1))])
def test_delete(self, volumes_client, volume, generic_action):
volumes_client._client.request.return_value = generic_action
delete_success = volumes_client.delete(volume)
volumes_client._client.request.assert_called_with(url="/volumes/1", method="DELETE")
assert delete_success is True
@pytest.mark.parametrize("volume", [Volume(id=1), BoundVolume(mock.MagicMock(), dict(id=1))])
def test_update(self, hetzner_client, volume):
volume = hetzner_client.volumes.update(volume, name="new-name", labels={})
assert volume.id == 4711
assert volume.name == "new-name"
assert bound_server.datacenter._client == bound_server._client._client.datacenters
assert bound_server.datacenter.id == 1
assert bound_server.datacenter.complete is True
assert isinstance(bound_server.server_type, BoundServerType)
assert bound_server.server_type._client == bound_server._client._client.server_types
assert bound_server.server_type.id == 1
assert bound_server.server_type.complete is True
assert len(bound_server.volumes) == 2
assert isinstance(bound_server.volumes[0], BoundVolume)
assert bound_server.volumes[0]._client == bound_server._client._client.volumes
assert bound_server.volumes[0].id == 1
assert bound_server.volumes[0].complete is False
assert isinstance(bound_server.volumes[1], BoundVolume)
assert bound_server.volumes[1]._client == bound_server._client._client.volumes
assert bound_server.volumes[1].id == 2
assert bound_server.volumes[1].complete is False
assert isinstance(bound_server.image, BoundImage)
assert bound_server.image._client == bound_server._client._client.images
assert bound_server.image.id == 4711
assert bound_server.image.name == "ubuntu-20.04"
assert bound_server.image.complete is True
assert isinstance(bound_server.iso, BoundIso)
assert bound_server.iso._client == bound_server._client._client.isos
assert bound_server.iso.id == 4711
assert bound_server.iso.name == "FreeBSD-11.0-RELEASE-amd64-dvd1"
assert bound_server.iso.complete is True
def test_create_with_volumes(self, servers_client, response_create_simple_server):
servers_client._client.request.return_value = response_create_simple_server
volumes = [Volume(id=1), BoundVolume(mock.MagicMock(), dict(id=2))]
response = servers_client.create(
"my-server",
server_type=ServerType(name="cx11"),
image=Image(id=4711),
volumes=volumes,
start_after_create=False
)
servers_client._client.request.assert_called_with(
url="/servers",
method="POST",
json={
'name': "my-server",
'server_type': "cx11",
'image': 4711,
'volumes': [1, 2],
"start_after_create": False
def bound_volume(self, hetzner_client):
return BoundVolume(client=hetzner_client.volumes, data=dict(id=14))
assert isinstance(bound_server.public_net.floating_ips[0], BoundFloatingIP)
assert bound_server.public_net.floating_ips[0].id == 478
assert bound_server.public_net.floating_ips[0].complete is False
assert isinstance(bound_server.datacenter, BoundDatacenter)
assert bound_server.datacenter._client == bound_server._client._client.datacenters
assert bound_server.datacenter.id == 1
assert bound_server.datacenter.complete is True
assert isinstance(bound_server.server_type, BoundServerType)
assert bound_server.server_type._client == bound_server._client._client.server_types
assert bound_server.server_type.id == 1
assert bound_server.server_type.complete is True
assert len(bound_server.volumes) == 2
assert isinstance(bound_server.volumes[0], BoundVolume)
assert bound_server.volumes[0]._client == bound_server._client._client.volumes
assert bound_server.volumes[0].id == 1
assert bound_server.volumes[0].complete is False
assert isinstance(bound_server.volumes[1], BoundVolume)
assert bound_server.volumes[1]._client == bound_server._client._client.volumes
assert bound_server.volumes[1].id == 2
assert bound_server.volumes[1].complete is False
assert isinstance(bound_server.image, BoundImage)
assert bound_server.image._client == bound_server._client._client.images
assert bound_server.image.id == 4711
assert bound_server.image.name == "ubuntu-20.04"
assert bound_server.image.complete is True
assert isinstance(bound_server.iso, BoundIso)
:return: (List[:class:`BoundVolume `], :class:`Meta `)
"""
params = {}
if name is not None:
params['name'] = name
if label_selector is not None:
params['label_selector'] = label_selector
if status is not None:
params["status"] = status
if page is not None:
params['page'] = page
if per_page is not None:
params['per_page'] = per_page
response = self._client.request(url="/volumes", method="GET", params=params)
volumes = [BoundVolume(self, volume_data) for volume_data in response['volumes']]
return self._add_meta_to_result(volumes, response)
if labels is not None:
data['labels'] = labels
if location is not None:
data['location'] = location.id_or_name
if server is not None:
data['server'] = server.id
if automount is not None:
data['automount'] = automount
if format is not None:
data['format'] = format
response = self._client.request(url="/volumes", json=data, method="POST")
result = CreateVolumeResponse(
volume=BoundVolume(self, response['volume']),
action=BoundAction(self._client.actions, response['action']),
next_actions=[BoundAction(self._client.actions, action) for action in response['next_actions']]
)
return result
def __init__(self, client, data, complete=True):
datacenter = data.get('datacenter')
if datacenter is not None:
data['datacenter'] = BoundDatacenter(client._client.datacenters, datacenter)
volumes = data.get('volumes', [])
if volumes:
volumes = [BoundVolume(client._client.volumes, {"id": volume}, complete=False) for volume in volumes]
data['volumes'] = volumes
image = data.get("image", None)
if image is not None:
data['image'] = BoundImage(client._client.images, image)
iso = data.get("iso", None)
if iso is not None:
data['iso'] = BoundIso(client._client.isos, iso)
server_type = data.get("server_type")
if server_type is not None:
data['server_type'] = BoundServerType(client._client.server_types, server_type)
public_net = data.get("public_net")
if public_net: