Skip to content

Commit

Permalink
Collection: Testing fixes due to stricted postgres requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel G. A. Smith committed Nov 6, 2019
1 parent f593241 commit 332192b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
7 changes: 4 additions & 3 deletions qcfractal/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion qcfractal/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
54 changes: 40 additions & 14 deletions qcfractal/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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'
Expand All @@ -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],
Expand All @@ -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
Expand All @@ -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": {},
}
}

Expand All @@ -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):
Expand Down Expand Up @@ -1301,20 +1311,36 @@ 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 = {
"collection": collection,
"name": name2,
"visibility": True,
"view_available": False,
"records": []
"records": [],
"group": "default"
}

ret = storage_socket.add_collection(db)
Expand Down

0 comments on commit 332192b

Please sign in to comment.