Skip to content

Commit c31aefe

Browse files
committed
Add status and product info support and Issue #4
1 parent 9824f86 commit c31aefe

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

kepconfig/connection.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,37 @@ def SSL_trust_all_certs(self, val):
152152
self.__ssl_context.verify_mode = ssl.CERT_REQUIRED
153153

154154

155+
def get_status(self) -> dict:
156+
'''Executes a health status request to the Kepware instance to report service statuses.
155157
158+
RETURNS:
159+
160+
list - list of data for the health status request
161+
162+
EXCEPTIONS:
163+
164+
KepHTTPError - If urllib provides an HTTPError
165+
KepURLError - If urllib provides an URLError
166+
'''
167+
168+
r = self._config_get(f'{self.url}/status')
169+
return r.payload
170+
def get_info(self) -> dict:
171+
'''Requests product information from the Kepware instance. Provides various information including
172+
product name and version information.
173+
174+
RETURNS:
175+
176+
dict - data for the product information request
177+
178+
EXCEPTIONS:
179+
180+
KepHTTPError - If urllib provides an HTTPError
181+
KepURLError - If urllib provides an URLError
182+
'''
183+
184+
r = self._config_get(f'{self.url}/about')
185+
return r.payload
156186

157187
def reinitialize(self, job_ttl = None) -> KepServiceResponse:
158188
'''Executes a Reinitialize call to the Kepware instance.
@@ -337,6 +367,9 @@ def _config_add(self, url, DATA):
337367
'''Conducts an POST method at *url* to add an object in the Kepware Configuration
338368
*DATA* is required to be a properly JSON object (dict) of the item to be posted to *url*
339369
'''
370+
if len(DATA) == 0:
371+
err_msg = f'Error: Empty List or Dict in DATA | DATA type: {type(DATA)}'
372+
raise KepError(err_msg)
340373
data = json.dumps(DATA).encode('utf-8')
341374
url_obj = self.__url_validate(url)
342375
q = request.Request(url_obj, data, method='POST')

tests/connectivity_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ def test_channel_add(server):
7777
channel_data = {"common.ALLTYPES_NAME": ch_name,"servermain.MULTIPLE_TYPES_DEVICE_DRIVER": "Simulator"}
7878
assert kepconfig.connectivity.channel.add_channel(server,channel_data)
7979

80+
# Add a empty Channel objects to validate error handling. Validates low level _config_add() methond in Server class
81+
# used by all add methods across the package
82+
channel_data = {}
83+
# pytest.raises(kepconfig.error.KepError,kepconfig.connectivity.channel.add_channel, {'server': server, 'DATA': channel_data})
84+
with pytest.raises(kepconfig.error.KepError) as e:
85+
kepconfig.connectivity.channel.add_channel(server,channel_data)
86+
assert e.type == kepconfig.error.KepError
87+
# assert type(kepconfig.connectivity.channel.add_channel(server,channel_data)) == kepconfig.error.KepError
88+
89+
channel_data = []
90+
with pytest.raises(kepconfig.error.KepError) as e:
91+
kepconfig.connectivity.channel.add_channel(server,channel_data)
92+
assert e.type == kepconfig.error.KepError
93+
8094
# Add multi channels with one failure
8195
channel_data = [
8296
{"common.ALLTYPES_NAME": ch_name+"1","servermain.MULTIPLE_TYPES_DEVICE_DRIVER": "Simulator"},

0 commit comments

Comments
 (0)