Skip to content

Commit 0427e53

Browse files
TheVaanhanspagel
authored andcommitted
chore(django-ninja): update setup.py and package.json; add run_tests.py
1 parent 6331638 commit 0427e53

File tree

4 files changed

+97
-9
lines changed

4 files changed

+97
-9
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
include README.md
22
include package.json
3-
include LICENSE
3+
include LICENSE
4+
prune tests

integrations/django-ninja/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
"engines": {
1616
"node": ">=20"
1717
},
18-
"scripts": {},
18+
"scripts": {
19+
"dev": "command -v python >/dev/null 2>&1 && python manage.py runserver || echo '⚠️ python is not available, skipping the dev server.'",
20+
"test": "command -v python >/dev/null 2>&1 && python run_tests.py || echo '⚠️ python is not available, skipping the tests.'"
21+
},
1922
"dependencies": {},
2023
"devDependencies": {}
2124
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Test runner for scalar-django-ninja integration.
4+
This script runs all tests and provides a summary.
5+
"""
6+
7+
import subprocess
8+
import sys
9+
import os
10+
from pathlib import Path
11+
12+
13+
def run_tests():
14+
"""Run all tests for the scalar-django-ninja integration"""
15+
16+
# Get the directory where this script is located
17+
script_dir = Path(__file__).parent
18+
os.chdir(script_dir)
19+
20+
print("🧪 Running Scalar Django Ninja Integration Tests")
21+
print("=" * 50)
22+
23+
# Check if pytest is available
24+
try:
25+
import pytest
26+
except ImportError:
27+
print("❌ pytest is not installed. Installing test dependencies...")
28+
subprocess.run(
29+
[sys.executable, "-m", "pip", "install", "-r", "tests/requirements.txt"],
30+
check=True,
31+
)
32+
33+
# Run the tests
34+
print("📋 Running unit tests...")
35+
result = subprocess.run(
36+
[sys.executable, "-m", "pytest", "tests/", "-v", "--tb=short", "--color=yes"]
37+
)
38+
39+
if result.returncode == 0:
40+
print("\n✅ All tests passed!")
41+
else:
42+
print("\n❌ Some tests failed!")
43+
sys.exit(1)
44+
45+
46+
def run_specific_test(test_file=None, test_function=None):
47+
"""Run a specific test file or function"""
48+
49+
script_dir = Path(__file__).parent
50+
os.chdir(script_dir)
51+
52+
cmd = [sys.executable, "-m", "pytest", "-v", "--tb=short", "--color=yes"]
53+
54+
if test_file:
55+
cmd.append(f"tests/{test_file}")
56+
57+
if test_function:
58+
cmd.append(f"-k {test_function}")
59+
60+
subprocess.run(cmd)
61+
62+
63+
if __name__ == "__main__":
64+
if len(sys.argv) > 1:
65+
if sys.argv[1] == "--help" or sys.argv[1] == "-h":
66+
print("Usage:")
67+
print(" python run_tests.py # Run all tests")
68+
print(" python run_tests.py test_file.py # Run specific test file")
69+
print(
70+
" python run_tests.py test_file.py func # Run specific test function"
71+
)
72+
elif len(sys.argv) == 2:
73+
run_specific_test(sys.argv[1])
74+
elif len(sys.argv) == 3:
75+
run_specific_test(sys.argv[1], sys.argv[2])
76+
else:
77+
run_tests()

integrations/django-ninja/setup.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1+
import json
2+
import os
13
from setuptools import setup, find_packages
24

5+
6+
# Read version from package.json
7+
def get_version():
8+
package_json_path = os.path.join(os.path.dirname(__file__), "package.json")
9+
with open(package_json_path, "r") as f:
10+
package_data = json.load(f)
11+
return package_data["version"]
12+
13+
314
setup(
415
name="scalar_django_ninja",
5-
version="1.0.0",
6-
packages=find_packages(),
7-
install_requires=[
8-
# Add your package dependencies here
9-
],
16+
version=get_version(),
17+
packages=find_packages(exclude=["tests"]),
18+
install_requires=[],
1019
author="Marc Laventure",
1120
author_email="marc@scalar.com",
1221
description="This plugin provides an easy way to render a beautiful API reference based on a OpenAPI/Swagger file with Django Ninja.",
1322
long_description=open("README.md").read(),
1423
long_description_content_type="text/markdown",
1524
url="https://github.com/scalar/scalar",
16-
# classifiers=[
17-
# ],
1825
)

0 commit comments

Comments
 (0)