Skip to content
Snippets Groups Projects

F doc test registration

Merged Florian Spreckelsen requested to merge f-doc-test-registration into dev
All threads resolved!
2 files
+ 50
25
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -18,44 +18,62 @@
@@ -18,44 +18,62 @@
#
#
# You should have received a copy of the GNU Affero General Public License
# 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/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""This module implements a registration procedure for integration tests which
import linkahead as db
from linkahead import administration as admin
"""
This module implements a registration procedure for integration tests which
need a running LinkAhead instance.
need a running LinkAhead instance.
It ensures that tests do not accidentally overwrite data in real LinkAhead
It ensures that tests do not accidentally overwrite data in real
instances, as it checks whether the running LinkAhead instance is actually the
LinkAhead instances, as it checks whether the running LinkAhead
correct one, that
instance is actually the correct one, that should be used for these
should be used for these tests.
tests.
The test files have to define a global variable TEST_KEY which must be unique
for each test using
set_test_key("ABCDE")
The test files have to define a global variable ``TEST_KEY`` which
 
must be unique for each test using
 
:py:meth:`~linkahead.utils.register_tests.set_test_key`.
The test procedure (invoked by pytest) checks whether a registration
The test procedure (invoked by pytest) checks whether a registration
information is stored in one of the server properties or otherwise
information is stored in one of the server properties or otherwise
- offers to register this test in the currently running database ONLY if this
is empty.
- offers to register this test in the currently running database ONLY if this is
 
empty.
- fails otherwise with a RuntimeError
- fails otherwise with a RuntimeError
NOTE: you probably need to use pytest with the -s option to be able to
.. note::
register the test interactively. Otherwise, the server property has to be
set before server start-up in the server.conf of the LinkAhead server.
you probably need to use pytest with the -s option to be able to
 
register the test interactively. Otherwise, the server property
 
has to be set before server start-up in the server.conf of the
 
LinkAhead server.
This module is intended to be used with pytest.
This module is intended to be used with pytest.
There is a pytest fixture "clear_database" that performs the above mentioned
There is a pytest fixture
checks and clears the database in case of success.
:py:meth:`~linkahead.utils.register_tests.clear_database` that
 
performs the above mentioned checks and clears the database in case of
 
success.
 
"""
"""
 
import linkahead as db
 
from linkahead import administration as admin
 
TEST_KEY = None
TEST_KEY = None
def set_test_key(KEY):
def set_test_key(KEY: str):
 
"""Set the global ``TEST_KEY`` variable to `KEY`. Afterwards, if
 
`KEY` matches the ``_CAOSDB_INTEGRATION_TEST_SUITE_KEY`` server
 
environment variable, mehtods like :py:meth:`clear_database` can
 
be used. Call this function in the beginning of your test file.
 
 
Parameters
 
----------
 
KEY : str
 
key with which the test using this function is registered and
 
which is checked against the
 
``_CAOSDB_INTEGRATION_TEST_SUITE_KEY`` server environment
 
variable.
 
 
"""
global TEST_KEY
global TEST_KEY
TEST_KEY = KEY
TEST_KEY = KEY
@@ -122,10 +140,14 @@ try:
@@ -122,10 +140,14 @@ try:
@pytest.fixture
@pytest.fixture
def clear_database():
def clear_database():
"""Remove Records, RecordTypes, Properties, and Files ONLY IF the LinkAhead
"""Remove Records, RecordTypes, Properties, and Files ONLY IF
server the current connection points to was registered with the appropriate key.
the LinkAhead server the current connection points to was
 
registered with the appropriate key using
 
:py:meth:`set_test_key`.
 
 
PyTestInfo Records and the corresponding RecordType and
 
Property are preserved.
PyTestInfo Records and the corresponding RecordType and Property are preserved.
"""
"""
_assure_test_is_registered()
_assure_test_is_registered()
yield _clear_database() # called before the test function
yield _clear_database() # called before the test function
Loading