Skip to content

Commit f03313e

Browse files
committed
Fix the unit tests
1 parent 05e177d commit f03313e

33 files changed

+435
-342
lines changed

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/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
@@ -78,7 +78,6 @@ def __init__(self, apiClient):
7878
super(DraftSchemas, self).__init__(apiClient, Schema, IterableSchemaList, "api/v0002/draft/schemas")
7979

8080
def create(self, name, schemaFileName, schemaContents, description):
81-
8281
"""
8382
Create a schema for the org.
8483
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/config.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
class ApplicationClientConfig(defaultdict):
2020
def __init__(self, **kwargs):
21-
if "auth" not in kwargs or kwargs["auth"] is None:
21+
# previously quickstart supported unauthenticated connections but has been removed
22+
if "auth" not in kwargs:
2223
raise ConfigurationException("Missing auth from configuration")
23-
2424
if "key" not in kwargs["auth"] or kwargs["auth"]["key"] is None:
2525
raise ConfigurationException("Missing auth.key from configuration")
2626
if "token" not in kwargs["auth"] or kwargs["auth"]["token"] is None:
@@ -248,6 +248,11 @@ def parseEnvVars():
248248
"auth": {"key": authKey, "token": authToken}
249249
}
250250

251+
<<<<<<< HEAD
252+
=======
253+
cfg["auth"] = {"key": authKey, "token": authToken}
254+
255+
>>>>>>> 1ec819d (Fix the unit tests)
251256
return ApplicationClientConfig(**cfg)
252257

253258

src/wiotp/sdk/client.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ def __init__(
132132
# paho 2.0.0 has a breaking change for callbacks to support both 2.0.0 and 1.x we need
133133
# to create a client in version1 mode if using 2.0.0
134134
if pahoVersion >= "2.0.0":
135-
self.client = paho.Client(paho.CallbackAPIVersion.VERSION1, self.clientId, transport=transport, clean_session=(not cleanStart))
135+
self.client = paho.Client(
136+
paho.CallbackAPIVersion.VERSION1, self.clientId, transport=transport, clean_session=(not cleanStart)
137+
)
136138
else:
137139
self.client = paho.Client(self.clientId, transport=transport, clean_session=(not cleanStart))
138140

src/wiotp/sdk/device/command.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
class Command:
1616
"""
1717
Represents a command sent to a device.
18-
18+
1919
# Parameters
2020
pahoMessage (?): ?
21-
messageEncoderModules (dict): Dictionary of Python modules, keyed to the
22-
message format the module should use.
23-
21+
messageEncoderModules (dict): Dictionary of Python modules, keyed to the
22+
message format the module should use.
23+
2424
# Attributes
2525
command (string): Identifies the command.
2626
format (string): The format can be any string, for example JSON.
2727
data (dict): The data for the payload. Maximum length is 131072 bytes.
2828
timestamp (datetime): The date and time of the event.
2929
3030
# Raises
31-
InvalidEventException: If the command was recieved on a topic that does
31+
InvalidEventException: If the command was recieved on a topic that does
3232
not match the regular expression `iot-2/cmd/(.+)/fmt/(.+)`
3333
"""
3434

src/wiotp/sdk/device/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ def parseEnvVars():
216216
"auth": {"token": authToken}
217217
}
218218

219+
cfg["auth"] = {"token": authToken}
220+
219221
return DeviceClientConfig(**cfg)
220222

221223

test/testUtils/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,22 @@
1010
import wiotp.sdk.application
1111
import pytest
1212
import os
13+
import sys
1314

1415
oneJobOnlyTest = pytest.mark.skipif(
1516
os.getenv("ONE_JOB_ONLY_TESTS", "true") == "false",
1617
reason="Doesn't support running in multiple envs in parallel due to limits on # of service bindings allowed",
1718
)
1819

1920

21+
def isstring(s):
22+
# if we use Python 3
23+
if sys.version_info[0] >= 3:
24+
return isinstance(s, str)
25+
else:
26+
return isinstance(s, basestring) # noqa: F821
27+
28+
2029
class AbstractTest(object):
2130

2231
WIOTP_API_KEY = os.getenv("WIOTP_API_KEY")

test/test_api_actions.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ class TestActions(testUtils.AbstractTest):
6969
testActionName = "test-action-new"
7070
updated_action_name = testActionName + "-updated"
7171

72-
def isstring(self, s):
73-
# if we use Python 3
74-
if sys.version_info[0] >= 3:
75-
basestring = str
76-
return isinstance(s, basestring)
77-
7872
# =========================================================================
7973
# Set up services
8074
# =========================================================================
@@ -125,9 +119,9 @@ def checkAction(self, action, name, type, description, configuration, enabled):
125119
assert action.configuration[configElement] is not None
126120
assert action.enabled == enabled
127121
assert isinstance(action.created, datetime)
128-
assert self.isstring(action.createdBy)
122+
assert testUtils.isstring(action.createdBy)
129123
assert isinstance(action.updated, datetime)
130-
assert self.isstring(action.updatedBy)
124+
assert testUtils.isstring(action.updatedBy)
131125

132126
def doesActionNameExist(self, name):
133127
for a in self.appClient.actions.find({"name": name}):

test/test_api_dsc_cloudant.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
import testUtils
1313
import time
1414
import pytest
15+
import os
1516
from wiotp.sdk.api.services import CloudantServiceBindingCredentials, CloudantServiceBindingCreateRequest
1617
from wiotp.sdk.exceptions import ApiException
1718

1819

1920
@testUtils.oneJobOnlyTest
21+
@pytest.mark.skipif(os.getenv("CLOUDANT_HOST", None) is None, reason="Cloudant host not specified")
2022
class TestDscCloudant(testUtils.AbstractTest):
2123

2224
# =========================================================================
@@ -153,7 +155,7 @@ def testCreateService2(self):
153155
assert rule1.logicalInterfaceId == None
154156
assert rule1.columnMappings == None
155157
assert rule1.enabled == True
156-
assert isinstance(rule1.id, str)
158+
assert testUtils.isstring(rule1.id)
157159
assert isinstance(rule1.updated, datetime)
158160
assert isinstance(rule1.created, datetime)
159161

test/test_api_dsc_db2.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import testUtils
1313
import time
1414
import pytest
15+
import os
1516
from wiotp.sdk.api.services import (
1617
CloudantServiceBindingCredentials,
1718
CloudantServiceBindingCreateRequest,
@@ -20,6 +21,7 @@
2021
from wiotp.sdk.exceptions import ApiException
2122

2223

24+
@pytest.mark.skipif(os.getenv("DB2_PASSWORD") is None, reason="DB2 settings not provided")
2325
@testUtils.oneJobOnlyTest
2426
class TestDscDb2(testUtils.AbstractTest):
2527
def checkDB2Service(self, service, name, description):
@@ -170,7 +172,7 @@ def checkDB2ForwardingRule(self, createdRule, name, destination, description, lo
170172
assert createdRule.columnMappings == columnMappings
171173
assert createdRule.typeId == None
172174
assert createdRule.eventId == None
173-
assert isinstance(createdRule.id, str)
175+
assert testUtils.isstring(createdRule.id)
174176
assert isinstance(createdRule.updated, datetime)
175177
assert isinstance(createdRule.created, datetime)
176178

test/test_api_dsc_eventstreams.py

+2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
import pytest
1313
import testUtils
1414
import time
15+
import os
1516

1617
from wiotp.sdk.api.services import EventStreamsServiceBindingCredentials, EventStreamsServiceBindingCreateRequest
1718
from wiotp.sdk.exceptions import ApiException
1819

1920

21+
@pytest.mark.skipif(os.getenv("EVENTSTREAMS_API_KEY") is None, reason="Eventstreams details not test")
2022
@testUtils.oneJobOnlyTest
2123
class TestDscEventStreams(testUtils.AbstractTest):
2224

test/test_api_dsc_postgres.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import testUtils
1313
import time
1414
import pytest
15+
import os
1516
from wiotp.sdk.api.services import (
1617
CloudantServiceBindingCredentials,
1718
CloudantServiceBindingCreateRequest,
@@ -21,6 +22,7 @@
2122
from wiotp.sdk.exceptions import ApiException
2223

2324

25+
@pytest.mark.skipif(os.getenv("POSTGRES_DATABASE") is None, reason="postgres database not specified")
2426
@testUtils.oneJobOnlyTest
2527
class TestDscPostgres(testUtils.AbstractTest):
2628
def checkPostgresService(self, service, name, description):
@@ -173,7 +175,7 @@ def checkPostgresForwardingRule(
173175
assert createdRule.columnMappings == columnMappings
174176
assert createdRule.typeId == None
175177
assert createdRule.eventId == None
176-
assert isinstance(createdRule.id, str)
178+
assert testUtils.isstring(createdRule.id)
177179
assert isinstance(createdRule.updated, datetime)
178180
assert isinstance(createdRule.created, datetime)
179181

test/test_api_registry_devicetypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,4 @@ def testDeleteTypeId(self, device, deviceType):
155155
{"id": typeId, "description": "This is still a test", "metadata": {"test": "test"}}
156156
)
157157
self.appClient.registry.devicetypes.delete(typeId)
158-
assert typeId not in deviceType.devices
158+
assert typeId not in deviceType.devices

test/test_api_state_device_types.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import string
1717
import json
1818
import sys
19-
from test_state_utils import TestStateUtils
19+
import test_state_utils as TestStateUtils
2020

2121

2222
@testUtils.oneJobOnlyTest
@@ -87,12 +87,6 @@ def testCleanup(self):
8787
self.appClient, (TestDeviceTypes.testEventSchemaName, TestDeviceTypes.testLiSchemaName)
8888
)
8989

90-
def isstring(self, s):
91-
# if we use Python 3
92-
if sys.version_info[0] >= 3:
93-
basestring = str
94-
return isinstance(s, basestring)
95-
9690
def createAndCheckDT(
9791
self, name, description, deviceInfo=None, metadata=None, edgeConfiguration=None, classId="Device"
9892
):

test/test_api_state_eventTypes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ def checkEventType(self, eventType, name, description, schemaId):
6262
assert eventType.version == "draft"
6363

6464
assert isinstance(eventType.created, datetime)
65-
assert isinstance(eventType.createdBy, str)
65+
assert testUtils.isstring(eventType.createdBy)
6666
assert isinstance(eventType.updated, datetime)
67-
assert isinstance(eventType.updatedBy, str)
67+
assert testUtils.isstring(eventType.updatedBy)
6868

6969
def doesSchemaNameExist(self, name):
7070
for a in self.appClient.state.draft.schemas.find({"name": name}):

test/test_api_state_logical_interfaces.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ def checkLI(self, logicalInterface, name, description, schemaId, version, alias)
6666
assert logicalInterface.alias == alias
6767

6868
assert isinstance(logicalInterface.created, datetime)
69-
assert isinstance(logicalInterface.createdBy, str)
69+
assert testUtils.isstring(logicalInterface.createdBy)
7070
assert isinstance(logicalInterface.updated, datetime)
71-
assert isinstance(logicalInterface.updatedBy, str)
71+
assert testUtils.isstring(logicalInterface.updatedBy)
7272

7373
def doesSchemaNameExist(self, name):
7474
for a in self.appClient.state.draft.schemas.find({"name": name}):

test/test_api_state_physical_interfaces.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ def checkPI(self, physicalInterface, name, description):
7272
assert physicalInterface.description == description
7373

7474
assert isinstance(physicalInterface.created, datetime)
75-
assert isinstance(physicalInterface.createdBy, str)
75+
assert testUtils.isstring(physicalInterface.createdBy)
7676
assert isinstance(physicalInterface.updated, datetime)
77-
assert isinstance(physicalInterface.updatedBy, str)
77+
assert testUtils.isstring(physicalInterface.updatedBy)
7878

7979
def doesSchemaNameExist(self, name):
8080
for a in self.appClient.state.draft.schemas.find({"name": name}):

test/test_api_state_rules.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ def checkRule(self, rule, name, description, logicalInterfaceId, condition, noti
7171
assert rule.notificationStrategy == notificationStrategy
7272

7373
assert isinstance(rule.created, datetime)
74-
assert isinstance(rule.createdBy, str)
74+
assert testUtils.isstring(rule.createdBy)
7575
assert isinstance(rule.updated, datetime)
76-
assert isinstance(rule.updatedBy, str)
76+
assert testUtils.isstring(rule.updatedBy)
7777

7878
def doesSchemaNameExist(self, name):
7979
for a in self.appClient.state.draft.schemas.find({"name": name}):

0 commit comments

Comments
 (0)