Skip to content

Commit 7ffe2bd

Browse files
authored
test: Update E2E Tests, improve test fixture namin/teardowns (#341)
1 parent e6e0d45 commit 7ffe2bd

14 files changed

+477
-347
lines changed

test/integration/conftest.py

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55

6+
from linode_api4 import ApiError
67
from linode_api4.linode_client import LinodeClient
78

89
ENV_TOKEN_NAME = "LINODE_TOKEN"
@@ -29,15 +30,15 @@ def run_long_tests():
2930

3031

3132
@pytest.fixture(scope="session")
32-
def create_linode(get_client):
33-
client = get_client
33+
def create_linode(test_linode_client):
34+
client = test_linode_client
3435
available_regions = client.regions()
3536
chosen_region = available_regions[0]
36-
timestamp = str(int(time.time()))
37+
timestamp = str(time.time_ns())
3738
label = "TestSDK-" + timestamp
3839

3940
linode_instance, password = client.linode.instance_create(
40-
"g5-standard-4", chosen_region, image="linode/debian9", label=label
41+
"g6-nanode-1", chosen_region, image="linode/debian10", label=label
4142
)
4243

4344
yield linode_instance
@@ -46,15 +47,15 @@ def create_linode(get_client):
4647

4748

4849
@pytest.fixture
49-
def create_linode_for_pass_reset(get_client):
50-
client = get_client
50+
def create_linode_for_pass_reset(test_linode_client):
51+
client = test_linode_client
5152
available_regions = client.regions()
5253
chosen_region = available_regions[0]
53-
timestamp = str(int(time.time()))
54+
timestamp = str(time.time_ns())
5455
label = "TestSDK-" + timestamp
5556

5657
linode_instance, password = client.linode.instance_create(
57-
"g5-standard-4", chosen_region, image="linode/debian9", label=label
58+
"g6-nanode-1", chosen_region, image="linode/debian10", label=label
5859
)
5960

6061
yield linode_instance, password
@@ -80,7 +81,7 @@ def ssh_key_gen():
8081

8182

8283
@pytest.fixture(scope="session")
83-
def get_client():
84+
def test_linode_client():
8485
token = get_token()
8586
api_url = get_api_url()
8687
api_ca_file = get_api_ca_file()
@@ -93,8 +94,8 @@ def get_client():
9394

9495

9596
@pytest.fixture
96-
def set_account_settings(get_client):
97-
client = get_client
97+
def test_account_settings(test_linode_client):
98+
client = test_linode_client
9899
account_settings = client.account.settings()
99100
account_settings._populated = True
100101
account_settings.network_helper = True
@@ -103,10 +104,10 @@ def set_account_settings(get_client):
103104

104105

105106
@pytest.fixture(scope="session")
106-
def create_domain(get_client):
107-
client = get_client
107+
def test_domain(test_linode_client):
108+
client = test_linode_client
108109

109-
timestamp = str(int(time.time()))
110+
timestamp = str(time.time_ns())
110111
domain_addr = timestamp + "-example.com"
111112
soa_email = "[email protected]"
112113

@@ -130,23 +131,36 @@ def create_domain(get_client):
130131

131132

132133
@pytest.fixture(scope="session")
133-
def create_volume(get_client):
134-
client = get_client
135-
timestamp = str(int(time.time()))
134+
def test_volume(test_linode_client):
135+
client = test_linode_client
136+
timestamp = str(time.time_ns())
136137
label = "TestSDK-" + timestamp
137138

138139
volume = client.volume_create(label=label, region="ap-west")
139140

140141
yield volume
141142

142-
volume.delete()
143+
timeout = 100 # give 100s for volume to be detached before deletion
144+
145+
start_time = time.time()
146+
147+
while time.time() - start_time < timeout:
148+
try:
149+
res = volume.delete()
150+
if res:
151+
break
152+
else:
153+
time.sleep(3)
154+
except ApiError as e:
155+
if time.time() - start_time > timeout:
156+
raise e
143157

144158

145159
@pytest.fixture
146-
def create_tag(get_client):
147-
client = get_client
160+
def test_tag(test_linode_client):
161+
client = test_linode_client
148162

149-
timestamp = str(int(time.time()))
163+
timestamp = str(time.time_ns())
150164
label = "TestSDK-" + timestamp
151165

152166
tag = client.tag_create(label=label)
@@ -157,10 +171,10 @@ def create_tag(get_client):
157171

158172

159173
@pytest.fixture
160-
def create_nodebalancer(get_client):
161-
client = get_client
174+
def test_nodebalancer(test_linode_client):
175+
client = test_linode_client
162176

163-
timestamp = str(int(time.time()))
177+
timestamp = str(time.time_ns())
164178
label = "TestSDK-" + timestamp
165179

166180
nodebalancer = client.nodebalancer_create(region="us-east", label=label)
@@ -171,9 +185,9 @@ def create_nodebalancer(get_client):
171185

172186

173187
@pytest.fixture
174-
def create_longview_client(get_client):
175-
client = get_client
176-
timestamp = str(int(time.time()))
188+
def test_longview_client(test_linode_client):
189+
client = test_linode_client
190+
timestamp = str(time.time_ns())
177191
label = "TestSDK-" + timestamp
178192
longview_client = client.longview.client_create(label=label)
179193

@@ -183,9 +197,9 @@ def create_longview_client(get_client):
183197

184198

185199
@pytest.fixture
186-
def upload_sshkey(get_client, ssh_key_gen):
200+
def test_sshkey(test_linode_client, ssh_key_gen):
187201
pub_key = ssh_key_gen[0]
188-
client = get_client
202+
client = test_linode_client
189203
key = client.profile.ssh_key_upload(pub_key, "IntTestSDK-sshkey")
190204

191205
yield key
@@ -194,8 +208,8 @@ def upload_sshkey(get_client, ssh_key_gen):
194208

195209

196210
@pytest.fixture
197-
def create_ssh_keys_object_storage(get_client):
198-
client = get_client
211+
def ssh_keys_object_storage(test_linode_client):
212+
client = test_linode_client
199213
label = "TestSDK-obj-storage-key"
200214
key = client.object_storage.keys_create(label)
201215

@@ -205,8 +219,8 @@ def create_ssh_keys_object_storage(get_client):
205219

206220

207221
@pytest.fixture(scope="session")
208-
def create_firewall(get_client):
209-
client = get_client
222+
def test_firewall(test_linode_client):
223+
client = test_linode_client
210224
rules = {
211225
"outbound": [],
212226
"outbound_policy": "DROP",
@@ -224,8 +238,8 @@ def create_firewall(get_client):
224238

225239

226240
@pytest.fixture
227-
def create_oauth_client(get_client):
228-
client = get_client
241+
def test_oauth_client(test_linode_client):
242+
client = test_linode_client
229243
oauth_client = client.account.oauth_client_create(
230244
"test-oauth-client", "https://localhost/oauth/callback"
231245
)

0 commit comments

Comments
 (0)