(data_text, file_location, dataset_1_id, dataset_2_id)
| 12 | |
| 13 | |
| 14 | async 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 | |
| 53 | async def test_getting_of_documents(dataset_id_1): |
no test coverage detected