Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ module-root = ""

[tool.ruff]
# TODO(shamrin) fix these errors and stop ignoring them
lint.ignore = ["E721", "E711", "E712", "F401"]
lint.ignore = ["F401"]
16 changes: 8 additions & 8 deletions tests/unit_tests/authentication/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ def test_authenticate_successful(self, authentication_service, endpoint):
auth_data = authentication_service.authenticate()

# assert
assert type(auth_data) == dict
assert isinstance(auth_data, dict)
assert authentication_service._access_token == ACCESS_TOKEN
assert authentication_service._refresh_token == REFRESH_TOKEN
assert authentication_service._scope == SCOPE
assert authentication_service._token_type == TOKEN_TYPE
assert authentication_service._expires_at != None
assert authentication_service._expires_at is not None
assert responses.assert_call_count(endpoint, 1) is True

def test_authenticate_failed(self, authentication_service, endpoint):
Expand Down Expand Up @@ -117,23 +117,23 @@ def test_refresh_successful(self, authentication_service, endpoint):
auth_data = authentication_service.authenticate() # authenticate first

# assert
assert type(auth_data) == dict
assert isinstance(auth_data, dict)
assert authentication_service._access_token == ACCESS_TOKEN
assert authentication_service._refresh_token == REFRESH_TOKEN
assert authentication_service._scope == SCOPE
assert authentication_service._token_type == TOKEN_TYPE
assert authentication_service._expires_at != None
assert authentication_service._expires_at is not None
assert responses.calls[0].request.body == f'{{"grant_type": "client_credentials", "client_id": "{CLIENT_ID}", "client_secret": "{CLIENT_SECRET}"}}'.encode(
)

auth_data2 = authentication_service.refresh() # refresh

assert type(auth_data2) == dict
assert isinstance(auth_data2, dict)
assert authentication_service._access_token == ACCESS_TOKEN2
assert authentication_service._refresh_token == REFRESH_TOKEN2
assert authentication_service._scope == SCOPE
assert authentication_service._token_type == TOKEN_TYPE
assert authentication_service._expires_at != None
assert authentication_service._expires_at is not None
assert responses.calls[1].request.body == f'{{"grant_type": "refresh_token", "refresh_token": "{REFRESH_TOKEN}"}}'.encode(
)
assert responses.assert_call_count(endpoint, 2) is True
Expand Down Expand Up @@ -196,5 +196,5 @@ def test_is_expired(self, authentication_service, endpoint):
is_expired_future = authentication_service.is_expired()

# assert
assert is_expired_current == True
assert is_expired_future == False
assert is_expired_current
assert not is_expired_future
6 changes: 3 additions & 3 deletions tests/unit_tests/balance/test_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def test_balance(http_client):
balance = balance_service.get()

# assert
assert type(balance) == Balance
assert type(balance.amount) == float
assert type(balance.currency) == str
assert isinstance(balance, Balance)
assert isinstance(balance.amount, float)
assert isinstance(balance.currency, str)
assert balance.amount == 50.5
assert balance.currency == "usd"
42 changes: 21 additions & 21 deletions tests/unit_tests/containers/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ def test_get_deployments(self, containers_service, deployments_endpoint):
deployment = deployments[0]

# assert
assert type(deployments) == list
assert isinstance(deployments, list)
assert len(deployments) == 1
assert type(deployment) == Deployment
assert isinstance(deployment, Deployment)
assert deployment.name == DEPLOYMENT_NAME
assert len(deployment.containers) == 1
assert type(deployment.containers[0]) == Container
assert type(deployment.compute) == ComputeResource
assert isinstance(deployment.containers[0], Container)
assert isinstance(deployment.compute, ComputeResource)
assert deployment.compute.name == COMPUTE_RESOURCE_NAME_GENERAL_COMPUTE
assert responses.assert_call_count(deployments_endpoint, 1) is True

Expand All @@ -238,7 +238,7 @@ def test_get_deployment_by_name(self, containers_service, deployments_endpoint):
deployment = containers_service.get_deployment_by_name(DEPLOYMENT_NAME)

