From 7d895edf28e28c070f4b80ca48d9e48bbcacfbdc Mon Sep 17 00:00:00 2001
From: Alexander Schlemmer <alexander@mail-schlemmer.de>
Date: Mon, 2 May 2022 12:14:44 +0200
Subject: [PATCH] TST: created pytest file

---
 integrationtests/.pycaosdb.ini                | 13 +++
 integrationtests/test-profile/profile.yml     |  5 +-
 .../test_use_case_cardiac_simulations.py      | 89 +++++++++++++++++++
 .../use_case_cardiac_simulation/crawl_data.sh |  2 +-
 .../insert_data_model.py                      |  4 -
 5 files changed, 105 insertions(+), 8 deletions(-)
 create mode 100644 integrationtests/.pycaosdb.ini
 create mode 100644 integrationtests/test_use_case_cardiac_simulations.py

diff --git a/integrationtests/.pycaosdb.ini b/integrationtests/.pycaosdb.ini
new file mode 100644
index 00000000..4958eb59
--- /dev/null
+++ b/integrationtests/.pycaosdb.ini
@@ -0,0 +1,13 @@
+[Connection]
+ssl_insecure=false
+url=https://localhost:10443/
+password=caosdb
+username=admin
+password_method=plain
+cacert=/home/salexan/Projekte/2022/220309_DPGErlangenHackathon/live/live-profile/custom/other/cert/caosdb.cert.pem
+
+timeout=10000
+debug=0
+
+[Container]
+debug=0
diff --git a/integrationtests/test-profile/profile.yml b/integrationtests/test-profile/profile.yml
index 4cbbe28c..cafe041c 100644
--- a/integrationtests/test-profile/profile.yml
+++ b/integrationtests/test-profile/profile.yml
@@ -21,9 +21,8 @@ default:
     # extroot: From where files are copied/symlinked.  This is a
     # list of `NAME: PATH` pairs or a single path.  
     extroot:
-      "": "paths/extroot"
-    #
-    #  "base": "/path/to/base/dir"
+    #  "": "paths/extroot"
+      "base": "../use_case_cardiac_simulation/extroot"
     #  "other": "/path/to/other"
     #
     # dropoffbox: (Soon to be deprecated.) Files can be written here, but note that you may need to
diff --git a/integrationtests/test_use_case_cardiac_simulations.py b/integrationtests/test_use_case_cardiac_simulations.py
new file mode 100644
index 00000000..a15b06c1
--- /dev/null
+++ b/integrationtests/test_use_case_cardiac_simulations.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python3
+# encoding: utf-8
+#
+# ** header v3.0
+# This file is a part of the CaosDB Project.
+#
+# Copyright (C) 2021 Indiscale GmbH <info@indiscale.com>
+#               2021 Henrik tom Wörden <h.tomwoerden@indiscale.com>
+#               2021 Alexander Schlemmer
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+# ** end header
+#
+
+"""
+module description
+"""
+
+from caosdb import EmptyUniqueQueryError
+import argparse
+import sys
+from argparse import RawTextHelpFormatter
+from newcrawler import Crawler
+import caosdb as db
+from newcrawler.identifiable_adapters import CaosDBIdentifiableAdapter
+import pytest
+from caosadvancedtools.models.parser import parse_model_from_yaml
+from caosadvancedtools.models import parser as parser
+import yaml
+
+from caosadvancedtools.loadFiles import loadpath
+
+from subprocess import run
+
+from caosadvancedtools.testutils import clear_database, set_test_key
+set_test_key("10b128cf8a1372f30aa3697466bb55e76974e0c16a599bb44ace88f19c8f61e2")
+
+import os
+
+def rfp(*pathcomponents):
+    """
+    Return full path.
+    Shorthand convenience function.
+    """
+    return os.path.join(os.path.dirname(__file__), *pathcomponents)
+
+
+def test_complete_crawler(clear_database):
+    # Setup the data model:
+    model = parser.parse_model_from_yaml("use_case_cardiac_simulation/model.yml")
+    model.sync_data_model(noquestion=True, verbose=False)
+
+    # Insert the data:
+    for path in [
+            "/opt/caosdb/mnt/extroot/base/SimulationData",
+            "/opt/caosdb/mnt/extroot/base/DataAnalysis"]:
+        loadpath(
+            path=path,
+            include=None,
+            exclude=None,
+            prefix="/",
+            dryrun=False,
+            forceAllowSymlinks=False)
+
+    # Run the crawler:
+    run([
+        "crawler2.0",
+        "--debug",
+        '--load-identifiables=identifiables.yml',
+        "-s",
+        "--provenance=provenance.yml",
+        "simulation_cfood_baltasar.yml",
+        "extroot/"], cwd="use_case_cardiac_simulation",
+        check=True)
+
+    res = db.execute_query("FIND Record MonodomainTissueSimulationRun")
+    assert len(res) > 0
diff --git a/integrationtests/use_case_cardiac_simulation/crawl_data.sh b/integrationtests/use_case_cardiac_simulation/crawl_data.sh
index 01e28a09..af2e8f92 100755
--- a/integrationtests/use_case_cardiac_simulation/crawl_data.sh
+++ b/integrationtests/use_case_cardiac_simulation/crawl_data.sh
@@ -2,4 +2,4 @@
 # Run the crawler2.0 to test the data structure
 # A. Schlemmer, 03/2022
 
-crawler2.0 --debug --load-identifiables="identifiables.yml" -s --provenance=provenance.yml simulation_cfood_baltasar.yml ../../extroot/
+crawler2.0 --debug --load-identifiables="identifiables.yml" -s --provenance=provenance.yml simulation_cfood_baltasar.yml extroot/
diff --git a/integrationtests/use_case_cardiac_simulation/insert_data_model.py b/integrationtests/use_case_cardiac_simulation/insert_data_model.py
index 13382999..e3302073 100755
--- a/integrationtests/use_case_cardiac_simulation/insert_data_model.py
+++ b/integrationtests/use_case_cardiac_simulation/insert_data_model.py
@@ -2,7 +2,3 @@
 # Insert the data model using the yaml interface
 # A. Schlemmer, 02/2022
 
-from caosadvancedtools.models import parser as parser
-
-model = parser.parse_model_from_yaml("model.yml")
-model.sync_data_model()
-- 
GitLab