1 import ./make-test-python.nix ({ pkgs, lib, buildDeps ? [ ], pythonEnv ? [ ], ... }:
4 This test suite replaces the typical pytestCheckHook function in python
5 packages. Pgadmin4 test suite needs a running and configured postgresql
6 server. This is why this test exists.
8 To not repeat all the python dependencies needed, this test is called directly
9 from the pgadmin4 derivation, which also passes the currently
10 used propagatedBuildInputs and any python overrides.
12 Unfortunately, there doesn't seem to be an easy way to otherwise include
13 the needed packages here.
15 Due the the needed parameters a direct call to "nixosTests.pgadmin4" fails
16 and needs to be called as "pgadmin4.tests"
21 pgadmin4SrcDir = "/pgadmin";
22 pgadmin4Dir = "/var/lib/pgadmin";
23 pgadmin4LogDir = "/var/log/pgadmin";
28 meta.maintainers = with lib.maintainers; [ gador ];
30 nodes.machine = { pkgs, ... }: {
31 imports = [ ./common/x11.nix ];
32 # needed because pgadmin 6.8 will fail, if those dependencies get updated
35 pythonPackages = pythonEnv;
39 environment.systemPackages = with pkgs; [
44 # include the same packages as in pgadmin minus speaklater3
48 # test suite package requirements
49 pythonPackages.testscenarios
50 pythonPackages.selenium
54 services.postgresql = {
57 host all all localhost trust
63 "DATABASE \"postgres\"" = "ALL PRIVILEGES";
71 machine.wait_for_unit("postgresql")
73 # pgadmin4 needs its data and log directories
75 "mkdir -p ${pgadmin4Dir} \
76 && mkdir -p ${pgadmin4LogDir} \
77 && mkdir -p ${pgadmin4SrcDir}"
81 "tar xvzf ${pkgs.pgadmin4.src} -C ${pgadmin4SrcDir}"
84 machine.wait_for_file("${pgadmin4SrcDir}/pgadmin4-${pkgs.pgadmin4.version}/README.md")
86 # set paths and config for tests
88 "cd ${pgadmin4SrcDir}/pgadmin4-${pkgs.pgadmin4.version} \
89 && cp -v web/regression/test_config.json.in web/regression/test_config.json \
90 && sed -i 's|PostgreSQL 9.4|PostgreSQL|' web/regression/test_config.json \
91 && sed -i 's|/opt/PostgreSQL/9.4/bin/|${pkgs.postgresql}/bin|' web/regression/test_config.json \
92 && sed -i 's|\"headless_chrome\": false|\"headless_chrome\": true|' web/regression/test_config.json"
95 # adapt chrome config to run within a sandbox without GUI
96 # see https://stackoverflow.com/questions/50642308/webdriverexception-unknown-error-devtoolsactiveport-file-doesnt-exist-while-t#50642913
97 # add chrome binary path. use spaces to satisfy python indention (tabs throw an error)
98 # this works for selenium 3 (currently used), but will need to be updated
99 # to work with "from selenium.webdriver.chrome.service import Service" in selenium 4
101 "cd ${pgadmin4SrcDir}/pgadmin4-${pkgs.pgadmin4.version} \
102 && sed -i '\|options.add_argument(\"--disable-infobars\")|a \ \ \ \ \ \ \ \ options.binary_location = \"${pkgs.chromium}/bin/chromium\"' web/regression/runtests.py \
103 && sed -i '\|options.add_argument(\"--no-sandbox\")|a \ \ \ \ \ \ \ \ options.add_argument(\"--headless\")' web/regression/runtests.py \
104 && sed -i '\|options.add_argument(\"--disable-infobars\")|a \ \ \ \ \ \ \ \ options.add_argument(\"--disable-dev-shm-usage\")' web/regression/runtests.py \
105 && sed -i 's|(chrome_options=options)|(executable_path=\"${pkgs.chromedriver}/bin/chromedriver\", chrome_options=options)|' web/regression/runtests.py \
106 && sed -i 's|driver_local.maximize_window()||' web/regression/runtests.py"
109 # Don't bother to test LDAP or kerberos authentification
110 with subtest("run browser test"):
112 'cd ${pgadmin4SrcDir}/pgadmin4-${pkgs.pgadmin4.version}/web \
113 && python regression/runtests.py \
115 --exclude browser.tests.test_ldap_login.LDAPLoginTestCase,browser.tests.test_ldap_login,browser.tests.test_kerberos_with_mocking'
118 # fontconfig is necessary for chromium to run
119 # https://github.com/NixOS/nixpkgs/issues/136207
120 with subtest("run feature test"):
122 'cd ${pgadmin4SrcDir}/pgadmin4-${pkgs.pgadmin4.version}/web \
123 && export FONTCONFIG_FILE=${pkgs.makeFontsConf { fontDirectories = [];}} \
124 && python regression/runtests.py --pkg feature_tests'
127 with subtest("run resql test"):
129 'cd ${pgadmin4SrcDir}/pgadmin4-${pkgs.pgadmin4.version}/web \
130 && python regression/runtests.py --pkg resql'