Skip to content

Commit a4b7542

Browse files
committed
version 3.11 added get definition and updated to toml
1 parent a798de6 commit a4b7542

File tree

9 files changed

+151
-168
lines changed

9 files changed

+151
-168
lines changed

CHANGES.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@
3131
- Fixed `to_dict()` method for Segments, Segment Definitions and Split Definitions
3232
3.1.10 (Oct 30, 2023)
3333
- Added scope options for admin api
34-
34+
3.1.11 (Dec 13, 2023)
35+
- Added ability to get individual flag definitions with the `get_definition` method of splitDefinition

pyproject.toml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[build-system]
2+
requires = ["setuptools>=61.2", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "splitapiclient"
7+
version = "3.1.11"
8+
description = "This Python Library provide full support for Split REST Admin API, allow creating, deleting and editing Environments, Splits, Split Definitions, Segments, Segment Keys, Users, Groups, API Keys, Change Requests, Attributes and Identities"
9+
classifiers = [
10+
"Programming Language :: Python :: 3",
11+
"Operating System :: OS Independent",
12+
"Development Status :: 3 - Alpha",
13+
"Environment :: Console",
14+
"Intended Audience :: Developers",
15+
"Programming Language :: Python :: 3",
16+
"Topic :: Software Development :: Libraries",
17+
]
18+
authors = [
19+
{name = "Patricio Echague", email = "[email protected]"},
20+
{name = "Sebastian Arrubia", email = "[email protected]"},
21+
{name = "Martin Redolatti", email = "[email protected]"},
22+
{name = "Bilal Al-Shawany", email = "[email protected]"},
23+
]
24+
maintainers = [
25+
{name = "Josh Klein", email = "[email protected]"}
26+
]
27+
28+
29+
[project.license]
30+
text = "Apache License 2.0"
31+
32+
[project.readme]
33+
file = "README.md"
34+
content-type = "text/markdown"
35+
36+
[project.urls]
37+
Homepage = "https://github.com/splitio/python-api"
38+
"Bug Tracker" = "https://github.com/splitio/python-api/issues"
39+
Documentation = "https://help.split.io/hc/en-us/articles/4412331052685-Python-PyPi-library-for-Split-REST-Admin-API"
40+
41+
[tool.aliases]
42+
test = "pytest"
43+
44+
[tool.pytest.ini_options]
45+
addopts = "--verbose"
46+
47+
[tool.setuptools]
48+
include-package-data = false
49+
50+
[aliases]
51+
test = "pytest"
52+
53+
[tool.pytest]
54+
addopts = "--verbose"
55+
56+
[options]
57+
packages = "find:"
58+
setup_requires = "pytest-runner"
59+
60+
[options.install_requires]
61+
"argparse>" = "1.1"
62+
"requests>" = "2.14.2"
63+
"six>" = "1.10.0"
64+
65+
[options.tests_require]
66+
mock = "=2.0.0"
67+
pytest-mock = "=1.6.0"
68+
pytest = "=6.2.4"

pyvenv.cfg

Lines changed: 0 additions & 7 deletions
This file was deleted.

setup.cfg

Lines changed: 0 additions & 18 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 138 deletions
This file was deleted.

splitapiclient/microclients/split_definition_microclient.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from splitapiclient.resources import SplitDefinition
2-
from splitapiclient.util.exceptions import HTTPResponseError, \
2+
from splitapiclient.util.exceptions import HTTPNotFoundError, HTTPResponseError, \
33
UnknownApiClientError
44
from splitapiclient.util.logger import LOGGER
55
from splitapiclient.util.helpers import as_dict
@@ -19,6 +19,17 @@ class SplitDefinitionMicroClient:
1919
'query_string': [],
2020
'response': True,
2121
},
22+
'get_definition': {
23+
'method': 'GET',
24+
'url_template': ('splits/ws/{workspaceId}/{splitName}/environments/{environmentId}'),
25+
'headers': [{
26+
'name': 'Authorization',
27+
'template': 'Bearer {value}',
28+
'required': True,
29+
}],
30+
'query_string': [],
31+
'response': True,
32+
},
2233
'update_definition': {
2334
'method': 'PUT',
2435
'url_template': ('splits/ws/{workspaceId}/{splitName}/environments/{environmentId}'),
@@ -101,6 +112,26 @@ def find(self, split_name, environment_id, workspace_id):
101112
LOGGER.error("Split Name does not exist")
102113
return None
103114

115+
def get_definition(self, split_name, environment_id, workspace_id):
116+
'''
117+
Get a Split definition in a single API request.
118+
119+
:returns: SplitDefinition object
120+
:rtype: SplitDefinition
121+
'''
122+
try:
123+
response = self._http_client.make_request(
124+
self._endpoint['get_definition'],
125+
workspaceId = workspace_id,
126+
environmentId = environment_id,
127+
splitName = split_name
128+
)
129+
item = as_dict(response)
130+
return SplitDefinition(item, environment_id, workspace_id, self._http_client)
131+
except HTTPNotFoundError as e:
132+
LOGGER.error("Split Name '%s' does not exist", split_name)
133+
return None
134+
104135
def update_definition(self, split_name, environment_id, workspace_id, new_definition):
105136
'''
106137
update a split definition
@@ -155,4 +186,3 @@ def restore(self, split_name, environment_id, workspace_id):
155186
splitName = split_name
156187
)
157188
return response
158-

splitapiclient/tests/main/test_splitapiclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class TestSyncApiClient:
99
'''
1010
'''
1111

12-
def test_constructor(self, mock):
12+
def test_constructor(self):
1313
'''
1414
'''
1515
# Should have PROD url by default

splitapiclient/tests/microclients/split_definition_microclient_test.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,50 @@ def test_list(self, mocker):
105105
}]
106106
assert object_to_stringified_dict(result[0]) == data[0]
107107
assert object_to_stringified_dict(result[1]) == data[1]
108+
109+
def test_get_definition(self, mocker):
110+
'''
111+
'''
112+
mocker.patch('splitapiclient.http_clients.sync_client.SyncHttpClient.make_request')
113+
sc = SyncHttpClient('abc', 'abc')
114+
emc = SplitDefinitionMicroClient(sc)
115+
data = {
116+
'name': 'split1',
117+
'environment': Environment(data={'changePermissions': None, 'creationTime': None, 'dataExportPermissions': None, 'environmentType': None, 'workspaceIds': ['ws_id'], 'name':None, 'type': None, 'orgId': None, 'id':None, 'status':None}).to_dict(),
118+
'trafficType': {'displayAttributeId': None, 'id': None, 'name': None},
119+
'killed': False,
120+
'treatments': [],
121+
'defaultTreatment': 'off',
122+
'baselineTreatment': 'off',
123+
'trafficAllocation': 100,
124+
'rules': [],
125+
'defaultRule': [],
126+
'creationTime': None,
127+
'lastUpdateTime': None,
128+
'lastTrafficReceivedAt': None
129+
}
130+
131+
SyncHttpClient.make_request.return_value = data
132+
result = emc.get_definition('split1', 'env_id', 'ws_id')
133+
SyncHttpClient.make_request.assert_called_once_with(
134+
SplitDefinitionMicroClient._endpoint['get_definition'],
135+
workspaceId = 'ws_id',
136+
environmentId = 'env_id',
137+
splitName = 'split1'
138+
)
139+
data = {
140+
'name': 'split1',
141+
'environment': Environment(data={'changePermissions': None, 'creationTime': None, 'dataExportPermissions': None, 'environmentType': None, 'workspaceIds': ['ws_id'], 'name':None, 'type': None, 'orgId': None, 'id':None, 'status':None}).to_dict(),
142+
'trafficType': {'displayAttributeId': None, 'id': None, 'name': None},
143+
'killed': False,
144+
'treatments': None,
145+
'defaultTreatment': 'off',
146+
'baselineTreatment': 'off',
147+
'trafficAllocation': 100,
148+
'rules': None,
149+
'defaultRule': None,
150+
'creationTime': None,
151+
'lastUpdateTime': None,
152+
'lastTrafficReceivedAt': None
153+
}
154+
assert object_to_stringified_dict(result) == data

splitapiclient/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '3.1.10'
1+
__version__ = '3.1.11'

0 commit comments

Comments
 (0)