From 2d03a893d3b3db027d524938d6de3669c46303f0 Mon Sep 17 00:00:00 2001
From: vermeul <swen@ethz.ch>
Date: Wed, 20 Mar 2019 11:34:45 +0100
Subject: [PATCH] added server tests

---
 tests/conftest.py        | 43 ++++++++++++++++++++++++++++++++++++++++
 tests/test_connection.py |  8 ++++++++
 2 files changed, 51 insertions(+)
 create mode 100644 tests/conftest.py
 create mode 100644 tests/test_connection.py

diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..8704b2d
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,43 @@
+import pytest
+import time
+
+from pybis import Openbis
+
+openbis_url = 'https://localhost:8443'
+admin_username = 'admin'
+admin_password = 'changeit'
+
+@pytest.yield_fixture(scope="module")
+def openbis_instance():
+    instance = Openbis(url=openbis_url, verify_certificates=False)
+    print("\nLOGGING IN...")
+
+    timestamp = time.strftime('%a_%y%m%d_%H%M%S').upper()
+    space_code = 'test_space_' + timestamp
+    space = instance.new_space(code=space_code)
+    space.save()
+
+    project_code = "TEST-PROJECT-{:04d}".format(random.randint(0, 9999))
+    project = instance.new_project(code=project_code, space=space)
+    project.save()
+
+    experiment_code = "TEST-EXPERIMENT-{:04d}".format(random.randint(0, 9999))
+    experiment = instance.new_experiment(code=experiment_code, space=space, project=project)
+    experiment.save()
+
+    sample_code = "TEST-SAMPLE-{:04d}".format(random.randint(0, 9999))
+    sample = instance.new_sample(code=sample_code, space=space, project=project)
+    sample.save()
+
+    instance.login(admin_username, admin_password)
+
+    yield instance
+
+    # cleanup after tests have been running
+    sample.delete("test on {}".format(timestamp))
+    experiment.delete("test on {}".format(timestamp))
+    project.delete("test on {}".format(timestamp))
+    space.delete("test on {}".format(timestamp))
+    instance.logout()
+    print("LOGGED OUT...")
+
diff --git a/tests/test_connection.py b/tests/test_connection.py
new file mode 100644
index 0000000..c687d38
--- /dev/null
+++ b/tests/test_connection.py
@@ -0,0 +1,8 @@
+import pytest
+
+import importlib  
+jupyterserver = importlib.import_module("jupyter-openbis-extension")
+
+
+def test_conn():
+    pass    
-- 
GitLab