# assert
assert type(deployment) == Deployment
assert isinstance(deployment, Deployment)
assert deployment.name == DEPLOYMENT_NAME
assert len(deployment.containers) == 1
assert deployment.containers[0].name == CONTAINER_NAME
Expand Down Expand Up @@ -306,7 +306,7 @@ def test_create_deployment(self, containers_service, deployments_endpoint):
created_deployment = containers_service.create_deployment(deployment)

# assert
assert type(created_deployment) == Deployment
assert isinstance(created_deployment, Deployment)
assert created_deployment.name == DEPLOYMENT_NAME
assert len(created_deployment.containers) == 1
assert created_deployment.containers[0].name == CONTAINER_NAME
Expand Down Expand Up @@ -349,7 +349,7 @@ def test_update_deployment(self, containers_service, deployments_endpoint):
DEPLOYMENT_NAME, deployment)

# assert
assert type(updated_deployment) == Deployment
assert isinstance(updated_deployment, Deployment)
assert updated_deployment.name == DEPLOYMENT_NAME
assert len(updated_deployment.containers) == 1
assert updated_deployment.containers[0].name == CONTAINER_NAME
Expand Down Expand Up @@ -649,12 +649,12 @@ def test_get_compute_resources(self, containers_service, compute_resources_endpo
resources = containers_service.get_compute_resources()

# assert
assert type(resources) == list
assert isinstance(resources, list)
assert len(resources) == 2
assert type(resources[0]) == ComputeResource
assert isinstance(resources[0], ComputeResource)
assert resources[0].name == COMPUTE_RESOURCE_NAME_GENERAL_COMPUTE
assert resources[0].size == 1
assert resources[0].is_available == True
assert resources[0].is_available
assert responses.assert_call_count(
compute_resources_endpoint, 1) is True

Expand All @@ -672,12 +672,12 @@ def test_get_compute_resources_filter_by_size(self, containers_service, compute_
resources = containers_service.get_compute_resources(size=4)

# assert
assert type(resources) == list
assert isinstance(resources, list)
assert len(resources) == 1
assert type(resources[0]) == ComputeResource
assert isinstance(resources[0], ComputeResource)
assert resources[0].name == COMPUTE_RESOURCE_NAME_H100
assert resources[0].size == 4
assert resources[0].is_available == True
assert resources[0].is_available
assert responses.assert_call_count(
compute_resources_endpoint, 1) is True

Expand All @@ -695,9 +695,9 @@ def test_get_compute_resources_filter_by_availability(self, containers_service,
resources = containers_service.get_compute_resources(is_available=True)

# assert
assert type(resources) == list
assert isinstance(resources, list)
assert len(resources) == 2
assert all(r.is_available == True for r in resources)
assert all(r.is_available for r in resources)
assert responses.assert_call_count(
compute_resources_endpoint, 1) is True

Expand All @@ -716,11 +716,11 @@ def test_get_compute_resources_filter_by_size_and_availability(self, containers_
size=1, is_available=True)

# assert
assert type(resources) == list
assert isinstance(resources, list)
assert len(resources) == 1
assert resources[0].name == COMPUTE_RESOURCE_NAME_GENERAL_COMPUTE
assert resources[0].size == 1
assert resources[0].is_available == True
assert resources[0].is_available
assert responses.assert_call_count(
compute_resources_endpoint, 1) is True

Expand All @@ -738,9 +738,9 @@ def test_get_secrets(self, containers_service, secrets_endpoint):
secrets = containers_service.get_secrets()

# assert
assert type(secrets) == list
assert isinstance(secrets, list)
assert len(secrets) == 1
assert type(secrets[0]) == Secret
assert isinstance(secrets[0], Secret)
assert secrets[0].name == SECRET_NAME
assert responses.assert_call_count(secrets_endpoint, 1) is True

Expand Down Expand Up @@ -815,9 +815,9 @@ def test_get_registry_credentials(self, containers_service, registry_credentials
credentials = containers_service.get_registry_credentials()

# assert
assert type(credentials) == list
assert isinstance(credentials, list)
assert len(credentials) == 1
assert type(credentials[0]) == RegistryCredential
assert isinstance(credentials[0], RegistryCredential)
assert credentials[0].name == REGISTRY_CREDENTIAL_NAME
assert responses.assert_call_count(
registry_credentials_endpoint, 1) is True
Expand Down
12 changes: 6 additions & 6 deletions tests/unit_tests/http_client/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_generate_bearer_header(self, http_client):
bearer_string = http_client._generate_bearer_header()
access_token = http_client._auth_service._access_token

assert type(bearer_string) == str
assert isinstance(bearer_string, str)
assert bearer_string == f'Bearer {access_token}'

def test_generate_user_agent(self, http_client):
Expand All @@ -39,7 +39,7 @@ def test_generate_user_agent(self, http_client):
user_agent_string = http_client._generate_user_agent()

# assert
assert type(user_agent_string) == str
assert isinstance(user_agent_string, str)
assert user_agent_string == f'datacrunch-python-v{version}-{client_id_truncated}'

def test_generate_headers(self, http_client):
Expand All @@ -49,10 +49,10 @@ def test_generate_headers(self, http_client):
user_agent_string = http_client._generate_user_agent()

# assert
assert type(headers) == dict
assert type(headers['Content-Type']) == str
assert type(headers['Authorization']) == str
assert type(headers['User-Agent']) == str
assert isinstance(headers, dict)
assert isinstance(headers['Content-Type'], str)
assert isinstance(headers['Authorization'], str)
assert isinstance(headers['User-Agent'], str)
assert headers['Content-Type'] == 'application/json'
assert headers['Authorization'] == authorization_string
assert headers['User-Agent'] == user_agent_string
Expand Down
8 changes: 4 additions & 4 deletions tests/unit_tests/images/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ def test_images(http_client):
images = image_service.get()

# assert
assert type(images) == list
assert isinstance(images, list)
assert len(images) == 1
assert type(images[0]) == Image
assert isinstance(images[0], Image)
assert images[0].id == '0888da25-bb0d-41cc-a191-dccae45d96fd'
assert images[0].name == 'Ubuntu 20.04 + CUDA 11.0'
assert images[0].image_type == 'ubuntu-20.04-cuda-11.0'
assert type(images[0].details) == list
assert isinstance(images[0].details, list)
assert images[0].details[0] == "Ubuntu 20.04"
assert images[0].details[1] == "CUDA 11.0"
assert type(images[0].__str__()) == str
assert isinstance(images[0].__str__(), str)

12 changes: 6 additions & 6 deletions tests/unit_tests/instance_types/test_instance_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ def test_instance_types(http_client):
instance_type = instance_types[0]

# assert
assert type(instance_types) == list
assert isinstance(instance_types, list)
assert len(instance_types) == 1
assert type(instance_type) == InstanceType
assert isinstance(instance_type, InstanceType)
assert instance_type.id == TYPE_ID
assert instance_type.description == INSTANCE_TYPE_DESCRIPTION
assert instance_type.price_per_hour == PRICE_PER_HOUR
assert instance_type.spot_price_per_hour == SPOT_PRICE_PER_HOUR
assert instance_type.instance_type == INSTANCE_TYPE
assert type(instance_type.cpu) == dict
assert type(instance_type.gpu) == dict
assert type(instance_type.memory) == dict
assert type(instance_type.storage) == dict
assert isinstance(instance_type.cpu, dict)
assert isinstance(instance_type.gpu, dict)
assert isinstance(instance_type.memory, dict)
assert isinstance(instance_type.storage, dict)
assert instance_type.cpu['description'] == CPU_DESCRIPTION
assert instance_type.gpu['description'] == GPU_DESCRIPTION
assert instance_type.memory['description'] == MEMORY_DESCRIPTION
Expand Down
Loading