From 0d20f45bfe7f51e91070d72a5272bda6d154645f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <henrik@trineo.org>
Date: Thu, 14 Oct 2021 15:37:25 +0200
Subject: [PATCH] MAINT: further tests and docs

---
 CHANGELOG.md                     | 1 +
 integrationtests/insert_model.py | 4 ++++
 integrationtests/model.yml       | 3 +++
 src/doc/yaml_interface.rst       | 8 ++++++++
 4 files changed, 16 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3a0d6cc5..627ee4e4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
   h5py is now an optional dependency
 - table importer implementations for csv and tsv
 - string-in-list check for table imports
+- Documentation and test for the `extern` keyword used by the YAML interface
 
 ### Changed ###
 
diff --git a/integrationtests/insert_model.py b/integrationtests/insert_model.py
index ae3dd770..d793b041 100755
--- a/integrationtests/insert_model.py
+++ b/integrationtests/insert_model.py
@@ -5,6 +5,10 @@ from caosadvancedtools.cfoods.h5 import H5CFood
 from caosadvancedtools.models.data_model import DataModel
 from caosadvancedtools.models.parser import parse_model_from_yaml
 
+# for teseting existing data model parts for the YANL Interface
+db.RecordType(name="TestRT1", datatype=db.TEXT).insert()
+db.Property(name="TestP1", datatype=db.TEXT).insert()
+
 model = parse_model_from_yaml("model.yml")
 model.sync_data_model(noquestion=True)
 
diff --git a/integrationtests/model.yml b/integrationtests/model.yml
index e1753a9f..cad79588 100644
--- a/integrationtests/model.yml
+++ b/integrationtests/model.yml
@@ -69,3 +69,6 @@ Report:
   - Publication
 hdf5File:
   datatype: REFERENCE
+extern:
+  - TestRT1
+  - TestP1
diff --git a/src/doc/yaml_interface.rst b/src/doc/yaml_interface.rst
index 06248f2b..dcf4c5d6 100644
--- a/src/doc/yaml_interface.rst
+++ b/src/doc/yaml_interface.rst
@@ -39,6 +39,9 @@ Let's start with an example taken from https://gitlab.indiscale.com/caosdb/src/c
           table:
              datatype: FILE
              description: 'A table document associated with this recording'
+    extern:
+       - Textfile
+
 
 
 This example defines 3 ``RecordType``s:
@@ -46,6 +49,9 @@ This example defines 3 ``RecordType``s:
 - A ``Project`` with one obligatory property ``datatype``
 - A Person with a ``firstName`` and a ``lastName`` (as recommended properties)
 - A ``LabbookEntry`` with multiple recommended properties of different data types
+- It is assumed that the server knows a RecordType or Property with the name 
+  "Textfile".
+
 
 One major advantage of using this interface (in contrast to the standard python interface) is that properties can be defined and added to record types "on-the-fly". E.g. the three lines for ``firstName`` as sub entries of ``Person`` have two effects on CaosDB:
 
@@ -60,6 +66,8 @@ Note the difference between the three property declarations of ``LabbookEntry``:
 - ``responsible``: This defines and adds a property with name "responsible" to ``LabbookEntry`, which has a datatype ``Person``. ``Person`` is defined above.
 - ``firstName``: This defines and adds a property with the standard data type ``TEXT`` to record type ``Person``.
 
+If the data model depends on already existing parts, those can be added using the ``extern`` keyword.
+
 Datatypes
 ---------
 
-- 
GitLab