mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
863e0a4e24
Signed-off-by: phernandez <paul@basicmachines.co> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
72 lines
2.5 KiB
Python
72 lines
2.5 KiB
Python
"""Additional tests for ProjectService operations."""
|
|
|
|
import os
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from basic_memory.services.project_service import ProjectService
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_project_from_database(project_service: ProjectService):
|
|
"""Test getting projects from the database."""
|
|
# Generate unique project name for testing
|
|
test_project_name = f"test-project-{os.urandom(4).hex()}"
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
test_root = Path(temp_dir)
|
|
test_path = str(test_root / "test-project")
|
|
|
|
# Make sure directory exists
|
|
os.makedirs(test_path, exist_ok=True)
|
|
|
|
try:
|
|
# Add a project to the database
|
|
project_data = {
|
|
"name": test_project_name,
|
|
"path": test_path,
|
|
"permalink": test_project_name.lower().replace(" ", "-"),
|
|
"is_active": True,
|
|
"is_default": False,
|
|
}
|
|
await project_service.repository.create(project_data)
|
|
|
|
# Verify we can get the project
|
|
project = await project_service.repository.get_by_name(test_project_name)
|
|
assert project is not None
|
|
assert project.name == test_project_name
|
|
assert project.path == test_path
|
|
|
|
finally:
|
|
# Clean up
|
|
project = await project_service.repository.get_by_name(test_project_name)
|
|
if project:
|
|
await project_service.repository.delete(project.id)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_add_project_to_config(project_service: ProjectService, config_manager):
|
|
"""Test adding a project to the config manager."""
|
|
# Generate unique project name for testing
|
|
test_project_name = f"config-project-{os.urandom(4).hex()}"
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
test_root = Path(temp_dir)
|
|
test_path = test_root / "config-project"
|
|
|
|
# Make sure directory exists
|
|
test_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
try:
|
|
# Add a project to config only (using ConfigManager directly)
|
|
config_manager.add_project(test_project_name, str(test_path))
|
|
|
|
# Verify it's in the config
|
|
assert test_project_name in project_service.projects
|
|
assert Path(project_service.projects[test_project_name]) == test_path
|
|
|
|
finally:
|
|
# Clean up
|
|
if test_project_name in project_service.projects:
|
|
config_manager.remove_project(test_project_name)
|