Add fixture for mock user
This commit is contained in:
parent
7d3f2224eb
commit
7d3657aef7
4 changed files with 21 additions and 10 deletions
18
cognee/tests/unit/run_tasks/conftest.py
Normal file
18
cognee/tests/unit/run_tasks/conftest.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import pytest
|
||||||
|
import warnings
|
||||||
|
from cognee.tests.unit.utils.get_mock_user import get_mock_user
|
||||||
|
from cognee.modules.users.methods.get_default_user import get_default_user
|
||||||
|
import cognee
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True, scope="session")
|
||||||
|
def set_get_mock_user_wrapper():
|
||||||
|
|
||||||
|
def get_mock_user_wrapper():
|
||||||
|
warnings.warn("\n\n\n---------------USING MOCK USER--------------------\n\n\n")
|
||||||
|
return get_mock_user(None, None)
|
||||||
|
|
||||||
|
get_default_user = cognee.modules.users.methods.get_default_user
|
||||||
|
cognee.modules.users.methods.get_default_user = get_mock_user_wrapper()
|
||||||
|
yield
|
||||||
|
cognee.modules.users.methods.get_default_user = get_default_user
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import warnings
|
||||||
from cognee.modules.pipelines.operations.run_tasks import run_tasks
|
from cognee.modules.pipelines.operations.run_tasks import run_tasks
|
||||||
from cognee.modules.pipelines.tasks.Task import Task
|
from cognee.modules.pipelines.tasks.Task import Task
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
from cognee.tests.unit.utils.get_mock_user import get_mock_user
|
from cognee.tests.unit.utils.get_mock_user import get_mock_user
|
||||||
|
from cognee.modules.users.methods.get_default_user import get_default_user
|
||||||
|
|
||||||
|
|
||||||
async def run_and_check_tasks():
|
async def run_and_check_tasks():
|
||||||
|
|
@ -40,8 +42,4 @@ async def run_and_check_tasks():
|
||||||
|
|
||||||
|
|
||||||
def test_run_tasks():
|
def test_run_tasks():
|
||||||
@patch("from cognee.modules.users.methods import get_default_user")
|
|
||||||
def get_mock_user_wrapper():
|
|
||||||
return get_mock_user(None, None)
|
|
||||||
|
|
||||||
asyncio.run(run_and_check_tasks())
|
asyncio.run(run_and_check_tasks())
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@ import asyncio
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from cognee.modules.pipelines.operations.run_tasks import run_tasks
|
from cognee.modules.pipelines.operations.run_tasks import run_tasks
|
||||||
from cognee.modules.pipelines.tasks.Task import Task
|
from cognee.modules.pipelines.tasks.Task import Task
|
||||||
from unittest.mock import patch
|
|
||||||
from cognee.tests.unit.utils.get_mock_user import get_mock_user
|
|
||||||
|
|
||||||
|
|
||||||
async def pipeline(data_queue):
|
async def pipeline(data_queue):
|
||||||
|
|
@ -51,8 +49,4 @@ async def run_queue():
|
||||||
|
|
||||||
|
|
||||||
def test_run_tasks_from_queue():
|
def test_run_tasks_from_queue():
|
||||||
@patch("from cognee.modules.users.methods import get_default_user")
|
|
||||||
def get_mock_user_wrapper():
|
|
||||||
return get_mock_user(None, None)
|
|
||||||
|
|
||||||
asyncio.run(run_queue())
|
asyncio.run(run_queue())
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
from unittest.mock import Mock, create_autospec
|
from unittest.mock import Mock, create_autospec
|
||||||
from uuid import UUID, uuid4
|
from uuid import UUID, uuid4
|
||||||
from typing import Optional, List
|
from typing import Optional, List
|
||||||
|
from cognee.modules.users.models import User
|
||||||
|
|
||||||
|
|
||||||
def get_mock_user(
|
def get_mock_user(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue