Skip to content

Commit 1ec819d

Browse files
committed
Fix the unit tests
1 parent 6039e08 commit 1ec819d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+508
-555
lines changed

.tox.ini.swp

-12 KB
Binary file not shown.

src/wiotp/sdk/api/common.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,11 @@ def __iter__(self, *args, **kwargs):
360360
def find(self, query_params={}):
361361
"""
362362
Gets the list of Schemas, they are used to call specific business logic when data in Watson IoT Platform changes.
363-
363+
364364
Parameters:
365-
365+
366366
- queryParams(dict) - Filter the results by the key-value pairs in the dictionary
367-
367+
368368
Throws APIException on failure.
369369
"""
370370
return self._listToCast(self._apiClient, self._baseUrl, filters=query_params)
@@ -394,7 +394,7 @@ def __delitem__(self, key):
394394

395395
def create(self, item):
396396
"""
397-
Create an Item for the organization in the Watson IoT Platform.
397+
Create an Item for the organization in the Watson IoT Platform.
398398
Parameters:
399399
- name (string) - Name of the service
400400
- type - must be webhook

src/wiotp/sdk/api/dsc/connectors.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ def __init__(self, apiClient):
7979
def find(self, nameFilter=None, typeFilter=None, enabledFilter=None, serviceId=None):
8080
"""
8181
Gets the list of Historian connectors, they are used to configure the Watson IoT Platform to store IoT data in compatible services.
82-
82+
8383
Parameters:
84-
84+
8585
- nameFilter(string) - Filter the results by the specified name
8686
- typeFilter(string) - Filter the results by the specified type, Available values : cloudant, eventstreams
87-
- enabledFilter(boolean) - Filter the results by the enabled flag
87+
- enabledFilter(boolean) - Filter the results by the enabled flag
8888
- serviceId(string) - Filter the results by the service id
8989
- limit(number) - Max number of results returned, defaults 25
9090
- bookmark(string) - used for paging through results
91-
91+
9292
Throws APIException on failure.
9393
"""
9494

@@ -106,7 +106,7 @@ def find(self, nameFilter=None, typeFilter=None, enabledFilter=None, serviceId=N
106106

107107
def create(self, name, type, serviceId, timezone=None, description=None, enabled=None, configuration=None):
108108
"""
109-
Create a connector for the organization in the Watson IoT Platform.
109+
Create a connector for the organization in the Watson IoT Platform.
110110
The connector must reference the target service that the Watson IoT Platform will store the IoT data in.
111111
Parameters:
112112
- name (string) - Name of the service

src/wiotp/sdk/api/registry/devices.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -336,36 +336,36 @@ def __init__(self, apiClient, typeId=None):
336336

337337
class Devices(defaultdict):
338338
"""
339-
Use the global unique identifier of a device, it's `clientId` to address devices.
340-
339+
Use the global unique identifier of a device, it's `clientId` to address devices.
340+
341341
# Delete
342-
342+
343343
```python
344344
del devices["d:orgId:typeId:deviceId"]
345345
```
346-
346+
347347
# Get
348-
Use the global unique identifier of a device, it's `clientId`.
349-
348+
Use the global unique identifier of a device, it's `clientId`.
349+
350350
```python
351351
device = devices["d:orgId:typeId:deviceId"]
352352
print(device.clientId)
353353
print(device)
354-
354+
355355
# Is a device registered?
356-
356+
357357
```python
358358
if "d:orgId:typeId:deviceId" in devices:
359359
print("The device exists")
360360
```
361-
361+
362362
# Iterate through all registered devices
363-
363+
364364
```python
365365
for device in devices:
366366
print(device)
367367
```
368-
368+
369369
"""
370370

371371
# https://docs.python.org/2/library/collections.html#defaultdict-objects
@@ -456,9 +456,9 @@ def create(self, devices):
456456
The response body will contain the generated authentication tokens for all devices.
457457
You must make sure to record these tokens when processing the response.
458458
We are not able to retrieve lost authentication tokens
459-
459+
460460
It accepts accepts a list of devices (List of Dictionary of Devices), or a single device
461-
461+
462462
If you provide a list as the parameter it will return a list in response
463463
If you provide a singular device it will return a singular response
464464
"""

src/wiotp/sdk/api/registry/diag.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
import json
1212
from datetime import datetime
1313
from collections import defaultdict
14+
1415
try:
15-
from collections.abc import MutableSequence
16+
from collections.abc import MutableSequence
1617
except ImportError:
17-
from collections import MutableSequence
18+
from collections import MutableSequence
1819
from wiotp.sdk.exceptions import ApiException
1920

2021

src/wiotp/sdk/api/services/__init__.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,16 @@ def __init__(self, apiClient):
165165

166166
def find(self, nameFilter=None, typeFilter=None, bindingModeFilter=None, boundFilter=None):
167167
"""
168-
Gets the list of services that the Watson IoT Platform can connect to.
168+
Gets the list of services that the Watson IoT Platform can connect to.
169169
The list can include a mixture of services that are either bound or unbound.
170-
170+
171171
Parameters:
172-
172+
173173
- nameFilter(string) - Filter the results by the specified name
174174
- typeFilter(string) - Filter the results by the specified type, Available values : cloudant, eventstreams
175175
- bindingModeFilter(string) - Filter the results by the specified binding mode, Available values : automatic, manual
176-
- boundFilter(boolean) - Filter the results by the bound flag
177-
176+
- boundFilter(boolean) - Filter the results by the bound flag
177+
178178
Throws APIException on failure.
179179
"""
180180

@@ -192,9 +192,9 @@ def find(self, nameFilter=None, typeFilter=None, bindingModeFilter=None, boundFi
192192

193193
def create(self, serviceBinding):
194194
"""
195-
Create a new external service.
196-
The service must include all of the details required to connect
197-
and authenticate to the external service in the credentials property.
195+
Create a new external service.
196+
The service must include all of the details required to connect
197+
and authenticate to the external service in the credentials property.
198198
Parameters:
199199
- serviceName (string) - Name of the service
200200
- serviceType (string) - must be either eventstreams or cloudant

src/wiotp/sdk/api/state/deviceTypes.py

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from wiotp.sdk.api.state.logicalInterfaces import BaseLogicalInterface
2222
from wiotp.sdk.api.state.physicalInterfaces import PhysicalInterface
2323

24+
2425
# =========================================================================
2526
# Physical Interface for the Device Type
2627
# =========================================================================
@@ -166,6 +167,7 @@ def __init__(self, apiClient, deviceTypeId):
166167
# Mappings for the Device Type
167168
# =========================================================================
168169

170+
169171
# define the common properties found on most Rest API Items
170172
class DeviceTypeMapping(defaultdict):
171173
def __init__(self, **kwargs):

src/wiotp/sdk/api/state/schemas.py

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ def __init__(self, apiClient):
8080
super(DraftSchemas, self).__init__(apiClient, Schema, IterableSchemaList, "api/v0002/draft/schemas")
8181

