summaryrefslogtreecommitdiff
path: root/unittest/conftest.py
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2019-01-15 14:48:02 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2019-01-15 14:48:02 +0100
commit4078bf60135e9ad161eefa775e90dca3cced2730 (patch)
treeb0ca724e3b161507e65969fabd35ceaa7105e176 /unittest/conftest.py
parentc284da21d2eb9e9cbdc30cd82e9dd46ea4528683 (diff)
downloadlibnitrokey-4078bf60135e9ad161eefa775e90dca3cced2730.tar.gz
libnitrokey-4078bf60135e9ad161eefa775e90dca3cced2730.tar.bz2
Add Python offline tests
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'unittest/conftest.py')
-rw-r--r--unittest/conftest.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/unittest/conftest.py b/unittest/conftest.py
index ba21a38..a9f46c6 100644
--- a/unittest/conftest.py
+++ b/unittest/conftest.py
@@ -67,7 +67,18 @@ class AttrProxy(object):
@pytest.fixture(scope="module")
+def C_offline(request=None):
+ print("Getting library without initializing connection")
+ return get_library(request, allow_offline=True)
+
+
+@pytest.fixture(scope="module")
def C(request=None):
+ print("Getting library with connection initialized")
+ return get_library(request)
+
+
+def get_library(request, allow_offline=False):
fp = '../NK_C_API.h'
declarations = []
@@ -115,12 +126,13 @@ def C(request=None):
nk_login = C.NK_login_auto()
if nk_login != 1:
print('No devices detected!')
- assert nk_login != 0 # returns 0 if not connected or wrong model or 1 when connected
- global device_type
- firmware_version = C.NK_get_minor_firmware_version()
- model = 'P' if firmware_version < 20 else 'S'
- device_type = (model, firmware_version)
- print('Connected device: {} {}'.format(model, firmware_version))
+ if not allow_offline:
+ assert nk_login != 0 # returns 0 if not connected or wrong model or 1 when connected
+ global device_type
+ firmware_version = C.NK_get_minor_firmware_version()
+ model = 'P' if firmware_version < 20 else 'S'
+ device_type = (model, firmware_version)
+ print('Connected device: {} {}'.format(model, firmware_version))
# assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK
# assert C.NK_user_authenticate(DefaultPasswords.USER, DefaultPasswords.USER_TEMP) == DeviceErrorCode.STATUS_OK