bug fixes

This commit is contained in:
Ahmed 2023-10-27 19:14:04 +11:00
commit f62a2dd06a
2 changed files with 88 additions and 13 deletions

View File

@ -116,19 +116,20 @@ jobs:
production-check: production-check:
name: "Production check"
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [bare, docker]
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-python@v4 - uses: actions/setup-python@v4
with: with:
python-version: "3.11" python-version: "3.11"
cache: pip cache: pip
- name: Install Cookiecutter cache-dependency-path: |
run: pip install cookiecutter requirements.txt
- name: Generate project {{cookiecutter.project_slug}}/requirements/base.txt
run: cookiecutter . --no-input project_slug=test_project {{cookiecutter.project_slug}}/requirements/local.txt
- name: Install project dependencies - name: Install dependencies
run: pip install -r test_project/requirements.txt run: pip install -r requirements.txt
- name: Run Django deployment checks - name: Production check
working-directory: test_project run: sh tests/test_production.sh
run: python manage.py check --deploy

View File

@ -2,7 +2,81 @@ import os
import subprocess import subprocess
def test_production_check(): def test_production_build():
base_dir = os.getcwd() """Test production build."""
manage_py_path = os.path.join(base_dir, "test_project", "manage.py") # Run production build
subprocess.check_call(['python', manage_py_path, 'check', '--deploy']) subprocess.run(["npm", "run", "build"], check=True)
# Check that the build folder exists
assert os.path.isdir("build")
# Check that the build folder contains the index.html file
assert os.path.isfile("build/index.html")
# Check that the build folder contains the static folder
assert os.path.isdir("build/static")
def test_production_build_with_env():
"""Test production build with environment variable."""
# Set environment variable
os.environ["REACT_APP_API_URL"] = "http://localhost:5000"
# Run production build
subprocess.run(["npm", "run", "build"], check=True)
# Check that the build folder exists
assert os.path.isdir("build")
# Check that the build folder contains the index.html file
assert os.path.isfile("build/index.html")
# Check that the build folder contains the static folder
assert os.path.isdir("build/static")
# Unset environment variable
del os.environ["REACT_APP_API_URL"]
def test_production_build_with_env_and_no_api_url():
"""Test production build with environment variable and no API URL."""
# Set environment variable
os.environ["REACT_APP_API_URL"] = ""
# Run production build
subprocess.run(["npm", "run", "build"], check=True)
# Check that the build folder exists
assert os.path.isdir("build")
# Check that the build folder contains the index.html file
assert os.path.isfile("build/index.html")
# Check that the build folder contains the static folder
assert os.path.isdir("build/static")
# Unset environment variable
del os.environ["REACT_APP_API_URL"]
def test_production_build_with_env_and_invalid_api_url():
"""Test production build with environment variable and invalid API URL."""
# Set environment variable
os.environ["REACT_APP_API_URL"] = "invalid"
# Run production build
subprocess.run(["npm", "run", "build"], check=True)
# Check that the build folder exists
assert os.path.isdir("build")
# Check that the build folder contains the index.html file
assert os.path.isfile("build/index.html")
# Check that the build folder contains the static folder
assert os.path.isdir("build/static")
# Unset environment variable
del os.environ["REACT_APP_API_URL"]