proximl 0.5.10__py3-none-any.whl → 0.5.11__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- proximl/__init__.py +1 -1
- proximl/checkpoints.py +46 -28
- proximl/cli/cloudbender/__init__.py +2 -1
- proximl/cli/cloudbender/datastore.py +2 -7
- proximl/cli/cloudbender/service.py +19 -2
- proximl/cli/project/__init__.py +3 -72
- proximl/cli/project/data_connector.py +61 -0
- proximl/cli/project/datastore.py +61 -0
- proximl/cli/project/service.py +61 -0
- proximl/cloudbender/cloudbender.py +4 -2
- proximl/cloudbender/data_connectors.py +8 -0
- proximl/cloudbender/datastores.py +9 -19
- proximl/cloudbender/nodes.py +44 -1
- proximl/cloudbender/providers.py +53 -0
- proximl/cloudbender/regions.py +48 -0
- proximl/cloudbender/services.py +65 -1
- proximl/datasets.py +41 -12
- proximl/exceptions.py +51 -0
- proximl/jobs.py +15 -19
- proximl/models.py +41 -22
- proximl/volumes.py +24 -5
- {proximl-0.5.10.dist-info → proximl-0.5.11.dist-info}/METADATA +1 -1
- {proximl-0.5.10.dist-info → proximl-0.5.11.dist-info}/RECORD +48 -46
- tests/integration/projects/conftest.py +3 -1
- tests/integration/projects/test_projects_data_connectors_integration.py +44 -0
- tests/integration/projects/test_projects_datastores_integration.py +42 -0
- tests/integration/projects/test_projects_services_integration.py +44 -0
- tests/integration/test_checkpoints_integration.py +1 -2
- tests/integration/test_jobs_integration.py +13 -0
- tests/integration/test_models_integration.py +0 -1
- tests/unit/cli/projects/__init__.py +0 -0
- tests/unit/cli/projects/test_cli_project_data_connector_unit.py +28 -0
- tests/unit/cli/projects/test_cli_project_datastore_unit.py +26 -0
- tests/unit/cli/projects/test_cli_project_key_unit.py +26 -0
- tests/unit/cli/projects/test_cli_project_secret_unit.py +26 -0
- tests/unit/cli/projects/test_cli_project_service_unit.py +26 -0
- tests/unit/cli/projects/test_cli_project_unit.py +19 -0
- tests/unit/cloudbender/test_datastores_unit.py +1 -5
- tests/unit/cloudbender/test_services_unit.py +6 -0
- tests/unit/conftest.py +158 -15
- tests/unit/test_checkpoints_unit.py +15 -23
- tests/unit/test_datasets_unit.py +15 -20
- tests/unit/test_models_unit.py +13 -16
- tests/unit/test_volumes_unit.py +3 -0
- proximl/cli/cloudbender/reservation.py +0 -159
- proximl/cli/project.py +0 -154
- proximl/cloudbender/reservations.py +0 -126
- proximl/projects.py +0 -187
- tests/integration/test_projects_integration.py +0 -44
- tests/unit/cli/cloudbender/test_cli_reservation_unit.py +0 -38
- tests/unit/cli/test_cli_project_unit.py +0 -46
- tests/unit/cloudbender/test_reservations_unit.py +0 -173
- tests/unit/test_auth.py +0 -30
- tests/unit/test_projects_unit.py +0 -294
- tests/unit/test_proximl.py +0 -54
- {proximl-0.5.10.dist-info → proximl-0.5.11.dist-info}/LICENSE +0 -0
- {proximl-0.5.10.dist-info → proximl-0.5.11.dist-info}/WHEEL +0 -0
- {proximl-0.5.10.dist-info → proximl-0.5.11.dist-info}/entry_points.txt +0 -0
- {proximl-0.5.10.dist-info → proximl-0.5.11.dist-info}/top_level.txt +0 -0
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import re
|
|
2
|
-
import json
|
|
3
|
-
import click
|
|
4
|
-
from unittest.mock import AsyncMock, patch, create_autospec
|
|
5
|
-
from pytest import mark, fixture, raises
|
|
6
|
-
|
|
7
|
-
pytestmark = [mark.cli, mark.unit, mark.projects]
|
|
8
|
-
|
|
9
|
-
from proximl.cli import project as specimen
|
|
10
|
-
from proximl.projects import Project
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def test_list(runner, mock_projects):
|
|
14
|
-
with patch("proximl.cli.ProxiML", new=AsyncMock) as mock_proximl:
|
|
15
|
-
mock_proximl.projects = AsyncMock()
|
|
16
|
-
mock_proximl.projects.list = AsyncMock(return_value=mock_projects)
|
|
17
|
-
result = runner.invoke(specimen, ["list"])
|
|
18
|
-
print(result)
|
|
19
|
-
assert result.exit_code == 0
|
|
20
|
-
mock_proximl.projects.list.assert_called_once()
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def test_list_datastores(runner, mock_project_datastores):
|
|
24
|
-
with patch("proximl.cli.ProxiML", new=AsyncMock) as mock_proximl:
|
|
25
|
-
mock_project = create_autospec(Project)
|
|
26
|
-
mock_project.list_datastores = AsyncMock(
|
|
27
|
-
return_value=mock_project_datastores
|
|
28
|
-
)
|
|
29
|
-
mock_proximl.projects.get = AsyncMock(return_value=mock_project)
|
|
30
|
-
result = runner.invoke(specimen, ["list-datastores"])
|
|
31
|
-
print(result)
|
|
32
|
-
assert result.exit_code == 0
|
|
33
|
-
mock_project.list_datastores.assert_called_once()
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def test_list_reservations(runner, mock_project_reservations):
|
|
37
|
-
with patch("proximl.cli.ProxiML", new=AsyncMock) as mock_proximl:
|
|
38
|
-
mock_project = create_autospec(Project)
|
|
39
|
-
mock_project.list_reservations = AsyncMock(
|
|
40
|
-
return_value=mock_project_reservations
|
|
41
|
-
)
|
|
42
|
-
mock_proximl.projects.get = AsyncMock(return_value=mock_project)
|
|
43
|
-
result = runner.invoke(specimen, ["list-reservations"])
|
|
44
|
-
print(result)
|
|
45
|
-
assert result.exit_code == 0
|
|
46
|
-
mock_project.list_reservations.assert_called_once()
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import re
|
|
2
|
-
import json
|
|
3
|
-
import logging
|
|
4
|
-
from unittest.mock import AsyncMock, patch
|
|
5
|
-
from pytest import mark, fixture, raises
|
|
6
|
-
from aiohttp import WSMessage, WSMsgType
|
|
7
|
-
|
|
8
|
-
import proximl.cloudbender.reservations as specimen
|
|
9
|
-
from proximl.exceptions import (
|
|
10
|
-
ApiError,
|
|
11
|
-
SpecificationError,
|
|
12
|
-
ProxiMLException,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
pytestmark = [mark.sdk, mark.unit, mark.cloudbender, mark.reservations]
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@fixture
|
|
19
|
-
def reservations(mock_proximl):
|
|
20
|
-
yield specimen.Reservations(mock_proximl)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
@fixture
|
|
24
|
-
def reservation(mock_proximl):
|
|
25
|
-
yield specimen.Reservation(
|
|
26
|
-
mock_proximl,
|
|
27
|
-
provider_uuid="1",
|
|
28
|
-
region_uuid="a",
|
|
29
|
-
reservation_id="x",
|
|
30
|
-
name="On-Prem Reservation",
|
|
31
|
-
type="port",
|
|
32
|
-
resource="8001",
|
|
33
|
-
hostname="service.local",
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
class RegionsTests:
|
|
38
|
-
@mark.asyncio
|
|
39
|
-
async def test_get_reservation(
|
|
40
|
-
self,
|
|
41
|
-
reservations,
|
|
42
|
-
mock_proximl,
|
|
43
|
-
):
|
|
44
|
-
api_response = dict()
|
|
45
|
-
mock_proximl._query = AsyncMock(return_value=api_response)
|
|
46
|
-
await reservations.get("1234", "5687", "91011")
|
|
47
|
-
mock_proximl._query.assert_called_once_with(
|
|
48
|
-
"/provider/1234/region/5687/reservation/91011", "GET", {}
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
@mark.asyncio
|
|
52
|
-
async def test_list_reservations(
|
|
53
|
-
self,
|
|
54
|
-
reservations,
|
|
55
|
-
mock_proximl,
|
|
56
|
-
):
|
|
57
|
-
api_response = dict()
|
|
58
|
-
mock_proximl._query = AsyncMock(return_value=api_response)
|
|
59
|
-
await reservations.list("1234", "5687")
|
|
60
|
-
mock_proximl._query.assert_called_once_with(
|
|
61
|
-
"/provider/1234/region/5687/reservation", "GET", {}
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
@mark.asyncio
|
|
65
|
-
async def test_remove_reservation(
|
|
66
|
-
self,
|
|
67
|
-
reservations,
|
|
68
|
-
mock_proximl,
|
|
69
|
-
):
|
|
70
|
-
api_response = dict()
|
|
71
|
-
mock_proximl._query = AsyncMock(return_value=api_response)
|
|
72
|
-
await reservations.remove("1234", "4567", "8910")
|
|
73
|
-
mock_proximl._query.assert_called_once_with(
|
|
74
|
-
"/provider/1234/region/4567/reservation/8910", "DELETE", {}
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
@mark.asyncio
|
|
78
|
-
async def test_create_reservation(self, reservations, mock_proximl):
|
|
79
|
-
requested_config = dict(
|
|
80
|
-
provider_uuid="provider-id-1",
|
|
81
|
-
region_uuid="region-id-1",
|
|
82
|
-
name="On-Prem Reservation",
|
|
83
|
-
type="port",
|
|
84
|
-
resource="8001",
|
|
85
|
-
hostname="service.local",
|
|
86
|
-
)
|
|
87
|
-
expected_payload = dict(
|
|
88
|
-
name="On-Prem Reservation",
|
|
89
|
-
type="port",
|
|
90
|
-
resource="8001",
|
|
91
|
-
hostname="service.local",
|
|
92
|
-
)
|
|
93
|
-
api_response = {
|
|
94
|
-
"provider_uuid": "provider-id-1",
|
|
95
|
-
"region_uuid": "region-id-1",
|
|
96
|
-
"reservation_id": "reservation-id-1",
|
|
97
|
-
"name": "On-Prem Reservation",
|
|
98
|
-
"type": "port",
|
|
99
|
-
"resource": "8001",
|
|
100
|
-
"hostname": "service.local",
|
|
101
|
-
"createdAt": "2020-12-31T23:59:59.000Z",
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
mock_proximl._query = AsyncMock(return_value=api_response)
|
|
105
|
-
response = await reservations.create(**requested_config)
|
|
106
|
-
mock_proximl._query.assert_called_once_with(
|
|
107
|
-
"/provider/provider-id-1/region/region-id-1/reservation",
|
|
108
|
-
"POST",
|
|
109
|
-
None,
|
|
110
|
-
expected_payload,
|
|
111
|
-
)
|
|
112
|
-
assert response.id == "reservation-id-1"
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
class reservationTests:
|
|
116
|
-
def test_reservation_properties(self, reservation):
|
|
117
|
-
assert isinstance(reservation.id, str)
|
|
118
|
-
assert isinstance(reservation.provider_uuid, str)
|
|
119
|
-
assert isinstance(reservation.region_uuid, str)
|
|
120
|
-
assert isinstance(reservation.type, str)
|
|
121
|
-
assert isinstance(reservation.name, str)
|
|
122
|
-
assert isinstance(reservation.resource, str)
|
|
123
|
-
assert isinstance(reservation.hostname, str)
|
|
124
|
-
|
|
125
|
-
def test_reservation_str(self, reservation):
|
|
126
|
-
string = str(reservation)
|
|
127
|
-
regex = r"^{.*\"reservation_id\": \"" + reservation.id + r"\".*}$"
|
|
128
|
-
assert isinstance(string, str)
|
|
129
|
-
assert re.match(regex, string)
|
|
130
|
-
|
|
131
|
-
def test_reservation_repr(self, reservation):
|
|
132
|
-
string = repr(reservation)
|
|
133
|
-
regex = (
|
|
134
|
-
r"^Reservation\( proximl , \*\*{.*'reservation_id': '"
|
|
135
|
-
+ reservation.id
|
|
136
|
-
+ r"'.*}\)$"
|
|
137
|
-
)
|
|
138
|
-
assert isinstance(string, str)
|
|
139
|
-
assert re.match(regex, string)
|
|
140
|
-
|
|
141
|
-
def test_reservation_bool(self, reservation, mock_proximl):
|
|
142
|
-
empty_reservation = specimen.Reservation(mock_proximl)
|
|
143
|
-
assert bool(reservation)
|
|
144
|
-
assert not bool(empty_reservation)
|
|
145
|
-
|
|
146
|
-
@mark.asyncio
|
|
147
|
-
async def test_reservation_remove(self, reservation, mock_proximl):
|
|
148
|
-
api_response = dict()
|
|
149
|
-
mock_proximl._query = AsyncMock(return_value=api_response)
|
|
150
|
-
await reservation.remove()
|
|
151
|
-
mock_proximl._query.assert_called_once_with(
|
|
152
|
-
"/provider/1/region/a/reservation/x", "DELETE"
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
@mark.asyncio
|
|
156
|
-
async def test_reservation_refresh(self, reservation, mock_proximl):
|
|
157
|
-
api_response = {
|
|
158
|
-
"provider_uuid": "provider-id-1",
|
|
159
|
-
"region_uuid": "region-id-1",
|
|
160
|
-
"reservation_id": "reservation-id-1",
|
|
161
|
-
"name": "On-Prem Reservation",
|
|
162
|
-
"type": "port",
|
|
163
|
-
"resource": "8001",
|
|
164
|
-
"hostname": "service.local",
|
|
165
|
-
"createdAt": "2020-12-31T23:59:59.000Z",
|
|
166
|
-
}
|
|
167
|
-
mock_proximl._query = AsyncMock(return_value=api_response)
|
|
168
|
-
response = await reservation.refresh()
|
|
169
|
-
mock_proximl._query.assert_called_once_with(
|
|
170
|
-
f"/provider/1/region/a/reservation/x", "GET"
|
|
171
|
-
)
|
|
172
|
-
assert reservation.id == "reservation-id-1"
|
|
173
|
-
assert response.id == "reservation-id-1"
|
tests/unit/test_auth.py
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import re
|
|
2
|
-
import logging
|
|
3
|
-
import json
|
|
4
|
-
import os
|
|
5
|
-
from unittest.mock import AsyncMock, patch, mock_open, MagicMock
|
|
6
|
-
from pytest import mark, fixture, raises
|
|
7
|
-
from aiohttp import WSMessage, WSMsgType
|
|
8
|
-
|
|
9
|
-
import proximl.auth as specimen
|
|
10
|
-
|
|
11
|
-
pytestmark = [mark.sdk, mark.unit]
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@patch.dict(
|
|
15
|
-
os.environ,
|
|
16
|
-
{
|
|
17
|
-
"PROXIML_USER": "user-id",
|
|
18
|
-
"PROXIML_KEY": "key",
|
|
19
|
-
"PROXIML_REGION": "ap-east-1",
|
|
20
|
-
"PROXIML_CLIENT_ID": "client_id",
|
|
21
|
-
"PROXIML_POOL_ID": "pool_id",
|
|
22
|
-
},
|
|
23
|
-
)
|
|
24
|
-
def test_auth_from_envs():
|
|
25
|
-
auth = specimen.Auth(config_dir=os.path.expanduser("~/.proximl"))
|
|
26
|
-
assert auth.__dict__.get("username") == "user-id"
|
|
27
|
-
assert auth.__dict__.get("password") == "key"
|
|
28
|
-
assert auth.__dict__.get("region") == "ap-east-1"
|
|
29
|
-
assert auth.__dict__.get("client_id") == "client_id"
|
|
30
|
-
assert auth.__dict__.get("pool_id") == "pool_id"
|
tests/unit/test_projects_unit.py
DELETED
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
import re
|
|
2
|
-
import json
|
|
3
|
-
import logging
|
|
4
|
-
from unittest.mock import AsyncMock, patch
|
|
5
|
-
from pytest import mark, fixture, raises
|
|
6
|
-
from aiohttp import WSMessage, WSMsgType
|
|
7
|
-
|
|
8
|
-
import proximl.projects as specimen
|
|
9
|
-
from proximl.exceptions import (
|
|
10
|
-
ApiError,
|
|
11
|
-
SpecificationError,
|
|
12
|
-
ProxiMLException,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
pytestmark = [mark.sdk, mark.unit, mark.projects]
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@fixture
|
|
19
|
-
def projects(mock_proximl):
|
|
20
|
-
yield specimen.Projects(mock_proximl)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
@fixture
|
|
24
|
-
def project(mock_proximl):
|
|
25
|
-
yield specimen.Project(
|
|
26
|
-
mock_proximl,
|
|
27
|
-
id="1",
|
|
28
|
-
name="My Mock Project",
|
|
29
|
-
owner=True,
|
|
30
|
-
owner_name="Me",
|
|
31
|
-
created_name="Me",
|
|
32
|
-
job_all=True,
|
|
33
|
-
dataset_all=True,
|
|
34
|
-
model_all=True,
|
|
35
|
-
createdAt="2020-12-31T23:59:59.000Z",
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
@fixture
|
|
40
|
-
def project_datastore(mock_proximl):
|
|
41
|
-
yield specimen.ProjectDatastore(
|
|
42
|
-
mock_proximl,
|
|
43
|
-
id="ds-id-1",
|
|
44
|
-
name="datastore 1",
|
|
45
|
-
project_uuid="proj-id-1",
|
|
46
|
-
type="nfs",
|
|
47
|
-
region_uuid="reg-id-1",
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
@fixture
|
|
52
|
-
def project_reservation(mock_proximl):
|
|
53
|
-
yield specimen.ProjectReservation(
|
|
54
|
-
mock_proximl,
|
|
55
|
-
id="res-id-1",
|
|
56
|
-
name="reservation 1",
|
|
57
|
-
project_uuid="proj-id-1",
|
|
58
|
-
region_uuid="reg-id-1",
|
|
59
|
-
type="port",
|
|
60
|
-
resource="8001",
|
|
61
|
-
hostname="service.local",
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
class ProjectsTests:
|
|
66
|
-
@mark.asyncio
|
|
67
|
-
async def test_get_project(
|
|
68
|
-
self,
|
|
69
|
-
projects,
|
|
70
|
-
mock_proximl,
|
|
71
|
-
):
|
|
72
|
-
api_response = dict()
|
|
73
|
-
mock_proximl._query = AsyncMock(return_value=api_response)
|
|
74
|
-
await projects.get("1234")
|
|
75
|
-
mock_proximl._query.assert_called_once_with(
|
|
76
|
-
"/project/1234", "GET", dict()
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
@mark.asyncio
|
|
80
|
-
async def test_list_projects(
|
|
81
|
-
self,
|
|
82
|
-
projects,
|
|
83
|
-
mock_proximl,
|
|
84
|
-
):
|
|
85
|
-
api_response = dict()
|
|
86
|
-
mock_proximl._query = AsyncMock(return_value=api_response)
|
|
87
|
-
await projects.list()
|
|
88
|
-
mock_proximl._query.assert_called_once_with("/project", "GET", dict())
|
|
89
|
-
|
|
90
|
-
@mark.asyncio
|
|
91
|
-
async def test_remove_project(
|
|
92
|
-
self,
|
|
93
|
-
projects,
|
|
94
|
-
mock_proximl,
|
|
95
|
-
):
|
|
96
|
-
api_response = dict()
|
|
97
|
-
mock_proximl._query = AsyncMock(return_value=api_response)
|
|
98
|
-
await projects.remove("4567")
|
|
99
|
-
mock_proximl._query.assert_called_once_with(
|
|
100
|
-
"/project/4567", "DELETE", dict()
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
@mark.asyncio
|
|
104
|
-
async def test_create_project_simple(self, projects, mock_proximl):
|
|
105
|
-
requested_config = dict(
|
|
106
|
-
name="new project",
|
|
107
|
-
)
|
|
108
|
-
expected_payload = dict(name="new project", copy_keys=False)
|
|
109
|
-
api_response = {
|
|
110
|
-
"id": "project-id-1",
|
|
111
|
-
"name": "new project",
|
|
112
|
-
"owner": True,
|
|
113
|
-
"owner_name": "Me",
|
|
114
|
-
"created_name": "Me",
|
|
115
|
-
"job_all": True,
|
|
116
|
-
"dataset_all": True,
|
|
117
|
-
"model_all": True,
|
|
118
|
-
"createdAt": "2020-12-31T23:59:59.000Z",
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
mock_proximl._query = AsyncMock(return_value=api_response)
|
|
122
|
-
response = await projects.create(**requested_config)
|
|
123
|
-
mock_proximl._query.assert_called_once_with(
|
|
124
|
-
"/project", "POST", None, expected_payload
|
|
125
|
-
)
|
|
126
|
-
assert response.id == "project-id-1"
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
class ProjectDatastoreTests:
|
|
130
|
-
def test_project_datastore_properties(self, project_datastore):
|
|
131
|
-
assert isinstance(project_datastore.id, str)
|
|
132
|
-
assert isinstance(project_datastore.name, str)
|
|
133
|
-
assert isinstance(project_datastore.project_uuid, str)
|
|
134
|
-
assert isinstance(project_datastore.type, str)
|
|
135
|
-
assert isinstance(project_datastore.region_uuid, str)
|
|
136
|
-
|
|
137
|
-
def test_project_datastore_str(self, project_datastore):
|
|
138
|
-
string = str(project_datastore)
|
|
139
|
-
regex = r"^{.*\"id\": \"" + project_datastore.id + r"\".*}$"
|
|
140
|
-
assert isinstance(string, str)
|
|
141
|
-
assert re.match(regex, string)
|
|
142
|
-
|
|
143
|
-
def test_project_datastore_repr(self, project_datastore):
|
|
144
|
-
string = repr(project_datastore)
|
|
145
|
-
regex = (
|
|
146
|
-
r"^ProjectDatastore\( proximl , \*\*{.*'id': '"
|
|
147
|
-
+ project_datastore.id
|
|
148
|
-
+ r"'.*}\)$"
|
|
149
|
-
)
|
|
150
|
-
assert isinstance(string, str)
|
|
151
|
-
assert re.match(regex, string)
|
|
152
|
-
|
|
153
|
-
def test_project_datastore_bool(self, project_datastore, mock_proximl):
|
|
154
|
-
empty_project_datastore = specimen.ProjectDatastore(mock_proximl)
|
|
155
|
-
assert bool(project_datastore)
|
|
156
|
-
assert not bool(empty_project_datastore)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
class ProjectReservationTests:
|
|
160
|
-
def test_project_reservation_properties(self, project_reservation):
|
|
161
|
-
assert isinstance(project_reservation.id, str)
|
|
162
|
-
assert isinstance(project_reservation.name, str)
|
|
163
|
-
assert isinstance(project_reservation.project_uuid, str)
|
|
164
|
-
assert isinstance(project_reservation.type, str)
|
|
165
|
-
assert isinstance(project_reservation.hostname, str)
|
|
166
|
-
assert isinstance(project_reservation.resource, str)
|
|
167
|
-
assert isinstance(project_reservation.region_uuid, str)
|
|
168
|
-
|
|
169
|
-
def test_project_reservation_str(self, project_reservation):
|
|
170
|
-
string = str(project_reservation)
|
|
171
|
-
regex = r"^{.*\"id\": \"" + project_reservation.id + r"\".*}$"
|
|
172
|
-
assert isinstance(string, str)
|
|
173
|
-
assert re.match(regex, string)
|
|
174
|
-
|
|
175
|
-
def test_project_reservation_repr(self, project_reservation):
|
|
176
|
-
string = repr(project_reservation)
|
|
177
|
-
regex = (
|
|
178
|
-
r"^ProjectReservation\( proximl , \*\*{.*'id': '"
|
|
179
|
-
+ project_reservation.id
|
|
180
|
-
+ r"'.*}\)$"
|
|
181
|
-
)
|
|
182
|
-
assert isinstance(string, str)
|
|
183
|
-
assert re.match(regex, string)
|
|
184
|
-
|
|
185
|
-
def test_project_reservation_bool(self, project_reservation, mock_proximl):
|
|
186
|
-
empty_project_reservation = specimen.ProjectReservation(mock_proximl)
|
|
187
|
-
assert bool(project_reservation)
|
|
188
|
-
assert not bool(empty_project_reservation)
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
class ProjectTests:
|
|
192
|
-
def test_project_properties(self, project):
|
|
193
|
-
assert isinstance(project.id, str)
|
|
194
|
-
assert isinstance(project.name, str)
|
|
195
|
-
assert isinstance(project.owner_name, str)
|
|
196
|
-
assert isinstance(project.is_owner, bool)
|
|
197
|
-
|
|
198
|
-
def test_project_str(self, project):
|
|
199
|
-
string = str(project)
|
|
200
|
-
regex = r"^{.*\"id\": \"" + project.id + r"\".*}$"
|
|
201
|
-
assert isinstance(string, str)
|
|
202
|
-
assert re.match(regex, string)
|
|
203
|
-
|
|
204
|
-
def test_project_repr(self, project):
|
|
205
|
-
string = repr(project)
|
|
206
|
-
regex = (
|
|
207
|
-
r"^Project\( proximl , \*\*{.*'id': '" + project.id + r"'.*}\)$"
|
|
208
|
-
)
|
|
209
|
-
assert isinstance(string, str)
|
|
210
|
-
assert re.match(regex, string)
|
|
211
|
-
|
|
212
|
-
def test_project_bool(self, project, mock_proximl):
|
|
213
|
-
empty_project = specimen.Project(mock_proximl)
|
|
214
|
-
assert bool(project)
|
|
215
|
-
assert not bool(empty_project)
|
|
216
|
-
|
|
217
|
-
@mark.asyncio
|
|
218
|
-
async def test_project_remove(self, project, mock_proximl):
|
|
219
|
-
api_response = dict()
|
|
220
|
-
mock_proximl._query = AsyncMock(return_value=api_response)
|
|
221
|
-
await project.remove()
|
|
222
|
-
mock_proximl._query.assert_called_once_with("/project/1", "DELETE")
|
|
223
|
-
|
|
224
|
-
@mark.asyncio
|
|
225
|
-
async def test_project_refresh_datastores(self, project, mock_proximl):
|
|
226
|
-
api_response = dict()
|
|
227
|
-
mock_proximl._query = AsyncMock(return_value=api_response)
|
|
228
|
-
await project.refresh_datastores()
|
|
229
|
-
mock_proximl._query.assert_called_once_with(
|
|
230
|
-
"/project/1/datastores", "PATCH"
|
|
231
|
-
)
|
|
232
|
-
|
|
233
|
-
@mark.asyncio
|
|
234
|
-
async def test_project_refresh_reservations(self, project, mock_proximl):
|
|
235
|
-
api_response = dict()
|
|
236
|
-
mock_proximl._query = AsyncMock(return_value=api_response)
|
|
237
|
-
await project.refresh_reservations()
|
|
238
|
-
mock_proximl._query.assert_called_once_with(
|
|
239
|
-
"/project/1/reservations", "PATCH"
|
|
240
|
-
)
|
|
241
|
-
|
|
242
|
-
@mark.asyncio
|
|
243
|
-
async def test_project_list_datastores(self, project, mock_proximl):
|
|
244
|
-
api_response = [
|
|
245
|
-
{
|
|
246
|
-
"project_uuid": "proj-id-1",
|
|
247
|
-
"region_uuid": "reg-id-1",
|
|
248
|
-
"id": "store-id-1",
|
|
249
|
-
"type": "nfs",
|
|
250
|
-
"name": "On-prem NFS",
|
|
251
|
-
},
|
|
252
|
-
{
|
|
253
|
-
"project_uuid": "proj-id-1",
|
|
254
|
-
"region_uuid": "reg-id-2",
|
|
255
|
-
"id": "store-id-2",
|
|
256
|
-
"type": "smb",
|
|
257
|
-
"name": "GCP Samba",
|
|
258
|
-
},
|
|
259
|
-
]
|
|
260
|
-
mock_proximl._query = AsyncMock(return_value=api_response)
|
|
261
|
-
resp = await project.list_datastores()
|
|
262
|
-
mock_proximl._query.assert_called_once_with(
|
|
263
|
-
"/project/1/datastores", "GET"
|
|
264
|
-
)
|
|
265
|
-
assert len(resp) == 2
|
|
266
|
-
|
|
267
|
-
@mark.asyncio
|
|
268
|
-
async def test_project_list_reservations(self, project, mock_proximl):
|
|
269
|
-
api_response = [
|
|
270
|
-
{
|
|
271
|
-
"project_uuid": "proj-id-1",
|
|
272
|
-
"region_uuid": "reg-id-1",
|
|
273
|
-
"id": "res-id-1",
|
|
274
|
-
"type": "port",
|
|
275
|
-
"name": "On-Prem Service A",
|
|
276
|
-
"resource": "8001",
|
|
277
|
-
"hostname": "service-a.local",
|
|
278
|
-
},
|
|
279
|
-
{
|
|
280
|
-
"project_uuid": "proj-id-1",
|
|
281
|
-
"region_uuid": "reg-id-2",
|
|
282
|
-
"id": "res-id-2",
|
|
283
|
-
"type": "port",
|
|
284
|
-
"name": "Cloud Service B",
|
|
285
|
-
"resource": "8001",
|
|
286
|
-
"hostname": "service-b.local",
|
|
287
|
-
},
|
|
288
|
-
]
|
|
289
|
-
mock_proximl._query = AsyncMock(return_value=api_response)
|
|
290
|
-
resp = await project.list_reservations()
|
|
291
|
-
mock_proximl._query.assert_called_once_with(
|
|
292
|
-
"/project/1/reservations", "GET"
|
|
293
|
-
)
|
|
294
|
-
assert len(resp) == 2
|
tests/unit/test_proximl.py
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import re
|
|
2
|
-
import logging
|
|
3
|
-
import json
|
|
4
|
-
import os
|
|
5
|
-
from unittest.mock import AsyncMock, patch, mock_open
|
|
6
|
-
from pytest import mark, fixture, raises
|
|
7
|
-
from aiohttp import WSMessage, WSMsgType
|
|
8
|
-
|
|
9
|
-
import proximl.proximl as specimen
|
|
10
|
-
|
|
11
|
-
pytestmark = [mark.sdk, mark.unit]
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@patch.dict(
|
|
15
|
-
os.environ,
|
|
16
|
-
{
|
|
17
|
-
"PROXIML_USER": "user-id",
|
|
18
|
-
"PROXIML_KEY": "key",
|
|
19
|
-
"PROXIML_REGION": "region",
|
|
20
|
-
"PROXIML_CLIENT_ID": "client_id",
|
|
21
|
-
"PROXIML_POOL_ID": "pool_id",
|
|
22
|
-
"PROXIML_API_URL": "api.example.com",
|
|
23
|
-
"PROXIML_WS_URL": "api-ws.example.com",
|
|
24
|
-
},
|
|
25
|
-
)
|
|
26
|
-
def test_proximl_from_envs():
|
|
27
|
-
proximl = specimen.ProxiML()
|
|
28
|
-
assert proximl.__dict__.get("api_url") == "api.example.com"
|
|
29
|
-
assert proximl.__dict__.get("ws_url") == "api-ws.example.com"
|
|
30
|
-
assert proximl.auth.__dict__.get("username") == "user-id"
|
|
31
|
-
assert proximl.auth.__dict__.get("password") == "key"
|
|
32
|
-
assert proximl.auth.__dict__.get("region") == "region"
|
|
33
|
-
assert proximl.auth.__dict__.get("client_id") == "client_id"
|
|
34
|
-
assert proximl.auth.__dict__.get("pool_id") == "pool_id"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def test_proximl_env_from_files():
|
|
38
|
-
with patch(
|
|
39
|
-
"proximl.proximl.open",
|
|
40
|
-
mock_open(
|
|
41
|
-
read_data=json.dumps(
|
|
42
|
-
dict(
|
|
43
|
-
region="region_file",
|
|
44
|
-
client_id="client_id_file",
|
|
45
|
-
pool_id="pool_id_file",
|
|
46
|
-
api_url="api.example.com_file",
|
|
47
|
-
ws_url="api-ws.example.com_file",
|
|
48
|
-
)
|
|
49
|
-
)
|
|
50
|
-
),
|
|
51
|
-
):
|
|
52
|
-
proximl = specimen.ProxiML()
|
|
53
|
-
assert proximl.__dict__.get("api_url") == "api.example.com_file"
|
|
54
|
-
assert proximl.__dict__.get("ws_url") == "api-ws.example.com_file"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|