def test_molecules_add(storage_socket): water = portal.data.get_molecule("water_dimer_minima.psimol") # Add once ret1 = storage_socket.add_molecules({"new_water": water.to_json()}) assert ret1["meta"]["success"] is True assert ret1["meta"]["n_inserted"] == 1 # Try duplicate adds ret2 = storage_socket.add_molecules({"new_water2": water.to_json()}) assert ret2["meta"]["success"] is True assert ret2["meta"]["n_inserted"] == 0 assert ret2["meta"]["duplicates"][0] == "new_water2" # Assert the ids match assert ret1["data"]["new_water"] == ret2["data"]["new_water2"] # Pull molecule from the DB for tests db_json = storage_socket.get_molecules(water.get_hash(), index="hash")["data"][0] water.compare(db_json) # Cleanup adds ret = storage_socket.del_molecules(water.get_hash(), index="hash") assert ret == 1
def test_molecules_get(storage_socket): water = portal.data.get_molecule("water_dimer_minima.psimol") # Add once ret = storage_socket.add_molecules({"water": water.to_json()}) assert ret["meta"]["n_inserted"] == 1 water_id = ret["data"]["water"] # Pull molecule from the DB for tests db_json = storage_socket.get_molecules(water_id, index="id")["data"][0] water_db = portal.Molecule.from_json(db_json) water_db.compare(water) # Cleanup adds ret = storage_socket.del_molecules(water_id, index="id") assert ret == 1
def test_molecules_bad_get(storage_socket): water = portal.data.get_molecule("water_dimer_minima.psimol") # Add once ret = storage_socket.add_molecules({"water": water.to_json()}) assert ret["meta"]["n_inserted"] == 1 water_id = ret["data"]["water"] # Pull molecule from the DB for tests ret = storage_socket.get_molecules([water_id, "something", 5, (3, 2)], index="id") assert len(ret["meta"]["errors"]) == 1 assert ret["meta"]["errors"][0][0] == "Bad Ids" assert len(ret["meta"]["errors"][0][1]) == 3 assert ret["meta"]["n_found"] == 1 # Cleanup adds ret = storage_socket.del_molecules(water_id, index="id") assert ret == 1
def test_identical_mol_insert(storage_socket): """ Tests as edge case where to identical molecules are added under different tags. """ water = portal.data.get_molecule("water_dimer_minima.psimol") # Add two idential molecules ret1 = storage_socket.add_molecules({"w1": water.to_json(), "w2": water.to_json()}) assert ret1["meta"]["success"] is True assert ret1["meta"]["n_inserted"] == 1 assert ret1["data"]["w1"] == ret1["data"]["w2"] # Should only find one molecule ret2 = storage_socket.get_molecules([water.get_hash()], index="hash") assert ret2["meta"]["n_found"] == 1 ret = storage_socket.del_molecules(water.get_hash(), index="hash") assert ret == 1