8282
def create(self, name, schemaFileName, schemaContents, description):
83-
8483
"""
8584
Create a schema for the org.
8685
Returns: schemaId (string), response (object).

src/wiotp/sdk/api/state/thingTypes.py

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ def __init__(self, apiClient, thingTypeId):
179179
# Mappings for the Thing Type
180180
# =========================================================================
181181

182+
182183
# define the common properties found on most Rest API Items
183184
class ThingTypeMapping(defaultdict):
184185
def __init__(self, **kwargs):

src/wiotp/sdk/application/client.py

+21-59
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626

2727
class ApplicationClient(AbstractClient):
2828
"""
29-
Extends #wiotp.AbstractClient to implement an application client supporting
29+
Extends #wiotp.AbstractClient to implement an application client supporting
3030
messaging over MQTT
31-
31+
3232
# Parameters
3333
options (dict): Configuration options for the client
34-
logHandlers (list<logging.Handler>): Log handlers to configure. Defaults to `None`,
34+
logHandlers (list<logging.Handler>): Log handlers to configure. Defaults to `None`,
3535
which will result in a default log handler being created.
36-
36+
3737
# Configuration Options
3838
The options parameter expects a Python dictionary containing the following keys:
39-
39+
4040
- `auth-key` The API key to to securely connect your application to Watson IoT Platform.
4141
- `auth-token` An authentication token to securely connect your application to Watson IoT Platform.
4242
- `clean-session` A boolean value indicating whether to use MQTT clean session.
@@ -71,9 +71,8 @@ def __init__(self, config, logHandlers=None):
7171
self.client.message_callback_add("iot-2/type/+/id/+/err/data", self._onErrorTopic)
7272
self.client.message_callback_add("iot-2/thing/type/+/id/+/err/data", self._onThingError)
7373

74-
# Add handler for commands if not connected to QuickStart
75-
if not self._config.isQuickstart():
76-
self.client.message_callback_add("iot-2/type/+/id/+/cmd/+/fmt/+", self._onDeviceCommand)
74+
# Add handler for commands
75+
self.client.message_callback_add("iot-2/type/+/id/+/cmd/+/fmt/+", self._onDeviceCommand)
7776

7877
# Attach fallback handler
7978
self.client.on_message = self._onUnsupportedMessage
@@ -87,26 +86,22 @@ def __init__(self, config, logHandlers=None):
8786
self.errorTopicCallback = None
8887
self.appStatusCallback = None
8988

90-
# Create an api client if not connected in QuickStart mode
91-
if not self._config.isQuickstart():
92-
apiClient = ApiClient(self._config, self.logger)
93-
self.registry = Registry(apiClient)
94-
self.usage = Usage(apiClient)
95-
self.dsc = DSC(apiClient)
96-
self.lec = LEC(apiClient)
97-
self.mgmt = Mgmt(apiClient)
98-
self.serviceBindings = ServiceBindings(apiClient)
99-
self.actions = Actions(apiClient)
100-
self.state = StateMgr(apiClient)
101-
102-
# We directly expose the get() method via self.serviceStatus()
103-
self._serviceStatus = ServiceStatus(apiClient)
89+
# Create an api client
90+
apiClient = ApiClient(self._config, self.logger)
91+
self.registry = Registry(apiClient)
92+
self.usage = Usage(apiClient)
93+
self.dsc = DSC(apiClient)
94+
self.lec = LEC(apiClient)
95+
self.mgmt = Mgmt(apiClient)
96+
self.serviceBindings = ServiceBindings(apiClient)
97+
self.actions = Actions(apiClient)
98+
self.state = StateMgr(apiClient)
99+
100+
# We directly expose the get() method via self.serviceStatus()
101+
self._serviceStatus = ServiceStatus(apiClient)
104102

105103
def serviceStatus(self):
106-
if not self._config.isQuickstart():
107-
return self._serviceStatus.get()
108-
else:
109-
return None
104+
return self._serviceStatus.get()
110105

111106
def subscribeToDeviceEvents(self, typeId="+", deviceId="+", eventId="+", msgFormat="+", qos=0):
112107
"""
@@ -125,12 +120,6 @@ def subscribeToDeviceEvents(self, typeId="+", deviceId="+", eventId="+", msgForm
125120
the mid argument if you register a subscriptionCallback method.
126121
If the subscription fails then the return value will be `0`
127122
"""
128-
if self._config.isQuickstart() and deviceId == "+":
129-
self.logger.warning(
130-
"QuickStart applications do not support wildcard subscription to events from all devices"
131-
)
132-
return 0
133-
134123
topic = "iot-2/type/%s/id/%s/evt/%s/fmt/%s" % (typeId, deviceId, eventId, msgFormat)
135124
return self._subscribe(topic, qos)
136125

