ENH: new module which allows to register integration tests in caosdb instances
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.
Merge request reports
Activity
assigned to @salexan
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)]) added 1 commit
- fe111723 - FIX: refactored usage of global variables and rfp function
added 97 commits
-
fe111723...69596c39 - 96 commits from branch
dev
- 4b6a8bb9 - Merge branch 'dev' into f-register-integrationtests
-
fe111723...69596c39 - 96 commits from branch
mentioned in issue #81 (closed)
added 34 commits
-
5b29ad90...f1f68ae6 - 33 commits from branch
dev
- 98b4c69f - Merge branch 'dev' into f-register-integrationtests
-
5b29ad90...f1f68ae6 - 33 commits from branch
assigned to @henrik
mentioned in issue #91 (closed)
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): requested review from @timm
added 16 commits
-
0d5502df...6de42175 - 15 commits from branch
dev
- 25c57c57 - Merge branch 'dev' into f-register-integrationtests
-
0d5502df...6de42175 - 15 commits from branch