fix: bugfixs when mainModule != app name
This commit is contained in:
parent
63744b2b5d
commit
b1f50af8d3
3 changed files with 19 additions and 18 deletions
|
@ -7,11 +7,11 @@
|
||||||
let
|
let
|
||||||
mkManagePy = pkgs.callPackage ./utils/mkManagePy.nix { };
|
mkManagePy = pkgs.callPackage ./utils/mkManagePy.nix { };
|
||||||
mkStaticAssets =
|
mkStaticAssets =
|
||||||
{ app, managePy }:
|
{ app, managePy, mainModule }:
|
||||||
pkgs.runCommand "django-${app}-static" {} ''
|
pkgs.runCommand "django-${app}-static" {} ''
|
||||||
mkdir -p "$out/static"
|
mkdir -p "$out/static"
|
||||||
STATIC_ROOT="\"$out/static\"" \
|
STATIC_ROOT="\"$out/static\"" \
|
||||||
DJANGO_SETTINGS_MODULE="${app}_settings.mock" \
|
DJANGO_SETTINGS_MODULE="${mainModule}_settings.mock" \
|
||||||
${lib.getExe managePy} collectstatic --noinput
|
${lib.getExe managePy} collectstatic --noinput
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ let
|
||||||
staticAssets = lib.mkOption {
|
staticAssets = lib.mkOption {
|
||||||
type = lib.types.path;
|
type = lib.types.path;
|
||||||
default = mkStaticAssets {
|
default = mkStaticAssets {
|
||||||
inherit (config) managePy;
|
inherit (config) mainModule managePy;
|
||||||
app = name;
|
app = name;
|
||||||
};
|
};
|
||||||
description = "Satic assets to be served directly by nginx. The default value should be good enough in most cases.";
|
description = "Satic assets to be served directly by nginx. The default value should be good enough in most cases.";
|
||||||
|
|
19
test.nix
19
test.nix
|
@ -13,7 +13,7 @@ let
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
"default" = {
|
"default" = {
|
||||||
"ENGINE" = "django.db.backends.sqlite3";
|
"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;
|
SECRETS_SMOKE_TEST = secretFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
project = pkgs.runCommandNoCC "smoketest" { } ''
|
project = pkgs.runCommandNoCC "smoke-test" { } ''
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
${django}/bin/django-admin startproject smoketest $out
|
${django}/bin/django-admin startproject smoke_test $out
|
||||||
cp ${./test_assets/views.py} $out/smoketest/views.py
|
cp ${./test_assets/views.py} $out/smoke_test/views.py
|
||||||
cp ${./test_assets/urls.py} $out/smoketest/urls.py
|
cp ${./test_assets/urls.py} $out/smoke_test/urls.py
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
pkgs.testers.runNixOSTest (
|
pkgs.testers.runNixOSTest (
|
||||||
|
@ -40,8 +40,9 @@ pkgs.testers.runNixOSTest (
|
||||||
{
|
{
|
||||||
imports = [ ./module.nix ];
|
imports = [ ./module.nix ];
|
||||||
|
|
||||||
services.django.smoketest = {
|
services.django.smoke-test = {
|
||||||
src = project;
|
src = project;
|
||||||
|
mainModule = "smoke_test";
|
||||||
inherit settings secrets;
|
inherit settings secrets;
|
||||||
port = 8000;
|
port = 8000;
|
||||||
};
|
};
|
||||||
|
@ -50,8 +51,8 @@ pkgs.testers.runNixOSTest (
|
||||||
recommendedProxySettings = true;
|
recommendedProxySettings = true;
|
||||||
virtualHosts.netbox = {
|
virtualHosts.netbox = {
|
||||||
default = true;
|
default = true;
|
||||||
locations."/".proxyPass = "http://localhost:${toString config.services.django.smoketest.port}";
|
locations."/".proxyPass = "http://localhost:${toString config.services.django.smoke-test.port}";
|
||||||
locations."/static/".alias = config.services.django.smoketest.staticAssets;
|
locations."/static/".alias = config.services.django.smoke-test.staticAssets;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -60,7 +61,7 @@ pkgs.testers.runNixOSTest (
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
start_all()
|
start_all()
|
||||||
machine.wait_for_unit("django-smoketest.service")
|
machine.wait_for_unit("django-smoke-test.service")
|
||||||
machine.wait_for_unit("nginx.service")
|
machine.wait_for_unit("nginx.service")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
with subtest("Test settings"):
|
with subtest("Test settings"):
|
||||||
|
|
|
@ -36,11 +36,11 @@ let
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
buildPythonPackage {
|
buildPythonPackage {
|
||||||
name = "${mainModule}-settings";
|
name = "${mainModule}_settings";
|
||||||
unpackPhase = ''
|
unpackPhase = ''
|
||||||
cat > pyproject.toml << EOF
|
cat > pyproject.toml << EOF
|
||||||
[project]
|
[project]
|
||||||
name = "${mainModule}-settings"
|
name = "${mainModule}_settings"
|
||||||
version="0.0.1"
|
version="0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"loadcredential"
|
"loadcredential"
|
||||||
|
@ -51,15 +51,15 @@ buildPythonPackage {
|
||||||
requires = ["hatchling"]
|
requires = ["hatchling"]
|
||||||
EOF
|
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}
|
${mock}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
cat > src/${mainModule}_settings/prod.py << EOF
|
cat > ${mainModule}_settings/prod.py << EOF
|
||||||
${prod}
|
${prod}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue