From 9496d5eb799da1615df415a85ddcfa1082875638 Mon Sep 17 00:00:00 2001 From: Kerstin Humm Date: Fri, 23 Jan 2026 13:34:52 +0100 Subject: [PATCH] weblate: run pytest unit tests --- pkgs/by-name/we/weblate/package.nix | 119 ++++++++++++++++++++++++++-- 1 file changed, 111 insertions(+), 8 deletions(-) diff --git a/pkgs/by-name/we/weblate/package.nix b/pkgs/by-name/we/weblate/package.nix index 04749c37a459..2fc9c6dbe630 100644 --- a/pkgs/by-name/we/weblate/package.nix +++ b/pkgs/by-name/we/weblate/package.nix @@ -9,15 +9,29 @@ gdk-pixbuf, glib, gobject-introspection, - askalono, borgbackup, writeText, + postgresqlTestHook, + postgresql, + redisTestHook, + fontconfig, nixosTests, + + # runtime inputs + gitSVN, + subversion, + + #optional runtime inputs + git-review, + tesseract, + licensee, + mercurial, + openssh, }: let python = python3.override { - packageOverrides = final: prev: { + packageOverrides = _final: prev: { django = prev.django_5; }; }; @@ -40,6 +54,10 @@ python.pkgs.buildPythonApplication rec { hash = "sha256-qNv3aaPyQ/bOrPbK7u9vtq8R1MFqXLJzvLUZfVgjMK0="; }; + postPatch = '' + sed -i 's|/bin/true|true|g' weblate/addons/example_pre.py + ''; + build-system = with python.pkgs; [ setuptools ]; nativeBuildInputs = [ gettext ]; @@ -54,14 +72,14 @@ python.pkgs.buildPythonApplication rec { # So we don't need postgres dependencies DATABASES = {} ''; + manage = "DJANGO_SETTINGS_MODULE='weblate.settings_static' ${python.pythonOnBuildForHost.interpreter} manage.py"; in '' mkdir $static cat weblate/settings_example.py ${staticSettings} > weblate/settings_static.py - export DJANGO_SETTINGS_MODULE="weblate.settings_static" - ${python.pythonOnBuildForHost.interpreter} manage.py compilemessages - ${python.pythonOnBuildForHost.interpreter} manage.py collectstatic --no-input - ${python.pythonOnBuildForHost.interpreter} manage.py compress + ${manage} compilemessages + ${manage} collectstatic --no-input + ${manage} compress ''; pythonRelaxDeps = [ @@ -152,8 +170,30 @@ python.pkgs.buildPythonApplication rec { ++ urllib3.optional-dependencies.brotli ++ urllib3.optional-dependencies.zstd; - optional-dependencies = { - postgres = with python.pkgs; [ psycopg ]; + # Commented entries are not packaged yet + optional-dependencies = with python.pkgs; { + alibaba = [ + aliyun-python-sdk-alimt + aliyun-python-sdk-core + ]; + amazon = [ boto3 ]; + # antispam = [ python-akismet ]; + # gelf = [ logging-gelf ]; + # gerrit = [ git-review ]; + google = [ + google-cloud-storage + google-cloud-translate + ]; + ldap = [ django-auth-ldap ]; + # mercurial = [ mercurial ]; + mysql = [ mysqlclient ]; + openai = [ openai ]; + postgres = [ psycopg ]; + saml = [ python3-saml ]; + # saml2idp = [ djangosaml2idp ]; + # wlhosted = [ wlhosted ]; + wsgi = [ granian ]; + # zxcvbn = [ django-zxcvbn-password-validator ]; }; # We don't just use wrapGAppsNoGuiHook because we need to expose GI_TYPELIB_PATH @@ -167,6 +207,69 @@ python.pkgs.buildPythonApplication rec { ]; makeWrapperArgs = [ "--set GI_TYPELIB_PATH \"$GI_TYPELIB_PATH\"" ]; + nativeCheckInputs = + with python.pkgs; + [ + pytestCheckHook + postgresqlTestHook + postgresql + redisTestHook + pytest-cov-stub + pytest-django + pytest-xdist + responses + respx + selenium + standardwebhooks + + gitSVN + subversion + gettext + fontconfig + borgbackup + + #optional + git-review + tesseract + licensee + mercurial + openssh + ] + ++ social-auth-core.optional-dependencies.saml + ++ (lib.concatLists (builtins.attrValues optional-dependencies)); + + env = { + CI_DATABASE = "postgresql"; + DJANGO_SETTINGS_MODULE = "weblate.settings_test"; + + # Only needed to make weblate/settings_test.py happy + CI_DB_PORT = ""; + CI_DB_PASSWORD = ""; + CI_REDIS_HOST = ""; + CI_REDIS_PORT = ""; + }; + + # pytest-xdist wants to create an additional database per test group + postgresqlTestUserOptions = "LOGIN SUPERUSER"; + + postgresqlTestSetupPost = '' + export CI_DB_HOST="$PGHOST" + export CI_DB_USER="$PGUSER" + export CI_DB_NAME="$PGDATABASE" + + echo "CACHES[\"avatar\"][\"LOCATION\"] = \"unix://$NIX_BUILD_TOP/run/redis.sock\"" \ + >> weblate/settings_test.py + + ${python.pythonOnBuildForHost.interpreter} manage.py migrate --noinput + ${python.pythonOnBuildForHost.interpreter} manage.py check + ''; + + disabledTests = [ + # Tries to download things from GitHub + "test_ocr" + "test_ocr_backend" + ]; + passthru = { inherit python; # We need to expose this so weblate can work outside of calling its bin output