Skip to content

Commit

Permalink
Merge pull request versionone#21 from mtalexan/connection-unittests
Browse files Browse the repository at this point in the history
Better Connection Unittests
  • Loading branch information
mtalexan authored Jun 21, 2018
2 parents 4b7495d + 0908438 commit 0de1eca
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 15 deletions.
9 changes: 7 additions & 2 deletions tests/common_test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ class PublicTestServerConnection():
password = 'admin'
address = 'www14.v1host.com'
instance = 'v1sdktesting'
#TODO: Add OAuth key
scheme = 'https'
# must match scheme + "://" + address + "/" + instance
instance_url = 'https://www14.v1host.com/v1sdktesting'
token = '1.VdeWXQVNdY0yVpYexTtznCxcWTQ='

def __init__():
pass
Expand All @@ -27,7 +30,9 @@ def getV1Meta():
return None
else:
return v1pysdk.V1Meta(
instance_url = 'https://' + PublicTestServerConnection.address + '/' + PublicTestServerConnection.instance,
address = PublicTestServerConnection.address,
instance = PublicTestServerConnection.instance,
scheme = 'https',
username = PublicTestServerConnection.username,
password = PublicTestServerConnection.password,
)
135 changes: 122 additions & 13 deletions tests/connect_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,134 @@
from elementtree.ElementTree import parse, fromstring, Element

from v1pysdk.client import *
from v1pysdk import V1Meta
from .common_test_server import PublicTestServerConnection

class TestV1Connection(TestCase):
def test_connect(self, username=None, password=None, address=None, instance=None):
if not username and not password:
def test_connect(self):
username = PublicTestServerConnection.username
password = PublicTestServerConnection.password
if not address:
address = PublicTestServerConnection.address
if not instance:
instance = PublicTestServerConnection.instance
self.addDetail('URL', text_content(address + "/" + instance))
self.addDetail('username', text_content(username))
self.addDetail('URL', text_content(address + "/" + instance))
self.addDetail('username', text_content(username))

server = V1Server(address=address, username=username, password=password,instance=instance)
# The story names, but limit to only the first result so we don't get inundated with results
code, body = server.fetch('/rest-1.v1/Data/Story?sel=Name&page=1,0')
self.addDetail('Code', text_content(str(code)))
self.addDetail('Body', text_content(str(body)))
server = V1Server(address=address, username=username, password=password,instance=instance)
# The story names, but limit to only the first result so we don't get inundated with results
code, body = server.fetch('/rest-1.v1/Data/Story?sel=Name&page=1,0')
self.addDetail('Code', text_content(str(code)))
self.addDetail('Body', text_content(str(body)))

elem = fromstring(body)
self.assertThat(elem.tag, Equals('Assets'))
elem = fromstring(body)
self.assertThat(elem.tag, Equals('Assets'))

def test_meta_connect_instance_url(self):
v1 = None
self.addDetail('URL', text_content(PublicTestServerConnection.instance_url))
self.addDetail('username', text_content(PublicTestServerConnection.username))
try:
v1 = V1Meta(
instance_url = PublicTestServerConnection.instance_url,
username = PublicTestServerConnection.username,
password = PublicTestServerConnection.password,
)
except Exception as e:
self.assertTrue(False, message="Error trying to create connection: " + str(e))

try:
items = v1.Story.select('Name').page(size=1)
items.first() #run the query
except Exception as e:
self.assertTrue(False, message="Error running query from connection: " + str(e))

def test_meta_connect_instance_and_address(self):
v1 = None
self.addDetail('address', text_content(PublicTestServerConnection.address))
self.addDetail('instance', text_content(PublicTestServerConnection.instance))
self.addDetail('username', text_content(PublicTestServerConnection.username))

try:
v1 = V1Meta(
address = PublicTestServerConnection.address,
instance = PublicTestServerConnection.instance,
username = PublicTestServerConnection.username,
password = PublicTestServerConnection.password,
)
except Exception as e:
self.assertTrue(False, message="Error trying to create connection: " + str(e))

try:
items = v1.Story.select('Name').page(size=1)
items.first() #run the query
except Exception as e:
self.assertTrue(False, message="Error running query from connection: " + str(e))

def test_meta_connect_instance_url_overrides_separate(self):
v1 = None
address = self.getUniqueString() #garbage
instance = self.getUniqueString() #garbage
self.addDetail('address', text_content(PublicTestServerConnection.address))
self.addDetail('instance-url', text_content(PublicTestServerConnection.instance_url))
self.addDetail('instance', text_content(address))
self.addDetail('username', text_content(instance))

try:
v1 = V1Meta(
instance_url = PublicTestServerConnection.instance_url,
address = address,
instance = instance,
username = PublicTestServerConnection.username,
password = PublicTestServerConnection.password,
)
except Exception as e:
self.assertTrue(False, message="Error trying to create connection: " + str(e))

try:
items = v1.Story.select('Name').page(size=1)
items.first() #run the query
except Exception as e:
self.assertTrue(False, message="Error running query from connection: " + str(e))

def test_meta_connect_oauth(self):
v1 = None
self.addDetail('address', text_content(PublicTestServerConnection.address))
self.addDetail('instance', text_content(PublicTestServerConnection.instance))

try:
v1 = V1Meta(
instance_url = PublicTestServerConnection.instance_url,
#no username
password = PublicTestServerConnection.token,
use_password_as_token=True,
)
except Exception as e:
self.assertTrue(False, message="Error trying to create connection: " + str(e))

try:
items = v1.Story.select('Name').page(size=1)
items.first() #run the query
except Exception as e:
self.assertTrue(False, message="Error running query from connection: " + str(e))

def test_meta_connect_oauth_ignores_username(self):
v1 = None
username = self.getUniqueString() #garbage
self.addDetail('address', text_content(PublicTestServerConnection.address))
self.addDetail('instance', text_content(PublicTestServerConnection.instance))
self.addDetail('username', text_content(username))

try:
v1 = V1Meta(
instance_url = PublicTestServerConnection.instance_url,
username = username,
password = PublicTestServerConnection.token,
use_password_as_token=True,
)
except Exception as e:
self.assertTrue(False, message="Error trying to create connection: " + str(e))

try:
items = v1.Story.select('Name').page(size=1)
items.first() #run the query
except Exception as e:
self.assertTrue(False, message="Error running query from connection: " + str(e))

0 comments on commit 0de1eca

Please sign in to comment.