Files
dss/tests/test_atomic_dss.py
DSS ec09a0a662
Some checks failed
DSS Project Analysis / dss-context-update (push) Has been cancelled
Unify MCP across clients; remove legacy plugin server
2025-12-12 14:33:18 -03:00

88 lines
2.9 KiB
Python

"""Tests for the atomic DSS structure."""
import asyncio
from pathlib import Path
from unittest.mock import MagicMock, patch
import pytest
from dss.models.component import AtomicType
from dss.project.manager import DSSProject, ProjectManager, ProjectRegistry
@pytest.fixture
def project_manager(tmp_path: Path) -> ProjectManager:
"""
Fixture for the ProjectManager.
"""
registry_path = tmp_path / "registry.json"
registry = ProjectRegistry(registry_path=registry_path)
return ProjectManager(registry=registry)
@pytest.fixture
def dss_project(project_manager: ProjectManager, tmp_path: Path) -> DSSProject:
"""
Fixture for a DSSProject.
"""
project_path = tmp_path / "test_project"
project = project_manager.init(project_path, "test_project")
project.config.figma = MagicMock()
project.config.figma.files = [MagicMock(key="fake_key", name="fake_name")]
return project
# Mock Figma client with async context manager and async methods
class MockAsyncClient:
def __init__(self, *args, **kwargs):
pass
async def __aenter__(self):
return self
async def __aexit__(self, exc_type, exc_val, exc_tb):
pass
async def get_file(self, file_key: str):
return {
"document": {
"id": "0:0",
"name": "Document",
"type": "DOCUMENT",
"children": [
{
"id": "1:0",
"name": "Page 1",
"type": "CANVAS",
"children": [
{"id": "1:1", "name": "Icon", "type": "COMPONENT"},
{
"id": "1:2",
"name": "Button",
"type": "COMPONENT",
"children": [{"id": "1:1", "name": "Icon", "type": "COMPONENT"}],
},
{
"id": "1:3",
"name": "Card",
"type": "COMPONENT_SET",
"children": [{"id": "1:2", "name": "Button", "type": "COMPONENT"}],
},
],
}
],
}
}
async def get_file_variables(self, file_key: str):
return {"meta": {"variables": {}, "variableCollections": {}}}
@patch("dss.ingest.sources.figma.IntelligentFigmaClient", new=MockAsyncClient)
def test_recursive_figma_import(dss_project: DSSProject, project_manager: ProjectManager):
"""Project sync uses extracted Figma components."""
dss_project = asyncio.run(project_manager.sync(dss_project, figma_token="fake_token"))
assert len(dss_project.components) == 1
assert dss_project.components[0].name == "Card"
assert dss_project.components[0].classification == AtomicType.COMPOSITE_COMPONENT