Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ install:
- pip install -r test_requirements.txt
before_install:
- export DEVICE_HIVE_TRANSPORT_URLS='http://playground.dev.devicehive.com/api/rest,ws://playground.dev.devicehive.com/api/websocket'
- openssl aes-256-cbc -K $encrypted_1ea9ebbf5537_key -iv $encrypted_1ea9ebbf5537_iv -in refresh_token.txt.enc -out refresh_token.txt -d
- export DEVICE_HIVE_REFRESH_TOKEN=$(cat refresh_token.txt)
script: pytest -xv tests --transport-urls=$DEVICE_HIVE_TRANSPORT_URLS --refresh-token=$DEVICE_HIVE_REFRESH_TOKEN
- openssl aes-256-cbc -K $encrypted_1ea9ebbf5537_key -iv $encrypted_1ea9ebbf5537_iv -in admin_refresh_token.txt.enc -out admin_refresh_token.txt -d
- export DEVICE_HIVE_ADMIN_REFRESH_TOKEN=$(cat admin_refresh_token.txt)
- openssl aes-256-cbc -K $encrypted_94dc46d8330a_key -iv $encrypted_94dc46d8330a_iv -in user_refresh_token.txt.enc -out user_refresh_token.txt -d
- export DEVICE_HIVE_USER_REFRESH_TOKEN=$(cat user_refresh_token.txt)
script: pytest -xv tests --transport-urls=$DEVICE_HIVE_TRANSPORT_URLS --admin-refresh-token=$DEVICE_HIVE_ADMIN_REFRESH_TOKEN --user-refresh-token=$DEVICE_HIVE_USER_REFRESH_TOKEN
File renamed without changes.
15 changes: 11 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@

def pytest_addoption(parser):
parser.addoption('--transport-urls', action='store', help='Transport urls')
parser.addoption('--refresh-token', action='store', help='Refresh token')
parser.addoption('--admin-refresh-token', action='store',
help='Admin refresh tokens')
parser.addoption('--user-refresh-token', action='store',
help='User refresh tokens')


def pytest_generate_tests(metafunc):
if metafunc.module.__name__.find('.test_api') == -1:
return
transport_urls = metafunc.config.option.transport_urls.split(',')
refresh_token = metafunc.config.option.refresh_token
refresh_tokens = {'admin': metafunc.config.option.admin_refresh_token,
'user': metafunc.config.option.user_refresh_token}
tests = []
ids = []
for transport_url in transport_urls:
tests.append(Test(transport_url, refresh_token))
ids.append(transport_url)
for token_type, refresh_token in refresh_tokens.items():
if not refresh_token:
continue
tests.append(Test(transport_url, refresh_token, token_type))
ids.append('%s:%s' % (token_type, transport_url))
metafunc.parametrize('test', tests, ids=ids)
27 changes: 24 additions & 3 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,19 @@ def disconnect(self):
class Test(object):
"""Test class."""

def __init__(self, transport_url, refresh_token):
def __init__(self, transport_url, refresh_token, token_type):
self._transport_url = transport_url
self._refresh_token = refresh_token
self._token_type = token_type
self._transport_name = DeviceHive.transport_name(self._transport_url)

def generate_id(self, key=None):
time_key = repr(time.time())
if not key:
return '%s-%s' % (self._transport_name, time_key)
return '%s-%s-%s' % (self._transport_name, key, time_key)
return '%s-%s-%s' % (self._transport_name, self._token_type,
time_key)
return '%s-%s-%s-%s' % (self._transport_name, key, self._token_type,
time_key)

@property
def transport_name(self):
Expand All @@ -67,6 +70,24 @@ def http_transport(self):
def websocket_transport(self):
return self._transport_name == 'websocket'

@property
def user_refresh_token(self):
return self._token_type == 'user'

@property
def admin_refresh_token(self):
return self._token_type == 'admin'

def only_user_implementation(self):
if self.user_refresh_token:
return
pytest.skip('Implemented only for user refresh token.')

def only_admin_implementation(self):
if self.admin_refresh_token:
return
pytest.skip('Implemented only for admin refresh token.')

def only_http_implementation(self):
if self.http_transport:
return
Expand Down
57 changes: 31 additions & 26 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ def handle_connect(handler):
handler.api.create_token(user_id)
assert False
except ApiResponseError as api_response_error:
# TODO: add http support after server response will be fixed.
if test.websocket_transport:
assert api_response_error.code == 404
assert api_response_error.code == 404

