Skip to content

Commit

Permalink
Add connection tagging support
Browse files Browse the repository at this point in the history
Added generic test config
Added some new tests for connection tagging
  • Loading branch information
Jyrno42 committed Oct 1, 2014
1 parent 9f260dd commit c56f5d7
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 22 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@ coverage.xml
# Sphinx documentation
docs/_build/

# Test Certificate
test_cert.pfx
# Test Certificates
certs/*

# Local Test config
lvis_test_config/local.py
2 changes: 1 addition & 1 deletion elvis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '0.0.10'
__version__ = '0.1.0'
__all__ = ['api', 'enums', 'models']
15 changes: 13 additions & 2 deletions elvis/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,14 @@ def server_info(self):
else:
raise ElvisException("Server information not available, it was added in proxy version 1.1.*", raw=result)

def authorize(self):
def authorize(self, session_tag='default'):
assert self.certificate, "Certificate must be provided"

result = self.__request("Authorize", "POST", {
'code': self.person_code,
'certificateData': self.certificate,
'password': self.certificate_password
'password': self.certificate_password,
'connectionTag': session_tag,
})

if result["Success"] and result["raw"].get("AuthorizeResult", None) and result['raw']['AuthorizeResult'].get('Success'):
Expand All @@ -155,6 +156,16 @@ def authorize(self):
else:
raise ElvisException("Authorization failed:", result)

def get_session_tag(self):
assert self.session_token, "No valid session available"

result = self.__request("getSessionTag", "GET", {})

if result["Success"]:
return result["raw"]['getSessionTagResult']
else:
raise ElvisException(result['message'], result['raw'])

def get_assortment_types(self, assortment_type=AssortmentType.ELVIS):
assert self.session_token, "No valid session available"
assert assortment_type in [AssortmentType.ELVIS, AssortmentType.COMPANY], "Invalid assortment type"
Expand Down
7 changes: 7 additions & 0 deletions lvis_test_config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import sys

try:
from .local import *
except ImportError:
sys.stderr.write("Couldn't import lvis_test_config.local, have you created it from lvis_test_config/local.py.example?\n")
sys.exit(1)
6 changes: 6 additions & 0 deletions lvis_test_config/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

TEST_LEVEL_ASSORTMENTS = 1
TEST_LEVEL_WAREHOUSE = 2
TEST_LEVEL_WAYBILL = 3

TEST_ALL = True
7 changes: 7 additions & 0 deletions lvis_test_config/local.py.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
PROXY_HOST_URL = "http://54.194.211.213:9500/%s"

TEST_CERTIFICATE_PATH = "test_cert.pfx"
TEST_CERTIFICATE_PERSON_CODE = "00000000000"
TEST_CERTIFICATE_PASSWORD = "test"

TESTING_RANGE = TEST_ALL # Valid values are a list of test types (see base.py), TEST_ALL, or None for no extra tests.
76 changes: 59 additions & 17 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
Warehouse, AdditionalProperty, TimberOwner, AuthorizedPerson, TimberReceiverDestination, TimberReceiver,
WaybillTransporter, Transport, Person, Vehicle, Waybill)

import lvis_test_config


class ElvisProxyTest(object):

def __init__(self):
self.file_path = "test_cert.pfx"
self.file_path = lvis_test_config.TEST_CERTIFICATE_PATH

self.client = ElvisClient("http://54.194.211.213:9500/%s", "00000000000", certificate_pass='test')
self.client = ElvisClient(lvis_test_config.PROXY_HOST_URL, lvis_test_config.TEST_CERTIFICATE_PERSON_CODE,
certificate_pass=lvis_test_config.TEST_CERTIFICATE_PASSWORD)
self.client.load_cert_from_file(self.file_path)

self.warehouse_id = None
Expand All @@ -27,6 +30,31 @@ def test_authorize(self):
assert self.client.authorize()
print("Ühenduse loomine õnnestus")

def test_get_session_tag(self):
print("Ühenduse sildi kontrollimine")

original_token = self.client.session_token

tag = self.client.get_session_tag()
print(' Vaikimisi silt: %s - %s' % (tag, original_token))
assert tag == 'default'
print(' Vaikimisi silt on korrektne')

print(" Valikulise sildi testimine: 'testing'")
assert self.client.authorize('testing')

tag = self.client.get_session_tag()
new_token = self.client.session_token

print(' Valikuline silt: %s - %s' % (tag, new_token))
assert tag == 'testing'
print(' Valikuline silt on korrektne')

assert new_token != original_token
print(' %s != %s: Success' % (original_token, new_token))

print("Ühenduse sildi kontrollimine õnnestus")

def test_assortment_types(self):
print("Sortimendi tüüpide pärimine (elvise omad) ...")

Expand Down Expand Up @@ -376,20 +404,34 @@ def test_search_waybills(self):

# Start tests
test.test_authorize()

test.test_assortment_types()
test.test_assortment_types_company()

test.test_add_warehouse()
test.test_get_warehouse()
test.test_search_warehouse()
test.test_delete_warehouse()

test.test_insert_waybill()
test.test_get_waybill()
test.test_set_waybill_status()
test.test_get_waybill_status()

test.test_search_waybills()
test.test_get_session_tag()

if lvis_test_config.TESTING_RANGE:
all_tests = lvis_test_config.TESTING_RANGE is True
if not all_tests:
if not isinstance(lvis_test_config.TESTING_RANGE, (list, tuple)):
raise ValueError('TESTING RANGE MUST BE True or a list/tuple typed value')

if all_tests or lvis_test_config.TEST_LEVEL_ASSORTMENTS in lvis_test_config.TESTING_RANGE:
print('Testing assortments')
test.test_assortment_types()
test.test_assortment_types_company()

if all_tests or lvis_test_config.TEST_LEVEL_WAREHOUSE in lvis_test_config.TESTING_RANGE:
print('Testing warehouses')
test.test_add_warehouse()
test.test_get_warehouse()
test.test_search_warehouse()
test.test_delete_warehouse()

if all_tests or lvis_test_config.TEST_LEVEL_WAYBILL in lvis_test_config.TESTING_RANGE:
print('Testing waybills')

test.test_insert_waybill()
test.test_get_waybill()
test.test_set_waybill_status()
test.test_get_waybill_status()

test.test_search_waybills()

print("Testi lõpp!")

0 comments on commit c56f5d7

Please sign in to comment.