-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathtest_cloud_e2e.py
More file actions
65 lines (52 loc) 路 2.31 KB
/
Copy pathtest_cloud_e2e.py
File metadata and controls
65 lines (52 loc) 路 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import csv
import os
import pytest
from httpx import ASGITransport, AsyncClient
from boaviztapi import data_dir
from boaviztapi.main import app
from .util import CloudInstanceRequest
cloud_path = os.path.join(data_dir, "archetypes/cloud")
pytest_plugins = ("pytest_asyncio",)
# Generate test cases for all instances, across all providers
def _generate_cloud_provider_urls():
urls = []
try:
with open(f"{cloud_path}/providers.csv", "r") as providers_fh:
provider_reader = csv.DictReader(providers_fh)
for provider_row in provider_reader:
provider_name = provider_row.get("provider.name")
provider_csv_path = f"{cloud_path}/{provider_name}.csv"
try:
with open(provider_csv_path, "r") as instances_fh:
instances_reader = csv.DictReader(instances_fh)
for instances_row in instances_reader:
instance_id = instances_row.get("id")
request = CloudInstanceRequest(
provider_name,
instance_id,
use_url_params=True,
usage={
"usage_location": "FRA",
},
)
urls.append((request.to_url()))
except FileNotFoundError:
pytest.fail(
f"CSV file for provider '{provider_name}' not found: {provider_csv_path}"
)
except FileNotFoundError:
pytest.fail(f"provider file not found : {cloud_path}/providers.csv")
return urls
def pytest_generate_tests(metafunc):
if "cloud_provider_url" in metafunc.fixturenames:
cloud_provider_urls = _generate_cloud_provider_urls()
metafunc.parametrize("cloud_provider_url", cloud_provider_urls)
@pytest.mark.e2e
@pytest.mark.asyncio
async def test_all_instances(cloud_provider_url):
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.get(cloud_provider_url)
assert res.status_code in [200, 201], (
f"Http error status code {res.status_code}"
)