Add mockapi source files and tests
This commit is contained in:
@@ -1,151 +1,7 @@
|
|||||||
import json
|
|
||||||
import os
|
|
||||||
import tempfile
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from depviz.core.models import Dependency, PackageStatus
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def temp_project_dir():
|
def temp_dir(tmp_path):
|
||||||
"""Create a temporary project directory."""
|
"""Provide a temporary directory."""
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
return tmp_path
|
||||||
yield Path(tmpdir)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def sample_package_json(temp_project_dir):
|
|
||||||
"""Create a sample package.json file."""
|
|
||||||
package_json = {
|
|
||||||
"name": "test-project",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"dependencies": {
|
|
||||||
"lodash": "^4.17.21",
|
|
||||||
"express": "^4.18.2"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"jest": "^29.0.0",
|
|
||||||
"typescript": "^5.0.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
path = temp_project_dir / "package.json"
|
|
||||||
path.write_text(json.dumps(package_json, indent=2))
|
|
||||||
return path
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def sample_package_lock_json(temp_project_dir):
|
|
||||||
"""Create a sample package-lock.json file."""
|
|
||||||
package_lock = {
|
|
||||||
"name": "test-project",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"packages": {
|
|
||||||
"": {
|
|
||||||
"name": "test-project",
|
|
||||||
"version": "1.0.0"
|
|
||||||
},
|
|
||||||
"node_modules/lodash": {
|
|
||||||
"name": "lodash",
|
|
||||||
"version": "4.17.21",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"
|
|
||||||
},
|
|
||||||
"node_modules/express": {
|
|
||||||
"name": "express",
|
|
||||||
"version": "4.18.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz",
|
|
||||||
"dependencies": {
|
|
||||||
"body-parser": {
|
|
||||||
"version": "1.20.2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
path = temp_project_dir / "package-lock.json"
|
|
||||||
path.write_text(json.dumps(package_lock, indent=2))
|
|
||||||
return path
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def sample_requirements_txt(temp_project_dir):
|
|
||||||
"""Create a sample requirements.txt file."""
|
|
||||||
content = """requests>=2.28.0
|
|
||||||
flask>=2.3.0
|
|
||||||
redis>=4.5.0
|
|
||||||
"""
|
|
||||||
path = temp_project_dir / "requirements.txt"
|
|
||||||
path.write_text(content)
|
|
||||||
return path
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def sample_pipfile_lock(temp_project_dir):
|
|
||||||
"""Create a sample Pipfile.lock file."""
|
|
||||||
pipfile_lock = {
|
|
||||||
"default": {
|
|
||||||
"requests": {
|
|
||||||
"version": "==2.28.0"
|
|
||||||
},
|
|
||||||
"flask": {
|
|
||||||
"version": "==2.3.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"develop": {
|
|
||||||
"pytest": {
|
|
||||||
"version": "==7.4.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
path = temp_project_dir / "Pipfile.lock"
|
|
||||||
path.write_text(json.dumps(pipfile_lock, indent=2))
|
|
||||||
return path
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def sample_pyproject_toml(temp_project_dir):
|
|
||||||
"""Create a sample pyproject.toml file."""
|
|
||||||
content = """[project]
|
|
||||||
name = \"test-project\"
|
|
||||||
version = \"1.0.0\"
|
|
||||||
dependencies = [
|
|
||||||
\"requests>=2.28.0\",
|
|
||||||
\"flask>=2.3.0\",
|
|
||||||
]
|
|
||||||
|
|
||||||
[project.optional-dependencies]
|
|
||||||
dev = [
|
|
||||||
\"pytest>=7.4.0\",
|
|
||||||
\"black>=23.0.0\",
|
|
||||||
]
|
|
||||||
"""
|
|
||||||
path = temp_project_dir / "pyproject.toml"
|
|
||||||
path.write_text(content)
|
|
||||||
return path
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def sample_dependencies():
|
|
||||||
"""Create sample Dependency objects."""
|
|
||||||
return [
|
|
||||||
Dependency(
|
|
||||||
name="lodash",
|
|
||||||
version="4.17.21",
|
|
||||||
status=PackageStatus.CURRENT,
|
|
||||||
is_dev=False
|
|
||||||
),
|
|
||||||
Dependency(
|
|
||||||
name="express",
|
|
||||||
version="4.18.2",
|
|
||||||
status=PackageStatus.OUTDATED,
|
|
||||||
latest_version="4.19.0",
|
|
||||||
is_dev=False
|
|
||||||
),
|
|
||||||
Dependency(
|
|
||||||
name="jest",
|
|
||||||
version="29.0.0",
|
|
||||||
status=PackageStatus.VULNERABLE,
|
|
||||||
is_dev=True
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|||||||
Reference in New Issue
Block a user