proximl 0.5.7__py3-none-any.whl → 0.5.9__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.
Files changed (30) hide show
  1. proximl/cli/project/__init__.py +153 -0
  2. proximl/cli/project/key.py +124 -0
  3. proximl/cli/project/secret.py +71 -0
  4. proximl/projects/__init__.py +3 -0
  5. proximl/projects/data_connectors.py +63 -0
  6. proximl/projects/datastores.py +58 -0
  7. proximl/projects/keys.py +71 -0
  8. proximl/projects/projects.py +83 -0
  9. proximl/projects/secrets.py +70 -0
  10. proximl/projects/services.py +63 -0
  11. {proximl-0.5.7.dist-info → proximl-0.5.9.dist-info}/METADATA +1 -1
  12. {proximl-0.5.7.dist-info → proximl-0.5.9.dist-info}/RECORD +30 -6
  13. tests/integration/projects/__init__.py +0 -0
  14. tests/integration/projects/conftest.py +8 -0
  15. tests/integration/projects/test_projects_integration.py +38 -0
  16. tests/integration/projects/test_projects_keys_integration.py +43 -0
  17. tests/integration/projects/test_projects_secrets_integration.py +44 -0
  18. tests/unit/projects/__init__.py +0 -0
  19. tests/unit/projects/test_project_data_connectors_unit.py +102 -0
  20. tests/unit/projects/test_project_datastores_unit.py +96 -0
  21. tests/unit/projects/test_project_keys_unit.py +96 -0
  22. tests/unit/projects/test_project_secrets_unit.py +101 -0
  23. tests/unit/projects/test_project_services_unit.py +102 -0
  24. tests/unit/projects/test_projects_unit.py +128 -0
  25. tests/unit/test_auth_unit.py +30 -0
  26. tests/unit/test_proximl_unit.py +54 -0
  27. {proximl-0.5.7.dist-info → proximl-0.5.9.dist-info}/LICENSE +0 -0
  28. {proximl-0.5.7.dist-info → proximl-0.5.9.dist-info}/WHEEL +0 -0
  29. {proximl-0.5.7.dist-info → proximl-0.5.9.dist-info}/entry_points.txt +0 -0
  30. {proximl-0.5.7.dist-info → proximl-0.5.9.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,101 @@
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.secrets 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 project_secrets(mock_proximl):
20
+ yield specimen.ProjectSecrets(mock_proximl, project_id="1")
21
+
22
+
23
+ @fixture
24
+ def project_service(mock_proximl):
25
+ yield specimen.ProjectSecret(
26
+ mock_proximl,
27
+ project_uuid="proj-id-1",
28
+ name="secret_value",
29
+ )
30
+
31
+
32
+ class ProjectSecretsTests:
33
+ @mark.asyncio
34
+ async def test_project_secrets_list(self, project_secrets, mock_proximl):
35
+ api_response = [
36
+ {
37
+ "project_uuid": "proj-id-1",
38
+ "name": "secret_value",
39
+ },
40
+ {
41
+ "project_uuid": "proj-id-1",
42
+ "name": "secret_value_2",
43
+ },
44
+ ]
45
+ mock_proximl._query = AsyncMock(return_value=api_response)
46
+ resp = await project_secrets.list()
47
+ mock_proximl._query.assert_called_once_with("/project/1/secrets", "GET", dict())
48
+ assert len(resp) == 2
49
+
50
+ @mark.asyncio
51
+ async def test_remove_project_secret(
52
+ self,
53
+ project_secrets,
54
+ mock_proximl,
55
+ ):
56
+ api_response = dict()
57
+ mock_proximl._query = AsyncMock(return_value=api_response)
58
+ await project_secrets.remove("secret_value")
59
+ mock_proximl._query.assert_called_once_with(
60
+ "/project/1/secret/secret_value", "DELETE", dict()
61
+ )
62
+
63
+ @mark.asyncio
64
+ async def test_put_project_secret(self, project_secrets, mock_proximl):
65
+ requested_config = dict(name="secret_value", value="ASKHJSLKF")
66
+ expected_payload = dict(value="ASKHJSLKF")
67
+ api_response = {"project_uuid": "project-id-1", "name": "secret_value"}
68
+
69
+ mock_proximl._query = AsyncMock(return_value=api_response)
70
+ response = await project_secrets.put(**requested_config)
71
+ mock_proximl._query.assert_called_once_with(
72
+ "/project/1/secret/secret_value", "PUT", None, expected_payload
73
+ )
74
+ assert response.name == "secret_value"
75
+
76
+
77
+ class ProjectSecretTests:
78
+ def test_project_service_properties(self, project_service):
79
+ assert isinstance(project_service.name, str)
80
+ assert isinstance(project_service.project_uuid, str)
81
+
82
+ def test_project_service_str(self, project_service):
83
+ string = str(project_service)
84
+ regex = r"^{.*\"name\": \"" + project_service.name + r"\".*}$"
85
+ assert isinstance(string, str)
86
+ assert re.match(regex, string)
87
+
88
+ def test_project_service_repr(self, project_service):
89
+ string = repr(project_service)
90
+ regex = (
91
+ r"^ProjectSecret\( proximl , \*\*{.*'name': '"
92
+ + project_service.name
93
+ + r"'.*}\)$"
94
+ )
95
+ assert isinstance(string, str)
96
+ assert re.match(regex, string)
97
+
98
+ def test_project_service_bool(self, project_service, mock_proximl):
99
+ empty_project_service = specimen.ProjectSecret(mock_proximl)
100
+ assert bool(project_service)
101
+ assert not bool(empty_project_service)
@@ -0,0 +1,102 @@
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.services 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 project_services(mock_proximl):
20
+ yield specimen.ProjectServices(mock_proximl, project_id="1")
21
+
22
+
23
+ @fixture
24
+ def project_service(mock_proximl):
25
+ yield specimen.ProjectService(
26
+ mock_proximl,
27
+ id="res-id-1",
28
+ name="service 1",
29
+ project_uuid="proj-id-1",
30
+ region_uuid="reg-id-1",
31
+ public=False,
32
+ hostname="asdf.proximl.cloud",
33
+ )
34
+
35
+
36
+ class ProjectServicesTests:
37
+ @mark.asyncio
38
+ async def test_project_services_refresh(self, project_services, mock_proximl):
39
+ api_response = dict()
40
+ mock_proximl._query = AsyncMock(return_value=api_response)
41
+ await project_services.refresh()
42
+ mock_proximl._query.assert_called_once_with("/project/1/services", "PATCH")
43
+
44
+ @mark.asyncio
45
+ async def test_project_services_list(self, project_services, mock_proximl):
46
+ api_response = [
47
+ {
48
+ "project_uuid": "proj-id-1",
49
+ "region_uuid": "reg-id-1",
50
+ "id": "res-id-1",
51
+ "type": "port",
52
+ "name": "On-Prem Service A",
53
+ "resource": "8001",
54
+ "hostname": "service-a.local",
55
+ },
56
+ {
57
+ "project_uuid": "proj-id-1",
58
+ "region_uuid": "reg-id-2",
59
+ "id": "res-id-2",
60
+ "type": "port",
61
+ "name": "Cloud Service B",
62
+ "resource": "8001",
63
+ "hostname": "service-b.local",
64
+ },
65
+ ]
66
+ mock_proximl._query = AsyncMock(return_value=api_response)
67
+ resp = await project_services.list()
68
+ mock_proximl._query.assert_called_once_with(
69
+ "/project/1/services", "GET", dict()
70
+ )
71
+ assert len(resp) == 2
72
+
73
+
74
+ class ProjectServiceTests:
75
+ def test_project_service_properties(self, project_service):
76
+ assert isinstance(project_service.id, str)
77
+ assert isinstance(project_service.name, str)
78
+ assert isinstance(project_service.project_uuid, str)
79
+ assert isinstance(project_service.hostname, str)
80
+ assert isinstance(project_service.public, bool)
81
+ assert isinstance(project_service.region_uuid, str)
82
+
83
+ def test_project_service_str(self, project_service):
84
+ string = str(project_service)
85
+ regex = r"^{.*\"id\": \"" + project_service.id + r"\".*}$"
86
+ assert isinstance(string, str)
87
+ assert re.match(regex, string)
88
+
89
+ def test_project_service_repr(self, project_service):
90
+ string = repr(project_service)
91
+ regex = (
92
+ r"^ProjectService\( proximl , \*\*{.*'id': '"
93
+ + project_service.id
94
+ + r"'.*}\)$"
95
+ )
96
+ assert isinstance(string, str)
97
+ assert re.match(regex, string)
98
+
99
+ def test_project_service_bool(self, project_service, mock_proximl):
100
+ empty_project_service = specimen.ProjectService(mock_proximl)
101
+ assert bool(project_service)
102
+ assert not bool(empty_project_service)
@@ -0,0 +1,128 @@
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
+ class ProjectsTests:
40
+ @mark.asyncio
41
+ async def test_get_project(
42
+ self,
43
+ projects,
44
+ mock_proximl,
45
+ ):
46
+ api_response = dict()
47
+ mock_proximl._query = AsyncMock(return_value=api_response)
48
+ await projects.get("1234")
49
+ mock_proximl._query.assert_called_once_with("/project/1234", "GET", dict())
50
+
51
+ @mark.asyncio
52
+ async def test_list_projects(
53
+ self,
54
+ projects,
55
+ mock_proximl,
56
+ ):
57
+ api_response = dict()
58
+ mock_proximl._query = AsyncMock(return_value=api_response)
59
+ await projects.list()
60
+ mock_proximl._query.assert_called_once_with("/project", "GET", dict())
61
+
62
+ @mark.asyncio
63
+ async def test_remove_project(
64
+ self,
65
+ projects,
66
+ mock_proximl,
67
+ ):
68
+ api_response = dict()
69
+ mock_proximl._query = AsyncMock(return_value=api_response)
70
+ await projects.remove("4567")
71
+ mock_proximl._query.assert_called_once_with("/project/4567", "DELETE", dict())
72
+
73
+ @mark.asyncio
74
+ async def test_create_project_simple(self, projects, mock_proximl):
75
+ requested_config = dict(
76
+ name="new project",
77
+ )
78
+ expected_payload = dict(name="new project", copy_keys=False, copy_secrets=False)
79
+ api_response = {
80
+ "id": "project-id-1",
81
+ "name": "new project",
82
+ "owner": True,
83
+ "owner_name": "Me",
84
+ "created_name": "Me",
85
+ "job_all": True,
86
+ "dataset_all": True,
87
+ "model_all": True,
88
+ "createdAt": "2020-12-31T23:59:59.000Z",
89
+ }
90
+
91
+ mock_proximl._query = AsyncMock(return_value=api_response)
92
+ response = await projects.create(**requested_config)
93
+ mock_proximl._query.assert_called_once_with(
94
+ "/project", "POST", None, expected_payload
95
+ )
96
+ assert response.id == "project-id-1"
97
+
98
+
99
+ class ProjectTests:
100
+ def test_project_properties(self, project):
101
+ assert isinstance(project.id, str)
102
+ assert isinstance(project.name, str)
103
+ assert isinstance(project.owner_name, str)
104
+ assert isinstance(project.is_owner, bool)
105
+
106
+ def test_project_str(self, project):
107
+ string = str(project)
108
+ regex = r"^{.*\"id\": \"" + project.id + r"\".*}$"
109
+ assert isinstance(string, str)
110
+ assert re.match(regex, string)
111
+
112
+ def test_project_repr(self, project):
113
+ string = repr(project)
114
+ regex = r"^Project\( proximl , \*\*{.*'id': '" + project.id + r"'.*}\)$"
115
+ assert isinstance(string, str)
116
+ assert re.match(regex, string)
117
+
118
+ def test_project_bool(self, project, mock_proximl):
119
+ empty_project = specimen.Project(mock_proximl)
120
+ assert bool(project)
121
+ assert not bool(empty_project)
122
+
123
+ @mark.asyncio
124
+ async def test_project_remove(self, project, mock_proximl):
125
+ api_response = dict()
126
+ mock_proximl._query = AsyncMock(return_value=api_response)
127
+ await project.remove()
128
+ mock_proximl._query.assert_called_once_with("/project/1", "DELETE")
@@ -0,0 +1,30 @@
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"
@@ -0,0 +1,54 @@
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"