Move cognee_db for integration test
This commit is contained in:
parent
c42bb510c8
commit
adbf3df4e0
7 changed files with 13 additions and 70 deletions
Binary file not shown.
10
cognee/tests/integration/run_toy_tasks/conftest.py
Normal file
10
cognee/tests/integration/run_toy_tasks/conftest.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
import os
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="session")
|
||||
def copy_cognee_db_to_target_location():
|
||||
|
||||
os.system
|
||||
yield
|
||||
0
cognee/tests/integration/run_toy_tasks/data/cognee_db
Normal file
0
cognee/tests/integration/run_toy_tasks/data/cognee_db
Normal file
|
|
@ -5,7 +5,6 @@ from unittest.mock import patch
|
|||
from cognee.modules.pipelines.operations.run_tasks import run_tasks
|
||||
from cognee.modules.pipelines.tasks.Task import Task
|
||||
from cognee.modules.users.methods.get_default_user import get_default_user
|
||||
from cognee.tests.unit.utils.get_mock_user import get_mock_user
|
||||
|
||||
|
||||
async def run_and_check_tasks():
|
||||
|
|
@ -1,28 +1,7 @@
|
|||
import sys
|
||||
import warnings
|
||||
from unittest.mock import patch
|
||||
|
||||
import os
|
||||
import pytest
|
||||
|
||||
from cognee.modules.users.methods.get_default_user import get_default_user
|
||||
from cognee.tests.unit.utils.get_mock_user import get_mock_user
|
||||
|
||||
|
||||
def apply_with_to_item(module_items, fn, fn_str):
|
||||
for i, (name, module) in enumerate(module_items):
|
||||
if hasattr(module, fn_str) and not "test" in name:
|
||||
with patch(name, fn):
|
||||
if len(module_items[(i + 1) :]) > 0:
|
||||
apply_with_to_item(module_items[(i + 1) :], fn, fn_str)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="session")
|
||||
def set_get_mock_user_wrapper():
|
||||
|
||||
def get_mock_user_wrapper():
|
||||
return get_mock_user(None, None)
|
||||
|
||||
module_items = list(sys.modules.items())
|
||||
apply_with_to_item(module_items, get_mock_user_wrapper(), "get_default_user")
|
||||
|
||||
yield
|
||||
def copy_cognee_db_to_target_location():
|
||||
os.system("mv cognee/tests/integration/run_toy_tasks/data/cognee_db cognee/.cognee_system/databases")
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
import warnings
|
||||
from typing import List, Optional
|
||||
from unittest.mock import Mock, create_autospec
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from cognee.modules.users.models import User
|
||||
|
||||
|
||||
def get_mock_user(
|
||||
user_id: Optional[UUID] = None,
|
||||
groups: Optional[List["Group"]] = None,
|
||||
**additional_attributes
|
||||
) -> Mock:
|
||||
"""
|
||||
Creates a mock User instance with configurable attributes.
|
||||
|
||||
Args:
|
||||
user_id: Optional UUID for the user. Generates random UUID if not provided.
|
||||
groups: Optional list of group mocks to associate with the user.
|
||||
**additional_attributes: Any additional attributes to set on the mock user.
|
||||
|
||||
Returns:
|
||||
Mock: A configured mock User instance.
|
||||
"""
|
||||
warnings.warn("\n\n\n---------------USING MOCK USER--------------------\n\n\n")
|
||||
|
||||
# Generate a random UUID if none provided
|
||||
user_id = user_id or uuid4()
|
||||
|
||||
# Create base mock
|
||||
mock_user = create_autospec(User, instance=True)
|
||||
|
||||
# Configure basic attributes
|
||||
mock_user.id = user_id
|
||||
mock_user.__tablename__ = "users"
|
||||
mock_user.groups = groups or []
|
||||
|
||||
# Set polymorphic identity
|
||||
mock_user.__mapper_args__ = {"polymorphic_identity": "user"}
|
||||
|
||||
# Add any additional attributes
|
||||
for attr_name, attr_value in additional_attributes.items():
|
||||
setattr(mock_user, attr_name, attr_value)
|
||||
|
||||
return mock_user
|
||||
Loading…
Add table
Reference in a new issue