Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(SomeDomain(id=1), 1),
(SomeDomain(name="name"), "name"),
])
def test_id_or_name_ok(self, domain, expected_result):
assert domain.id_or_name == expected_result
def test_id_or_name_exception(self):
domain = SomeDomain()
with pytest.raises(ValueError) as exception_info:
domain.id_or_name
error = exception_info.value
assert str(error) == "id or name must be set"
class ActionDomain(BaseDomain, DomainIdentityMixin):
__slots__ = ("id", "name", "started")
def __init__(self, id, name="name1", started=None):
self.id = id
self.name = name
self.started = isoparse(started) if started else None
class TestBaseDomain(object):
@pytest.mark.parametrize(
"data_dict,expected_result",
[
({"id": 1},
{"id": 1, "name": "name1", "started": None}
),
"next_page": 3,
"last_page": 10,
"total_entries": 100
}
}
}
result = add_meta_to_result([1, 2, 3], json_content, "id_list")
assert result.id_list == [1, 2, 3]
assert result.meta.pagination.page == 2
assert result.meta.pagination.per_page == 10
assert result.meta.pagination.next_page == 3
assert result.meta.pagination.last_page == 10
assert result.meta.pagination.total_entries == 100
class SomeDomain(BaseDomain, DomainIdentityMixin):
__slots__ = ("id", "name")
def __init__(self, id=None, name=None):
self.id = id
self.name = name
class TestDomainIdentityMixin(object):
@pytest.mark.parametrize(
"domain,expected_result",
[
(SomeDomain(id=1, name="name"), 1),
(SomeDomain(id=1), 1),
(SomeDomain(name="name"), "name"),
])
# -*- coding: utf-8 -*-
from dateutil.parser import isoparse
from hcloud.core.domain import BaseDomain, DomainIdentityMixin
class Iso(BaseDomain, DomainIdentityMixin):
"""Iso Domain
:param id: int
ID of the ISO
:param name: str, None
Unique identifier of the ISO. Only set for public ISOs
:param description: str
Description of the ISO
:param type: str
Type of the ISO. Choices: `public`, `private`
:param deprecated: datetime, None
ISO 8601 timestamp of deprecation, None if ISO is still available. After the deprecation time it will no longer be possible to attach the ISO to servers.
"""
__slots__ = (
"id",
# -*- coding: utf-8 -*-
from hcloud.core.domain import BaseDomain, DomainIdentityMixin
class Location(BaseDomain, DomainIdentityMixin):
"""Location Domain
:param id: int
ID of location
:param name: str
Name of location
:param description: str
Description of location
:param country: str
ISO 3166-1 alpha-2 code of the country the location resides in
:param city: str
City the location is closest to
:param latitude: float
Latitude of the city closest to the location
:param longitude: float
Longitude of the city closest to the location
# -*- coding: utf-8 -*-
from dateutil.parser import isoparse
from hcloud.core.domain import BaseDomain, DomainIdentityMixin
class SSHKey(BaseDomain, DomainIdentityMixin):
"""SSHKey Domain
:param id: int
ID of the SSH key
:param name: str
Name of the SSH key (must be unique per project)
:param fingerprint: str
Fingerprint of public key
:param public_key: str
Public Key
:param labels: Dict
User-defined labels (key-value pairs)
:param created: datetime
Point in time when the SSH Key was created
"""
__slots__ = (
# -*- coding: utf-8 -*-
from hcloud.core.domain import BaseDomain, DomainIdentityMixin
class Datacenter(BaseDomain, DomainIdentityMixin):
"""Datacenter Domain
:param id: int ID of Datacenter
:param name: str Name of Datacenter
:param description: str Description of Datacenter
:param location: :class:`BoundLocation `
:param server_types: :class:`DatacenterServerTypes `
"""
__slots__ = (
"id",
"name",
"description",
"location",
"server_types",
)
# -*- coding: utf-8 -*-
from hcloud.core.domain import BaseDomain, DomainIdentityMixin
class ServerType(BaseDomain, DomainIdentityMixin):
"""ServerType Domain
:param id: int
ID of the server type
:param name: str
Unique identifier of the server type
:param description: str
Description of the server type
:param cores: int
Number of cpu cores a server of this type will have
:param memory: int
Memory a server of this type will have in GB
:param disk: int
Disk size a server of this type will have in GB
:param prices: Dict
Prices in different locations
# -*- coding: utf-8 -*-
from dateutil.parser import isoparse
from hcloud.core.domain import BaseDomain, DomainIdentityMixin
class Image(BaseDomain, DomainIdentityMixin):
"""Image Domain
:param id: int
ID of the image
:param type: str
Type of the image Choices: `system`, `snapshot`, `backup`
:param status: str
Whether the image can be used or if it’s still being created Choices: `available`, `creating`
:param name: str, None
Unique identifier of the image. This value is only set for system images.
:param description: str
Description of the image
:param image_size: number, None
Size of the image file in our storage in GB. For snapshot images this is the value relevant for calculating costs for the image.
:param disk_size: number
Size of the disk contained in the image in GB.
# -*- coding: utf-8 -*-
from dateutil.parser import isoparse
from hcloud.core.domain import BaseDomain, DomainIdentityMixin
class Volume(BaseDomain, DomainIdentityMixin):
"""Volume Domain
:param id: int
ID of the Volume
:param name: str
Name of the Volume
:param server: :class:`BoundServer `, None
Server the Volume is attached to, None if it is not attached at all.
:param created: datetime
Point in time when the Volume was created
:param location: :class:`BoundLocation `
Location of the Volume. Volume can only be attached to Servers in the same location.
:param size: int
Size in GB of the Volume
:param linux_device: str
Device path on the file system for the Volume