Skip to content

Commit de1a03f

Browse files
authored
Merge pull request #200 from ibm-watson-iot/ServicesCredentialsUnitTestMiladLaly
Unitesting for Cloudant, DB2, Eventstreams, Postgres
2 parents 2396c7f + 3b24ec2 commit de1a03f

File tree

5 files changed

+174
-3
lines changed

5 files changed

+174
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class EventStreamsServiceBindingCredentials(ServiceBindingCredentials):
5959
def __init__(self, **kwargs):
6060
if not set(["api_key", "kafka_admin_url", "kafka_brokers_sasl", "user", "password"]).issubset(kwargs):
6161
raise Exception(
62-
"api_key, kafka_admin_url, host, port, username, & password are required parameters for a Cloudant Service Binding: %s"
62+
"api_key, kafka_admin_url, host, port, username, & password are required parameters for a EventStreams Service Binding: %s"
6363
% (json.dumps(kwargs, sort_keys=True))
6464
)
6565

test/test_api_dsc_cloudant.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,50 @@ def testCreateService2(self):
188188
# Deleting the connector will delete all the destinations and forwarding rules too
189189
del self.appClient.dsc[createdConnector.id]
190190
del self.appClient.serviceBindings[createdService.id]
191+
192+
def testCloudantServiceBindingParametersNone(self):
193+
with pytest.raises(Exception) as e:
194+
CloudantServiceBindingCredentials()
195+
assert "host, port, username, & password are required parameters for a Cloudant Service Binding: " in str(
196+
e.value
197+
)
198+
199+
def testCloudantURL(self):
200+
try:
201+
test = CloudantServiceBindingCredentials(host=1, port=2, username=3, password=4)
202+
test.url()
203+
assert False == True
204+
except:
205+
assert True
206+
207+
def testCloudantHost(self):
208+
try:
209+
test = CloudantServiceBindingCredentials(host=1, port=2, username=3, password=4)
210+
test.host()
211+
assert False == True
212+
except:
213+
assert True
214+
215+
def testCloudantPort(self):
216+
try:
217+
test = CloudantServiceBindingCredentials(host=1, port=2, username=3, password=4)
218+
test.port()
219+
assert False == True
220+
except:
221+
assert True
222+
223+
def testCloudantUsername(self):
224+
try:
225+
test = CloudantServiceBindingCredentials(host=1, port=2, username=3, password=4)
226+
test.username()
227+
assert False == True
228+
except:
229+
assert True
230+
231+
def testCloudantPassword(self):
232+
try:
233+
test = CloudantServiceBindingCredentials(host=1, port=2, username=3, password=4)
234+
test.password()
235+
assert False == True
236+
except:
237+
assert True

test/test_api_dsc_db2.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
import testUtils
1313
import time
1414
import pytest
15-
from wiotp.sdk.api.services import CloudantServiceBindingCredentials, CloudantServiceBindingCreateRequest
15+
from wiotp.sdk.api.services import (
16+
CloudantServiceBindingCredentials,
17+
CloudantServiceBindingCreateRequest,
18+
DB2ServiceBindingCredentials,
19+
)
1620
from wiotp.sdk.exceptions import ApiException
1721

1822

@@ -370,3 +374,42 @@ def testServiceDestinationAndRule(self):
370374
# Deleting the connector will delete all the destinations and forwarding rules too
371375
del self.appClient.dsc[createdConnector.id]
372376
del self.appClient.serviceBindings[createdService.id]
377+
378+
def testDB2ServiceBindingCredentialsNone(self):
379+
with pytest.raises(Exception) as e:
380+
test = DB2ServiceBindingCredentials()
381+
assert "username, password, db and ssljdbcurl are required paramaters for a DB2 Service Binding" in str(
382+
e.value
383+
)
384+
385+
def testDB2Username(self):
386+
try:
387+
test = DB2ServiceBindingCredentials(username=1, password=1, db=1, ssljdbcurl=1)
388+
test.username()
389+
assert False == True
390+
except:
391+
assert True
392+
393+
def testDB2Password(self):
394+
try:
395+
test = DB2ServiceBindingCredentials(username=1, password=1, db=1, ssljdbcurl=1)
396+
test.password()
397+
assert False == True
398+
except:
399+
assert True
400+
401+
def testDB2DB(self):
402+
try:
403+
test = DB2ServiceBindingCredentials(username=1, password=1, db=1, ssljdbcurl=1)
404+
test.db()
405+
assert False == True
406+
except:
407+
assert True
408+
409+
def testDB2SslDBCurl(self):
410+
try:
411+
test = DB2ServiceBindingCredentials(username=1, password=1, db=1, ssljdbcurl=1)
412+
test.ssljdbcurl()
413+
assert False == True
414+
except:
415+
assert True

