Skip to content
Snippets Groups Projects

ENH: new module which allows to register integration tests in caosdb instances

Closed Alexander Schlemmer requested to merge f-register-integrationtests into dev
4 unresolved threads

Summary

This is a proposal for an API to register integration tests.

Please see the documentation of register_tests.py for detailed information.

The API and its purpose is open for discussion and in principle open for changes and suggestions.

Related issue: https://gitlab.indiscale.com/caosdb/src/crawler2.0/-/issues/3 (maybe wrong place, but it came up during development of the new crawler framework)

Test Environment

Run an empty CaosDB instance and create a test file that uses the @pytest.fixture clear_database.

Also see documentation of the register_tests module and be careful with the CaosDB instance, as the fixture is intended to wipe a CaosDB instance.

Please test the behavior of the API for:

  • an empty database
  • a database with a registration with an unmatching KEY
  • a database with a registration with a matching KEY
  • a non-empty (test!) database without registration

Check List for the Author

Please, prepare your MR for a review. Be sure to write a summary and a focus and create gitlab comments for the reviewer. They should guide the reviewer through the changes, explain your changes and also point out open questions. For further good practices have a look at our review guidelines

  • All automated tests pass
  • Reference related Issues
  • Up-to-date CHANGELOG.md
  • Annotations in code (Gitlab comments)
    • Intent of new code
    • Problems with old code
    • Why this implementation?

Check List for the Reviewer

  • I understand the intent of this MR
  • All automated tests pass
  • Up-to-date CHANGELOG.md
  • The test environment setup works and the intended behavior is reproducible in the test environment
  • In-code documentation and comments are up-to-date.
  • Check: Are there spezifications? Are they satisfied?

For further good practices have a look at our review guidelines.

Edited by Timm Fitschen

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
58 try:
59 TEST_KEY
60 except NameError:
61 raise RuntimeError("TEST_KEY is not defined.")
62
63 def not_test_record(r: db.Record):
64 global TEST_KEY
65 if r.name == "PyTestInfo" or r.name == "TestIdentification":
66 return False
67 if r.get_property("TestIdentification") is not None:
68 if (r.get_property("TestIdentification").value ==
69 TEST_KEY):
70 return False
71 return True
72
73 def register_test():
  • 68 if (r.get_property("TestIdentification").value ==
    69 TEST_KEY):
    70 return False
    71 return True
    72
    73 def register_test():
    74 res = db.execute_query("COUNT Entity")
    75 if not isinstance(res, int):
    76 raise RuntimeError("Response from server for Info could not be interpreted.")
    77 if res > 0:
    78 raise RuntimeError("This instance of CaosDB contains entities already."
    79 "It must be empty in order to gegister a new test.")
    80
    81 print("Current host of CaosDB instance is: {}".format(
    82 db.connection.connection.get_connection()._delegate_connection.setup_fields["host"]))
    83 answer = input("This method will register your current test with key {} with the currently"
  • 108 answer = input("Do you want to register this instance of CaosDB"
    109 " with the current test? Do you want to continue (y/N)?")
    110 if answer == "y":
    111 register_test()
    112 raise RuntimeError("Test has been registered. Please rerun tests.")
    113 else:
    114 raise RuntimeError("The database has not been setup for this test.")
    115 if test_record.get_property("TestIdentification").value != TEST_KEY:
    116 raise RuntimeError("The database has been setup for a different test.")
    117
    118 c = db.execute_query("FIND Record")
    119 c.extend(db.execute_query("FIND RecordType"))
    120 c.extend(db.execute_query("FIND Property"))
    121 c.extend(db.execute_query("FIND File"))
    122
    123 c = db.Container().extend([r for r in c if not_test_record(r)])
  • Alexander Schlemmer marked the checklist item Annotations in code (Gitlab comments) as completed

    marked the checklist item Annotations in code (Gitlab comments) as completed

  • added 1 commit

    • fe111723 - FIX: refactored usage of global variables and rfp function

    Compare with previous version

  • added 97 commits

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • Alexander Schlemmer marked the checklist item All automated tests pass as completed

    marked the checklist item All automated tests pass as completed

  • mentioned in issue #81 (closed)

  • added 34 commits

    Compare with previous version

  • added 1 commit

    • ceeb48de - MAINT: minor refactoring and documentation

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • mentioned in issue #91 (closed)

  • added 2 commits

    • ea8a9b2b - Merge branch 'dev' into f-register-integrationtests
    • 5c3d1579 - Merge branch 'f-register-integrationtests' of...

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • Alexander Schlemmer
    Alexander Schlemmer @salexan started a thread on commit ceeb48de
  • 58 58
    59 def rfp(*pathcomponents):
    60 """
    61 Return full path.
    62 Shorthand convenience function.
    63 """
    64 return os.path.join(os.path.dirname(__file__), *pathcomponents)
    65
    66
    67 59 def set_test_key(KEY):
    68 60 global TEST_KEY
    69 61 TEST_KEY = KEY
    70 62
    71 63
    72 def not_test_record(r: db.Record):
    64 def belongs_to_test_identification(r: db.Record):
  • Timm Fitschen marked the checklist item I understand the intent of this MR as completed

    marked the checklist item I understand the intent of this MR as completed

  • Timm Fitschen marked the checklist item Up-to-date CHANGELOG.md as completed

    marked the checklist item Up-to-date CHANGELOG.md as completed

  • Timm Fitschen requested review from @timm

    requested review from @timm

  • Timm Fitschen added 16 commits

    added 16 commits

    Compare with previous version

  • Rejected, code moved to caosdb-pylib.

  • closed

  • Please register or sign in to reply
    Loading