MCPcopy
hub / github.com/topoteretes/cognee / test_local_file_deletion

Function test_local_file_deletion

cognee/tests/test_pgvector.py:14–50  ·  view source on GitHub ↗
(data_text, file_location, dataset_1_id, dataset_2_id)

Source from the content-addressed store, hash-verified

12
13
14async def test_local_file_deletion(data_text, file_location, dataset_1_id, dataset_2_id):
15 from sqlalchemy import select
16 import hashlib
17 from cognee.infrastructure.databases.relational import get_relational_engine
18
19 engine = get_relational_engine()
20
21 async with engine.get_async_session() as session:
22 # Get hash of data contents
23 encoded_text = data_text.encode("utf-8")
24 data_hash = hashlib.md5(encoded_text).hexdigest()
25 # Get data entry from database based on hash contents
26 data = (await session.scalars(select(Data).where(Data.content_hash == data_hash))).one()
27 assert os.path.isfile(data.raw_data_location.replace("file://", "")), (
28 f"Data location doesn't exist: {data.raw_data_location}"
29 )
30 # Test deletion of data along with local files created by cognee
31 await engine.delete_data_entity(data.id, dataset_id=dataset_2_id)
32 assert not os.path.exists(data.raw_data_location.replace("file://", "")), (
33 f"Data location still exists after deletion: {data.raw_data_location}"
34 )
35
36 async with engine.get_async_session() as session:
37 # Get data entry from database based on file path
38 data = (
39 await session.scalars(
40 select(Data).where(Data.original_data_location == "file://" + file_location)
41 )
42 ).one()
43 assert os.path.isfile(data.original_data_location.replace("file://", "")), (
44 f"Data location doesn't exist: {data.original_data_location}"
45 )
46 # Test local files not created by cognee won't get deleted
47 await engine.delete_data_entity(data.id, dataset_id=dataset_1_id)
48 assert os.path.exists(data.original_data_location.replace("file://", "")), (
49 f"Data location doesn't exists: {data.original_data_location}"
50 )
51
52
53async def test_getting_of_documents(dataset_id_1):

Callers 1

mainFunction · 0.70

Calls 6

get_relational_engineFunction · 0.90
selectFunction · 0.85
delete_data_entityMethod · 0.80
get_async_sessionMethod · 0.45
scalarsMethod · 0.45
whereMethod · 0.45

Tested by

no test coverage detected