|
15 | 15 | import pytest
|
16 | 16 | from httpx import AsyncClient, BasicAuth
|
17 | 17 | from numpy import random
|
18 |
| -from osparc._models import ConfigurationModel |
| 18 | +from packaging.version import Version |
19 | 19 | from pydantic import ByteSize
|
20 | 20 |
|
| 21 | +try: |
| 22 | + from osparc._models import ConfigurationModel |
| 23 | +except ImportError: |
| 24 | + pass |
| 25 | + |
| 26 | + |
21 | 27 | _KB: ByteSize = ByteSize(1024) # in bytes
|
22 | 28 | _MB: ByteSize = ByteSize(_KB * 1024) # in bytes
|
23 | 29 | _GB: ByteSize = ByteSize(_MB * 1024) # in bytes
|
@@ -96,12 +102,21 @@ def api_client() -> Iterable[osparc.ApiClient]:
|
96 | 102 |
|
97 | 103 | @pytest.fixture
|
98 | 104 | def async_client() -> Iterable[AsyncClient]:
|
99 |
| - configuration = ConfigurationModel() |
| 105 | + if Version(osparc.__version__) >= Version("8.0.0"): |
| 106 | + configuration = ConfigurationModel() |
| 107 | + host = configuration.OSPARC_API_HOST.rstrip("/") |
| 108 | + username = configuration.OSPARC_API_KEY |
| 109 | + password = configuration.OSPARC_API_SECRET |
| 110 | + else: |
| 111 | + host = os.environ.get("OSPARC_API_HOST") |
| 112 | + username = os.environ.get("OSPARC_API_KEY") |
| 113 | + password = os.environ.get("OSPARC_API_SECRET") |
| 114 | + assert host and username and password |
100 | 115 | yield AsyncClient(
|
101 |
| - base_url=f"{configuration.OSPARC_API_HOST}".rstrip("/"), |
| 116 | + base_url=host, |
102 | 117 | auth=BasicAuth(
|
103 |
| - username=configuration.OSPARC_API_KEY, |
104 |
| - password=configuration.OSPARC_API_SECRET, |
| 118 | + username=username, |
| 119 | + password=password, |
105 | 120 | ),
|
106 | 121 | ) # type: ignore
|
107 | 122 |
|
|
0 commit comments