about summary refs log tree commit diff
path: root/pkgs/tools/admin/pgadmin
diff options
context:
space:
mode:
authorFlorian Brandes <florian.brandes@posteo.de>2023-02-04 01:14:23 +0100
committerFlorian Brandes <florian.brandes@posteo.de>2023-02-09 08:06:52 +0100
commite4488f5efe4ee6fd401894e96abc44153d70b1d4 (patch)
tree7bf6a1981e9e0554241a70bf18b5b477ec6d637b /pkgs/tools/admin/pgadmin
parentcfc77dc41003c7c0abe820fc4c18a7492012f1df (diff)
pgadmin4: move package tests back into the package
We test pgadmin in nixosTests, because it needs a running postgresql instance.
This is now unnecessary since we can do so in the package itself.

This reduces the complexity of pgadmin and removes the need for the extra
nixosTests.

Also setting SERVER_MODE in `pkg/pip/setup_pip.py` does not have any effect
on the final package, so we remove it.
In NixOS, we use the module, which expects SERVER_MODE to be true (which it defaults to).
In non-NixOS installations, we will need the directory /var/lib/pgadmin and /var/log/pgadmin

Signed-off-by: Florian Brandes <florian.brandes@posteo.de>
Diffstat (limited to 'pkgs/tools/admin/pgadmin')
-rw-r--r--pkgs/tools/admin/pgadmin/default.nix150
1 files changed, 88 insertions, 62 deletions
diff --git a/pkgs/tools/admin/pgadmin/default.nix b/pkgs/tools/admin/pgadmin/default.nix
index d00b61744dc15..2f85b4e3aff99 100644
--- a/pkgs/tools/admin/pgadmin/default.nix
+++ b/pkgs/tools/admin/pgadmin/default.nix
@@ -7,6 +7,8 @@
 , nixosTests
 , pkgs
 , fetchPypi
+, postgresqlTestHook
+, postgresql
 }:
 
 let
@@ -26,54 +28,6 @@ let
     yarnNix = ./yarn.nix;
   };
 
-  # move buildDeps here to easily pass to test suite
-  buildDeps = with pythonPackages; [
-    flask
-    flask-gravatar
-    flask-login
-    flask_mail
-    flask_migrate
-    flask-sqlalchemy
-    flask-wtf
-    flask-compress
-    passlib
-    pytz
-    simplejson
-    sqlparse
-    wtforms
-    flask-paranoid
-    psutil
-    psycopg2
-    python-dateutil
-    sqlalchemy
-    itsdangerous
-    flask-security-too
-    bcrypt
-    cryptography
-    sshtunnel
-    ldap3
-    flask-babelex
-    flask-babel
-    gssapi
-    flask-socketio
-    eventlet
-    httpagentparser
-    user-agents
-    wheel
-    authlib
-    qrcode
-    pillow
-    pyotp
-    botocore
-    boto3
-    azure-mgmt-subscription
-    azure-mgmt-rdbms
-    azure-mgmt-resource
-    azure-identity
-    sphinxcontrib-youtube
-    dnspython
-    greenlet
-  ];
 
   # keep the scope, as it is used throughout the derivation and tests
   # this also makes potential future overrides easier
@@ -149,10 +103,8 @@ pythonPackages.buildPythonApplication rec {
 
     # relax dependencies
     sed 's|==|>=|g' -i requirements.txt
-    # don't use Server Mode (can be overridden later)
     substituteInPlace pkg/pip/setup_pip.py \
-      --replace "req = req.replace('psycopg2', 'psycopg2-binary')" "req = req" \
-      --replace "builtins.SERVER_MODE = None" "builtins.SERVER_MODE = False"
+      --replace "req = req.replace('psycopg2', 'psycopg2-binary')" "req = req"
   '';
 
   preBuild = ''
@@ -200,21 +152,95 @@ pythonPackages.buildPythonApplication rec {
     pythonPackages.wheel
   ];
 
-  # tests need an own data, log directory
-  # and a working and correctly setup postgres database
-  # checks will be run through nixos/tests
-  doCheck = false;
-
-  # speaklater3 is separate because when passing buildDeps
-  # to the test, it fails there due to a collision with speaklater
-  propagatedBuildInputs = buildDeps ++ [ pythonPackages.speaklater3 ];
+  propagatedBuildInputs = with pythonPackages; [
+    flask
+    flask-gravatar
+    flask-login
+    flask_mail
+    flask_migrate
+    flask-sqlalchemy
+    flask-wtf
+    flask-compress
+    passlib
+    pytz
+    simplejson
+    sqlparse
+    wtforms
+    flask-paranoid
+    psutil
+    psycopg2
+    python-dateutil
+    sqlalchemy
+    itsdangerous
+    flask-security-too
+    bcrypt
+    cryptography
+    sshtunnel
+    ldap3
+    flask-babelex
+    flask-babel
+    gssapi
+    flask-socketio
+    eventlet
+    httpagentparser
+    user-agents
+    wheel
+    authlib
+    qrcode
+    pillow
+    pyotp
+    botocore
+    boto3
+    azure-mgmt-subscription
+    azure-mgmt-rdbms
+    azure-mgmt-resource
+    azure-identity
+    sphinxcontrib-youtube
+    dnspython
+    greenlet
+    speaklater3
+  ];
 
   passthru.tests = {
-    standalone = nixosTests.pgadmin4-standalone;
-    # regression and function tests of the package itself
-    package = import ../../../../nixos/tests/pgadmin4.nix { inherit pkgs buildDeps; pythonEnv = pythonPackages; };
+    inherit (nixosTests) pgadmin4;
   };
 
+  nativeCheckInputs = [
+    postgresqlTestHook
+    postgresql
+    pythonPackages.testscenarios
+    pythonPackages.selenium
+  ];
+
+  checkPhase = ''
+    runHook preCheck
+
+    ## Setup ##
+
+    # pgadmin needs a home directory to save the configuration
+    export HOME=$TMPDIR
+    cd pgadmin4
+
+    # set configuration for postgresql test
+    # also ensure Server Mode is set to false. If not, the tests will fail, since pgadmin expects read/write permissions
+    # in /var/lib/pgadmin and /var/log/pgadmin
+    # see https://github.com/pgadmin-org/pgadmin4/blob/fd1c26408bbf154fa455a49ee5c12895933833a3/web/regression/runtests.py#L217-L226
+    cp -v regression/test_config.json.in regression/test_config.json
+    substituteInPlace regression/test_config.json --replace "localhost" "$PGHOST"
+    substituteInPlace regression/runtests.py --replace "builtins.SERVER_MODE = None" "builtins.SERVER_MODE = False"
+
+    ## Browser test ##
+
+    # don't bother to test kerberos authentication
+    python regression/runtests.py --pkg browser --exclude browser.tests.test_kerberos_with_mocking
+
+    ## Reverse engineered SQL test ##
+
+    python regression/runtests.py --pkg resql
+
+    runHook postCheck
+  '';
+
   meta = with lib; {
     description = "Administration and development platform for PostgreSQL";
     homepage = "https://www.pgadmin.org/";