53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
import pytest
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
|
|
from app.modules.project.domain.entities import Project
|
|
from app.modules.scanner.application.services import ScanService
|
|
from app.modules.editor.application.services import EditorService
|
|
|
|
|
|
@pytest.fixture
|
|
def editor_service():
|
|
return EditorService(ScanService())
|
|
|
|
|
|
@pytest.fixture
|
|
def test_project(tmp_path):
|
|
design = tmp_path / "design"
|
|
design.mkdir()
|
|
(design / "test.csv").write_text("col1,col2\nval1,val2\n")
|
|
(design / "test.md").write_text("---\ndoc_id: DOC-TEST\ntitle: Test\n---\n# Test\n")
|
|
return Project(
|
|
id="test", name="test",
|
|
design_dir=str(design), code_dir=None,
|
|
created_at=datetime(2026, 1, 1),
|
|
)
|
|
|
|
|
|
def test_get_file_csv(editor_service, test_project):
|
|
f = editor_service.get_file(test_project, "test.csv")
|
|
assert f.format == "csv"
|
|
assert "col1" in f.content
|
|
|
|
|
|
def test_get_file_md(editor_service, test_project):
|
|
f = editor_service.get_file(test_project, "test.md")
|
|
assert f.format == "md"
|
|
|
|
|
|
def test_save_file(editor_service, test_project):
|
|
result = editor_service.save_file(test_project, "test.csv", "a,b\n1,2\n")
|
|
assert result.project_id == "test"
|
|
# Verify file was actually written
|
|
content = (Path(test_project.design_dir) / "test.csv").read_text()
|
|
assert content == "a,b\n1,2\n"
|
|
|
|
|
|
def test_get_impact(editor_service, test_project):
|
|
scan_svc = ScanService()
|
|
scan_result = scan_svc.scan(test_project)
|
|
impact = editor_service.get_impact(test_project, "test.md", scan_result)
|
|
assert impact.source_file == "test.md"
|
|
assert isinstance(impact.affected_files, list)
|