test.only_admin_implementation()
test.run(handle_connect)


Expand Down Expand Up @@ -125,7 +124,6 @@ def handle_connect(handler):
except DeviceError:
pass
[device.remove() for device in devices]
# TODO: add http support after server response will be fixed.
if test.http_transport:
return
try:
Expand Down Expand Up @@ -230,7 +228,6 @@ def handle_connect(handler):
except DeviceError:
pass
[device.remove() for device in devices]
# TODO: add http support after server response will be fixed.
if test.http_transport:
return
try:
Expand Down Expand Up @@ -348,7 +345,6 @@ def handle_connect(handler):
except DeviceError:
pass
[device.remove() for device in devices]
# TODO: add http support after server response will be fixed.
if test.http_transport:
return
try:
Expand Down Expand Up @@ -450,7 +446,12 @@ def handle_connect(handler):
handler.api.get_device(device_id)
assert False
except ApiResponseError as api_response_error:
assert api_response_error.code == 404
if test.admin_refresh_token:
assert api_response_error.code == 404
# TODO: uncomment after server response for ws for user token will
# be fixed
# else:
# assert api_response_error.code == 403

test.run(handle_connect)

Expand Down Expand Up @@ -501,27 +502,26 @@ def handle_connect(handler):
name_pattern = test_id + '%'
networks = handler.api.list_networks(name_pattern=name_pattern)
assert len(networks) == len(options)
# TODO: add websocket transport after server response will be fixed.
if test.http_transport:
network_0, network_1 = handler.api.list_networks(
name_pattern=name_pattern, sort_field='name', sort_order='ASC')
assert network_0.name == options[0]['name']
assert network_1.name == options[1]['name']
network_0, network_1 = handler.api.list_networks(
name_pattern=name_pattern, sort_field='name', sort_order='DESC')
assert network_0.name == options[1]['name']
assert network_1.name == options[0]['name']
network, = handler.api.list_networks(name_pattern=name_pattern,
sort_field='name',
sort_order='ASC', take=1)
assert network.name == options[0]['name']
network, = handler.api.list_networks(name_pattern=name_pattern,
sort_field='name',
sort_order='ASC', take=1,
skip=1)
assert network.name == options[1]['name']
network_0, network_1 = handler.api.list_networks(
name_pattern=name_pattern, sort_field='name', sort_order='ASC')
assert network_0.name == options[0]['name']
assert network_1.name == options[1]['name']
network_0, network_1 = handler.api.list_networks(
name_pattern=name_pattern, sort_field='name', sort_order='DESC')
assert network_0.name == options[1]['name']
assert network_1.name == options[0]['name']
network, = handler.api.list_networks(name_pattern=name_pattern,
sort_field='name',
sort_order='ASC', take=1)
assert network.name == options[0]['name']
network, = handler.api.list_networks(name_pattern=name_pattern,
sort_field='name',
sort_order='ASC', take=1,
skip=1)
assert network.name == options[1]['name']
[test_network.remove() for test_network in test_networks]

test.only_admin_implementation()
test.run(handle_connect)


Expand All @@ -543,6 +543,7 @@ def handle_connect(handler):
except ApiResponseError as api_response_error:
assert api_response_error.code == 404

test.only_admin_implementation()
test.run(handle_connect)


Expand All @@ -562,6 +563,7 @@ def handle_connect(handler):
assert api_response_error.code == 403
network.remove()

test.only_admin_implementation()
test.run(handle_connect)


Expand Down Expand Up @@ -616,6 +618,7 @@ def handle_connect(handler):
assert user.login == options[1]['login']
[test_user.remove() for test_user in test_users]

test.only_admin_implementation()
test.run(handle_connect)


Expand Down Expand Up @@ -652,6 +655,7 @@ def handle_connect(handler):
except ApiResponseError as api_response_error:
assert api_response_error.code == 404

test.only_admin_implementation()
test.run(handle_connect)


Expand All @@ -677,4 +681,5 @@ def handle_connect(handler):
assert api_response_error.code == 403
user.remove()

test.only_admin_implementation()
test.run(handle_connect)
9 changes: 6 additions & 3 deletions tests/test_api_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ def handle_connect(handler):
command.save()
assert False
except ApiResponseError as api_response_error:
# TODO: uncomment after server response will be fixed.
# assert api_response_error.code() == 404
pass
if test.admin_refresh_token:
assert api_response_error.code == 404
# TODO: uncomment after server response for ws for user token will
# be fixed
# else:
# assert api_response_error.code == 403

test.run(handle_connect)
58 changes: 30 additions & 28 deletions tests/test_api_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ def handle_connect(handler):
device_1.remove()
assert False
except ApiResponseError as api_response_error:
assert api_response_error.code == 404
if test.admin_refresh_token:
assert api_response_error.code == 404
# TODO: uncomment after server response for ws for user token will
# be fixed
# else:
# assert api_response_error.code == 403

test.run(handle_connect)

Expand Down Expand Up @@ -117,7 +122,6 @@ def handle_connect(handler):
assert False
except DeviceError:
pass
# TODO: add http support after server response will be fixed.
if test.http_transport:
return
try:
Expand Down Expand Up @@ -149,12 +153,6 @@ def handle_connect(handler):
assert False
except DeviceError:
pass
# TODO: add after server response will be fixed.
# try:
# device_1.unsubscribe_insert_commands()
# assert False
# except ApiResponseError as api_response_error:
# assert api_response_error.code == 403

test.run(handle_connect)

Expand Down Expand Up @@ -223,7 +221,6 @@ def handle_connect(handler):
assert False
except DeviceError:
pass
# TODO: add http support after server response will be fixed.
if test.http_transport:
return
try:
Expand Down Expand Up @@ -255,12 +252,6 @@ def handle_connect(handler):
assert False
except DeviceError:
pass
# TODO: add after server response will be fixed.
# try:
# device_1.unsubscribe_update_commands()
# assert False
# except ApiResponseError as api_response_error:
# assert api_response_error.code == 403

test.run(handle_connect)

Expand Down Expand Up @@ -315,7 +306,12 @@ def handle_connect(handler):
device_1.list_commands()
assert False
except ApiResponseError as api_response_error:
assert api_response_error.code == 404
if test.admin_refresh_token:
assert api_response_error.code == 404
# TODO: uncomment after server response for ws for user token will
# be fixed
# else:
# assert api_response_error.code == 403

test.run(handle_connect)

Expand Down Expand Up @@ -366,9 +362,12 @@ def handle_connect(handler):
device_1.send_command(command_name)
assert False
except ApiResponseError as api_response_error:
# TODO: uncomment after server response will be fixed.
# assert api_response_error.code() == 404
pass
if test.admin_refresh_token:
assert api_response_error.code == 404
# TODO: uncomment after server response for ws for user token will
# be fixed
# else:
# assert api_response_error.code == 403

test.run(handle_connect)

Expand Down Expand Up @@ -437,7 +436,6 @@ def handle_connect(handler):
assert False
except DeviceError:
pass
# TODO: add http support after server response will be fixed.
if test.http_transport:
return
try:
Expand Down Expand Up @@ -469,12 +467,6 @@ def handle_connect(handler):
assert False
except DeviceError:
pass
# TODO: add after server response will be fixed.
# try:
# device_1.unsubscribe_notifications()
# assert False
# except ApiResponseError as api_response_error:
# assert api_response_error.code == 403

test.run(handle_connect)

Expand Down Expand Up @@ -537,7 +529,12 @@ def handle_connect(handler):
device_1.list_commands()
assert False
except ApiResponseError as api_response_error:
assert api_response_error.code == 404
if test.admin_refresh_token:
assert api_response_error.code == 404
# TODO: uncomment after server response for ws for user token will
# be fixed
# else:
# assert api_response_error.code == 403

test.run(handle_connect)

Expand Down Expand Up @@ -573,6 +570,11 @@ def handle_connect(handler):
device_1.send_notification(notification_name)
assert False
except ApiResponseError as api_response_error:
assert api_response_error.code == 404
if test.admin_refresh_token:
assert api_response_error.code == 404
# TODO: uncomment after server response for ws for user token will
# be fixed
# else:
# assert api_response_error.code == 403

test.run(handle_connect)
2 changes: 2 additions & 0 deletions tests/test_api_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def handle_connect(handler):
# assert api_response_error.code == 404
pass

test.only_admin_implementation()
test.run(handle_connect)


Expand All @@ -53,4 +54,5 @@ def handle_connect(handler):
except ApiResponseError as api_response_error:
assert api_response_error.code == 404

test.only_admin_implementation()
test.run(handle_connect)
Loading