fix: bugfixs when mainModule != app name

This commit is contained in:
sinavir 2024-06-09 20:15:08 +02:00
parent 63744b2b5d
commit b1f50af8d3
3 changed files with 19 additions and 18 deletions

View file

@ -7,11 +7,11 @@
let
mkManagePy = pkgs.callPackage ./utils/mkManagePy.nix { };
mkStaticAssets =
{ app, managePy }:
{ app, managePy, mainModule }:
pkgs.runCommand "django-${app}-static" {} ''
mkdir -p "$out/static"
STATIC_ROOT="\"$out/static\"" \
DJANGO_SETTINGS_MODULE="${app}_settings.mock" \
DJANGO_SETTINGS_MODULE="${mainModule}_settings.mock" \
${lib.getExe managePy} collectstatic --noinput
'';
@ -112,7 +112,7 @@ let
staticAssets = lib.mkOption {
type = lib.types.path;
default = mkStaticAssets {
inherit (config) managePy;
inherit (config) mainModule managePy;
app = name;
};
description = "Satic assets to be served directly by nginx. The default value should be good enough in most cases.";

View file

@ -13,7 +13,7 @@ let
DATABASES = {
"default" = {
"ENGINE" = "django.db.backends.sqlite3";
"NAME" = "/var/lib/django-smoketest/db.sqlite3";
"NAME" = "/var/lib/django-smoke-test/db.sqlite3";
};
};
};
@ -24,11 +24,11 @@ let
SECRETS_SMOKE_TEST = secretFile;
};
project = pkgs.runCommandNoCC "smoketest" { } ''
project = pkgs.runCommandNoCC "smoke-test" { } ''
mkdir -p $out
${django}/bin/django-admin startproject smoketest $out
cp ${./test_assets/views.py} $out/smoketest/views.py
cp ${./test_assets/urls.py} $out/smoketest/urls.py
${django}/bin/django-admin startproject smoke_test $out
cp ${./test_assets/views.py} $out/smoke_test/views.py
cp ${./test_assets/urls.py} $out/smoke_test/urls.py
'';
in
pkgs.testers.runNixOSTest (
@ -40,8 +40,9 @@ pkgs.testers.runNixOSTest (
{
imports = [ ./module.nix ];
services.django.smoketest = {
services.django.smoke-test = {
src = project;
mainModule = "smoke_test";
inherit settings secrets;
port = 8000;
};
@ -50,8 +51,8 @@ pkgs.testers.runNixOSTest (
recommendedProxySettings = true;
virtualHosts.netbox = {
default = true;
locations."/".proxyPass = "http://localhost:${toString config.services.django.smoketest.port}";
locations."/static/".alias = config.services.django.smoketest.staticAssets;
locations."/".proxyPass = "http://localhost:${toString config.services.django.smoke-test.port}";
locations."/static/".alias = config.services.django.smoke-test.staticAssets;
};
};
};
@ -60,7 +61,7 @@ pkgs.testers.runNixOSTest (
import time
import json
start_all()
machine.wait_for_unit("django-smoketest.service")
machine.wait_for_unit("django-smoke-test.service")
machine.wait_for_unit("nginx.service")
time.sleep(1)
with subtest("Test settings"):

View file

@ -36,11 +36,11 @@ let
'';
in
buildPythonPackage {
name = "${mainModule}-settings";
name = "${mainModule}_settings";
unpackPhase = ''
cat > pyproject.toml << EOF
[project]
name = "${mainModule}-settings"
name = "${mainModule}_settings"
version="0.0.1"
dependencies = [
"loadcredential"
@ -51,15 +51,15 @@ buildPythonPackage {
requires = ["hatchling"]
EOF
mkdir -p src/${mainModule}_settings
mkdir -p ${mainModule}_settings
touch src/${mainModule}_settings/__init__.py
touch ${mainModule}_settings/__init__.py
cat > src/${mainModule}_settings/mock.py << EOF
cat > ${mainModule}_settings/mock.py << EOF
${mock}
EOF
cat > src/${mainModule}_settings/prod.py << EOF
cat > ${mainModule}_settings/prod.py << EOF
${prod}
EOF