fix: Address high-severity bandit issues

This commit is contained in:
DSS
2025-12-11 07:13:06 -03:00
parent bcb4475744
commit 5b2a328dd1
167 changed files with 7051 additions and 7168 deletions

View File

@@ -1,11 +1,7 @@
"""
Tests for the Figma ingestion source.
"""
"""Tests for the Figma ingestion source."""
import asyncio
from unittest.mock import patch, AsyncMock, MagicMock
import pytest
from unittest.mock import patch
from dss.ingest.sources.figma import FigmaTokenSource
from dss.models.component import AtomicType
@@ -15,9 +11,11 @@ from dss.models.component import AtomicType
class MockAsyncClient:
"""
Mocks the IntelligentFigmaClient for testing purposes.
Simulates an async context manager and provides mock async methods
for Figma API calls.
"""
def __init__(self, *args, **kwargs):
pass
@@ -28,9 +26,7 @@ class MockAsyncClient:
pass
async def get_file(self, file_key: str):
"""
Mocks the async get_file method to return a predefined Figma document structure.
"""
"""Mocks the async get_file method to return a predefined Figma document structure."""
return {
"document": {
"id": "0:0",
@@ -51,17 +47,13 @@ class MockAsyncClient:
"id": "1:2",
"name": "Button",
"type": "COMPONENT",
"children": [
{"id": "1:1", "name": "Icon", "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"}
],
"children": [{"id": "1:2", "name": "Button", "type": "COMPONENT"}],
},
],
}
@@ -70,16 +62,15 @@ class MockAsyncClient:
}
async def get_file_variables(self, file_key: str):
"""
Mocks the async get_file_variables method to return empty variables.
"""
"""Mocks the async get_file_variables method to return empty variables."""
return {"meta": {"variables": {}, "variableCollections": {}}}
@patch("dss.ingest.sources.figma.IntelligentFigmaClient", new=MockAsyncClient)
def test_figma_component_extraction():
"""
Test that the Figma ingestion source correctly extracts and classifies
Test that the Figma ingestion source correctly extracts and classifies.
components from a mock Figma file structure. It verifies that the recursive
component discovery works and assigns correct AtomicType classifications.
"""
@@ -96,8 +87,8 @@ def test_figma_component_extraction():
if component.name == "Card":
card_component_found = True
assert component.classification == AtomicType.MOLECULE
assert component.sub_components # should not be empty
assert len(component.sub_components) == 1 # Card has one child
assert component.sub_components # should not be empty
assert len(component.sub_components) == 1 # Card has one child
assert component.figma_node_id == "1:3"
assert card_component_found, "Card component not found in extracted components."
assert card_component_found, "Card component not found in extracted components."