test/test_api_dsc_eventstreams.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,61 @@ def testCreateService2(self):
123123

124124
del self.appClient.dsc[createdConnector.id]
125125
del self.appClient.serviceBindings[createdService.id]
126+
127+
def testEventStreamsServiceBindingParametersNone(self):
128+
with pytest.raises(Exception) as e:
129+
EventStreamsServiceBindingCredentials()
130+
assert (
131+
"api_key, kakfa_admin_url, host, port, username, & password are required parameters for a Cloudant Service Binding: "
132+
in str(e.value)
133+
)
134+
135+
def testEventStreamsAPIKey(self):
136+
try:
137+
test = EventStreamsServiceBindingCredentials(
138+
api_key=1, kafka_admin_url=1, kafka_brokers_sasl=1, user=1, password=1
139+
)
140+
test.api_key()
141+
assert False == True
142+
except:
143+
assert True
144+
145+
def testEventStreamsKafkaAdminURL(self):
146+
try:
147+
test = EventStreamsServiceBindingCredentials(
148+
api_key=1, kafka_admin_url=1, kafka_brokers_sasl=1, user=1, password=1
149+
)
150+
test.kafka_admin_url()
151+
assert False == True
152+
except:
153+
assert True
154+
155+
def testEventStreamsKafkaBrokersSasl(self):
156+
try:
157+
test = EventStreamsServiceBindingCredentials(
158+
api_key=1, kafka_admin_url=1, kafka_brokers_sasl=1, user=1, password=1
159+
)
160+
test.kafka_brokers_sasl()
161+
assert False == True
162+
except:
163+
assert True
164+
165+
def testEventStreamsUser(self):
166+
try:
167+
test = EventStreamsServiceBindingCredentials(
168+
api_key=1, kafka_admin_url=1, kafka_brokers_sasl=1, user=1, password=1
169+
)
170+
test.user()
171+
assert False == True
172+
except:
173+
assert True
174+
175+
def testEventStreamsPassword(self):
176+
try:
177+
test = EventStreamsServiceBindingCredentials(
178+
api_key=1, kafka_admin_url=1, kafka_brokers_sasl=1, user=1, password=1
179+
)
180+
test.password()
181+
assert False == True
182+
except:
183+
assert True

test/test_api_dsc_postgres.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
import testUtils
1313
import time
1414
import pytest
15-
from wiotp.sdk.api.services import CloudantServiceBindingCredentials, CloudantServiceBindingCreateRequest
15+
from wiotp.sdk.api.services import (
16+
CloudantServiceBindingCredentials,
17+
CloudantServiceBindingCreateRequest,
18+
PostgresServiceBindingCredentials,
19+
)
20+
1621
from wiotp.sdk.exceptions import ApiException
1722

1823

@@ -365,3 +370,21 @@ def testServiceDestinationAndRule(self):
365370
# Deleting the connector will delete all the destinations and forwarding rules too
366371
del self.appClient.dsc[createdConnector.id]
367372
del self.appClient.serviceBindings[createdService.id]
373+
374+
def testPostgresServiceBindingParametersNone(self):
375+
with pytest.raises(Exception) as e:
376+
PostgresServiceBindingCredentials()
377+
assert (
378+
"hostname, port, username, password, certificate and database are required paramaters for a PostgreSQL Service Binding: "
379+
in str(e.value)
380+
)
381+
382+
def testPostgresConnection(self):
383+
try:
384+
test = PostgresServiceBindingCredentials(
385+
hostname=1, port=1, username=1, password=1, certificate=1, database=1
386+
)
387+
test.connection()
388+
assert False == True
389+
except:
390+
assert True

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy