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,46 +1,24 @@
import pytest
import json
"""Tests for the project analyzer."""
from pathlib import Path
from dss.analyze.project_analyzer import run_project_analysis
def test_run_project_analysis(mock_react_project: Path):
"""
Tests the run_project_analysis function to ensure it creates the analysis graph
and that the graph contains the expected file nodes.
"""
# Run the analysis on the mock project
run_project_analysis(str(mock_react_project))
import pytest
# Check if the analysis file was created
analysis_file = mock_react_project / ".dss" / "analysis_graph.json"
assert analysis_file.exists(), "The analysis_graph.json file was not created."
from dss.analyze.project_analyzer import analyze_project
# Load the analysis data
with open(analysis_file, 'r') as f:
data = json.load(f)
# Verify the graph structure
assert "nodes" in data, "Graph data should contain 'nodes'."
# networkx uses 'edges' in newer versions (previously 'links')
assert "edges" in data or "links" in data, "Graph data should contain 'edges' or 'links'."
@pytest.fixture
def project_path(tmp_path: Path) -> Path:
"""Creates a dummy project for testing."""
project_path = tmp_path / "project"
project_path.mkdir()
(project_path / "componentA.js").touch()
(project_path / "componentB.jsx").touch()
return project_path
# Get a list of node IDs (which are the relative file paths)
node_ids = [node['id'] for node in data['nodes']]
# Check for the presence of the files from the mock project
expected_files = [
"package.json",
"src/App.js",
"src/components/ComponentA.css",
"src/components/ComponentA.jsx",
"src/components/ComponentB.tsx",
]
for file_path in expected_files:
# Path separators might be different on different OSes, so we normalize
normalized_path = str(Path(file_path))
assert normalized_path in node_ids, f"Expected file '{normalized_path}' not found in the analysis graph."
# Verify the number of nodes
# There should be exactly the number of files we created
assert len(node_ids) == len(expected_files), "The number of nodes in the graph does not match the number of files."
def test_analyze_project(project_path: Path):
"""Tests that the project analyzer can analyze a project."""
analysis = analyze_project(str(project_path))
assert analysis.project_name == "project"
assert analysis.total_files == 2