Skip to content

Commit 436c77a

Browse files
committed
added some integration tests
1 parent c77dc1b commit 436c77a

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import os
2+
import pytest
3+
from datacrunch.datacrunch import DataCrunchClient
4+
from datacrunch.constants import Locations
5+
6+
IN_GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true"
7+
8+
9+
@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.")
10+
@pytest.mark.withoutresponses
11+
class TestInstances():
12+
13+
def test_create_instance(self, datacrunch_client: DataCrunchClient):
14+
# get ssh key
15+
ssh_key = datacrunch_client.ssh_keys.get()[0]
16+
17+
# create instance
18+
instance = datacrunch_client.instances.create(
19+
hostname="test-instance",
20+
location=Locations.FIN_01,
21+
instance_type='CPU.4V',
22+
description="test instance",
23+
image="ubuntu-18.04",
24+
ssh_key_ids=[ssh_key.id])
25+
26+
# assert instance is created
27+
assert instance.id is not None
28+
assert instance.status == datacrunch_client.constants.instance_status.PROVISIONING
29+
30+
# delete instance
31+
datacrunch_client.instances.action(instance.id, "delete")
32+
33+
# permanently delete all volumes in trash
34+
trash = datacrunch_client.volumes.get_in_trash()
35+
for volume in trash:
36+
datacrunch_client.volumes.delete(volume.id, is_permanent=True)

tests/integration_tests/test_volumes.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import os
22
import pytest
33
from datacrunch.datacrunch import DataCrunchClient
4+
from datacrunch.constants import Locations, VolumeTypes, VolumeStatus
45

56
IN_GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true"
67

78

9+
NVMe = VolumeTypes.NVMe
10+
11+
812
@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.")
913
@pytest.mark.withoutresponses
1014
class TestVolumes():
1115

1216
def test_get_volumes_from_trash(self, datacrunch_client: DataCrunchClient):
1317
# create new volume
1418
volume = datacrunch_client.volumes.create(
15-
type=datacrunch_client.constants.volume_types.NVMe, name="test_volume", size=100)
19+
type=NVMe, name="test_volume", size=100)
1620

1721
# delete volume
1822
datacrunch_client.volumes.delete(volume.id)
@@ -29,7 +33,7 @@ def test_get_volumes_from_trash(self, datacrunch_client: DataCrunchClient):
2933
def test_permanently_delete_detached_volumes(seld, datacrunch_client):
3034
# create new volume
3135
volume = datacrunch_client.volumes.create(
32-
type=datacrunch_client.constants.volume_types.NVMe, name="test_volume", size=100)
36+
type=NVMe, name="test_volume", size=100)
3337

3438
# permanently delete the detached volume
3539
datacrunch_client.volumes.delete(volume.id, is_permanent=True)
@@ -49,7 +53,7 @@ def test_permanently_delete_detached_volumes(seld, datacrunch_client):
4953
def test_permanently_delete_a_deleted_volume_from_trash(self, datacrunch_client):
5054
# create new volume
5155
volume = datacrunch_client.volumes.create(
52-
type=datacrunch_client.constants.volume_types.NVMe, name="test_volume", size=100)
56+
type=NVMe, name="test_volume", size=100)
5357

5458
# delete volume
5559
datacrunch_client.volumes.delete(volume.id)
@@ -68,3 +72,16 @@ def test_permanently_delete_a_deleted_volume_from_trash(self, datacrunch_client)
6872

6973
# assert volume is not in trash
7074
assert volume.id not in [v.id for v in volumes]
75+
76+
def test_create_volume(self, datacrunch_client):
77+
# create new volume
78+
volume = datacrunch_client.volumes.create(
79+
type=NVMe, name="test_volume", size=100, location=Locations.FIN_01)
80+
81+
# assert volume is created
82+
assert volume.id is not None
83+
assert volume.location == Locations.FIN_01
84+
assert volume.status == VolumeStatus.ORDERED or volume.status == VolumeStatus.DETACHED
85+
86+
# cleaning: delete volume
87+
datacrunch_client.volumes.delete(volume.id, is_permanent=True)

0 commit comments

Comments
 (0)