@@ -148,10 +137,6 @@ def subscribeToDeviceStatus(self, typeId="+", deviceId="+"):
148137
the mid argument if you register a subscriptionCallback method.
149138
If the subscription fails then the return value will be `0`
150139
"""
151-
if self._config.isQuickstart() and deviceId == "+":
152-
self.logger.warning("QuickStart applications do not support wildcard subscription to device status")
153-
return 0
154-
155140
topic = "iot-2/type/%s/id/%s/mon" % (typeId, deviceId)
156141
return self._subscribe(topic, 0)
157142

@@ -169,10 +154,6 @@ def subscribeToErrorTopic(self, typeId="+", Id="+"):
169154
the mid argument if you register a subscriptionCallback method.
170155
If the subscription fails then the return value will be `0`
171156
"""
172-
if self._config.isQuickstart() and Id == "+":
173-
self.logger.warning("QuickStart applications do not support wildcard subscription to error topics")
174-
return 0
175-
176157
topic = "iot-2/type/%s/id/%s/err/data" % (typeId, Id)
177158
return self._subscribe(topic, 0)
178159

@@ -190,10 +171,6 @@ def subscribeToThingErrors(self, typeId="+", Id="+"):
190171
the mid argument if you register a subscriptionCallback method.
191172
If the subscription fails then the return value will be `0`
192173
"""
193-
if self._config.isQuickstart() and Id == "+":
194-
self.logger.warning("QuickStart applications do not support wildcard subscription to error topics")
195-
return 0
196-
197174
topic = "iot-2/thing/type/%s/id/%s/err/data" % (typeId, Id)
198175
return self._subscribe(topic, 0)
199176

@@ -212,10 +189,6 @@ def subscribeToThingState(self, typeId="+", thingId="+", logicalInterfaceId="+")
212189
the mid argument if you register a subscriptionCallback method.
213190
If the subscription fails then the return value will be `0`
214191
"""
215-
if self._config.isQuickstart():
216-
self.logger.warning("QuickStart applications do not support thing state")
217-
return 0
218-
219192
topic = "iot-2/thing/type/%s/id/%s/intf/%s/evt/state" % (typeId, thingId, logicalInterfaceId)
220193
return self._subscribe(topic, 0)
221194

@@ -234,10 +207,6 @@ def subscribeToDeviceState(self, typeId="+", deviceId="+", logicalInterfaceId="+
234207
the mid argument if you register a subscriptionCallback method.
235208
If the subscription fails then the return value will be `0`
236209
"""
237-
if self._config.isQuickstart():
238-
self.logger.warning("QuickStart applications do not support device state")
239-
return 0
240-
241210
topic = "iot-2/type/%s/id/%s/intf/%s/evt/state" % (typeId, deviceId, logicalInterfaceId)
242211
return self._subscribe(topic, 0)
243212

@@ -258,10 +227,6 @@ def subscribeToDeviceCommands(self, typeId="+", deviceId="+", commandId="+", msg
258227
the mid argument if you register a subscriptionCallback method.
259228
If the subscription fails then the return value will be `0`
260229
"""
261-
if self._config.isQuickstart():
262-
self.logger.warning("QuickStart applications do not support commands")
263-
return 0
264-
265230
topic = "iot-2/type/%s/id/%s/cmd/%s/fmt/%s" % (typeId, deviceId, commandId, msgFormat)
266231
return self._subscribe(topic, 0)
267232

@@ -285,9 +250,6 @@ def publishCommand(self, typeId, deviceId, commandId, msgFormat, data=None, qos=
285250
- qos 0 : the client has asynchronously begun to send the event
286251
- qos 1 and 2 : the client has confirmation of delivery from WIoTP
287252
"""
288-
if self._config.isQuickstart():
289-
self.logger.warning("QuickStart applications do not support sending commands")
290-
return False
291253
if not self.connectEvent.wait(timeout=10):
292254
return False
293255
else:

0 commit comments

Comments
 (0)