From 332192bf4e68444607ae46f36c0870070fa9c95a Mon Sep 17 00:00:00 2001 From: "Daniel G. A. Smith" Date: Wed, 6 Nov 2019 14:23:46 -0500 Subject: [PATCH] Collection: Testing fixes due to stricted postgres requirements --- qcfractal/tests/test_client.py | 7 +++-- qcfractal/tests/test_server.py | 2 +- qcfractal/tests/test_storage.py | 54 ++++++++++++++++++++++++--------- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/qcfractal/tests/test_client.py b/qcfractal/tests/test_client.py index 3bff8fcfc..2214011ba 100644 --- a/qcfractal/tests/test_client.py +++ b/qcfractal/tests/test_client.py @@ -101,14 +101,16 @@ def test_collection_portal(test_server, encoding): "something": "else", "array": ["12345"], "visibility": True, - "view_available": False + "view_available": False, + "group": "default" } client = ptl.FractalClient(test_server) client._set_encoding(encoding) # Test add - _ = client.add_collection(db) + ret = client.add_collection(db, full_return=True) + print(ret) # Test get get_db = client.get_collection(db["collection"], db["name"], full_return=True) @@ -121,7 +123,6 @@ def test_collection_portal(test_server, encoding): get_db.data[0].pop("view_url_hdf5", None) get_db.data[0].pop("view_url_plaintext", None) get_db.data[0].pop("view_metadata", None) - get_db.data[0].pop("group", None) get_db.data[0].pop("description", None) assert db == get_db.data[0] diff --git a/qcfractal/tests/test_server.py b/qcfractal/tests/test_server.py index 711c537c4..c774e9847 100644 --- a/qcfractal/tests/test_server.py +++ b/qcfractal/tests/test_server.py @@ -36,6 +36,7 @@ def test_storage_socket(test_server): "array": ["54321"], "visibility": True, "view_available": False, + "group": "default", } # Cast collection type to lower since the server-side does it anyways storage['collection'] = storage['collection'].lower() @@ -67,7 +68,6 @@ def test_storage_socket(test_server): pdata["data"][0].pop("view_url_hdf5", None) pdata["data"][0].pop("view_url_plaintext", None) pdata["data"][0].pop("view_metadata", None) - pdata["data"][0].pop("group", None) pdata["data"][0].pop("description", None) assert pdata["data"][0] == storage diff --git a/qcfractal/tests/test_storage.py b/qcfractal/tests/test_storage.py index d6606b6c2..07589d195 100644 --- a/qcfractal/tests/test_storage.py +++ b/qcfractal/tests/test_storage.py @@ -219,7 +219,8 @@ def test_collections_add(storage_socket): "something": "else", "array": ["54321"], "visibility": True, - "view_available": False + "view_available": False, + "group": "default", } ret = storage_socket.add_collection(db) @@ -239,6 +240,7 @@ def test_collections_add(storage_socket): # assert len(ret["meta"]["missing"]) == 1 assert ret["meta"]["n_found"] == 0 + def test_collections_overwrite(storage_socket): collection = 'TorsionDriveRecord' @@ -249,7 +251,8 @@ def test_collections_overwrite(storage_socket): "something": "else", "array": ["54321"], "visibility": True, - "view_available": False + "view_available": False, + "group": "default", } ret = storage_socket.add_collection(db) @@ -264,6 +267,7 @@ def test_collections_overwrite(storage_socket): # "id": ret["data"][0]["id"], "collection": "TorsionDriveRecord", # no need to include "name": "Torsion123", # no need to include + "group": "default", "something": "New", "something2": "else", "view_available": True, @@ -290,6 +294,7 @@ def test_collections_overwrite(storage_socket): ret = storage_socket.del_collection(collection, name) assert ret == 1 + def test_dataset_add_delete_cascade(storage_socket): collection = 'dataset' @@ -311,6 +316,8 @@ def test_dataset_add_delete_cascade(storage_socket): True, "view_available": False, + "group": + "default", "records": [{ "name": "He1", "molecule_id": mol_insert["data"][0], @@ -328,13 +335,15 @@ def test_dataset_add_delete_cascade(storage_socket): "theory_level": 'PBE0', "units": 'kcal/mol', "values": [5, 10], - "index": ["He2", "He1"] + "index": ["He2", "He1"], + "values_structure": {}, } } } ret = storage_socket.add_collection(db.copy()) - assert ret["meta"]["n_inserted"] == 1 + print(ret["meta"]["error_description"]) + assert ret["meta"]["n_inserted"] == 1, ret["meta"]["error_description"] ret = storage_socket.get_collections(collection=collection, name=name) assert ret["meta"]["success"] is True @@ -349,14 +358,16 @@ def test_dataset_add_delete_cascade(storage_socket): "theory_level": 'PBE0 FHI-AIMS', "units": 'kcal/mol', "values": np.array([5, 10], dtype=np.int16), - "index": ["He2", "He1"] + "index": ["He2", "He1"], + "values_structure": {}, }, 'contrib2': { "name": 'contrib2', "theory_level": 'PBE0 FHI-AIMS tight', "units": 'kcal/mol', "values": [np.random.rand(2, 3), np.random.rand(2, 3)], - "index": ["He2", "He1"] + "index": ["He2", "He1"], + "values_structure": {}, } } @@ -381,7 +392,6 @@ def test_dataset_add_delete_cascade(storage_socket): assert len(ret['data'][0]['contributed_values'].keys()) == 2 assert len(ret['data'][0]['records']) == 0 - # cleanup # Can't delete molecule when datasets refernece it (no cascade) with pytest.raises(sqlalchemy.exc.IntegrityError): @@ -1301,12 +1311,27 @@ def test_collections_include_exclude(storage_socket): mol_insert = storage_socket.add_molecules([water, water2]) db = { - "collection": collection, - "name": name, - "visibility": True, - "view_available": False, - "records": [{"name": "He1", "molecule_id": mol_insert["data"][0], "comment": None, "local_results": {}}, - {"name": "He2", "molecule_id": mol_insert["data"][1], "comment": None, "local_results": {}}] + "collection": + collection, + "name": + name, + "visibility": + True, + "view_available": + False, + "group": + "default", + "records": [{ + "name": "He1", + "molecule_id": mol_insert["data"][0], + "comment": None, + "local_results": {} + }, { + "name": "He2", + "molecule_id": mol_insert["data"][1], + "comment": None, + "local_results": {} + }] } db2 = { @@ -1314,7 +1339,8 @@ def test_collections_include_exclude(storage_socket): "name": name2, "visibility": True, "view_available": False, - "records": [] + "records": [], + "group": "default" } ret = storage_socket.add_collection(db)