at 23.05-pre 5.4 kB view raw
1import ./make-test-python.nix ({ pkgs, lib, buildDeps ? [ ], pythonEnv ? [ ], ... }: 2 3 /* 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. 7 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. 11 12 Unfortunately, there doesn't seem to be an easy way to otherwise include 13 the needed packages here. 14 15 Due the the needed parameters a direct call to "nixosTests.pgadmin4" fails 16 and needs to be called as "pgadmin4.tests" 17 18 */ 19 20 let 21 pgadmin4SrcDir = "/pgadmin"; 22 pgadmin4Dir = "/var/lib/pgadmin"; 23 pgadmin4LogDir = "/var/log/pgadmin"; 24 25 in 26 { 27 name = "pgadmin4"; 28 meta.maintainers = with lib.maintainers; [ gador ]; 29 30 nodes.machine = { pkgs, ... }: { 31 imports = [ ./common/x11.nix ]; 32 # needed because pgadmin 6.8 will fail, if those dependencies get updated 33 nixpkgs.overlays = [ 34 (self: super: { 35 pythonPackages = pythonEnv; 36 }) 37 ]; 38 39 environment.systemPackages = with pkgs; [ 40 pgadmin4 41 postgresql 42 chromedriver 43 chromium 44 # include the same packages as in pgadmin minus speaklater3 45 (python3.withPackages 46 (ps: buildDeps ++ 47 [ 48 # test suite package requirements 49 pythonPackages.testscenarios 50 pythonPackages.selenium 51 ]) 52 ) 53 ]; 54 services.postgresql = { 55 enable = true; 56 authentication = '' 57 host all all localhost trust 58 ''; 59 ensureUsers = [ 60 { 61 name = "postgres"; 62 ensurePermissions = { 63 "DATABASE \"postgres\"" = "ALL PRIVILEGES"; 64 }; 65 } 66 ]; 67 }; 68 }; 69 70 testScript = '' 71 machine.wait_for_unit("postgresql") 72 73 # pgadmin4 needs its data and log directories 74 machine.succeed( 75 "mkdir -p ${pgadmin4Dir} \ 76 && mkdir -p ${pgadmin4LogDir} \ 77 && mkdir -p ${pgadmin4SrcDir}" 78 ) 79 80 machine.succeed( 81 "tar xvzf ${pkgs.pgadmin4.src} -C ${pgadmin4SrcDir}" 82 ) 83 84 machine.wait_for_file("${pgadmin4SrcDir}/pgadmin4-${pkgs.pgadmin4.version}/README.md") 85 86 # set paths and config for tests 87 machine.succeed( 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" 93 ) 94 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 100 machine.succeed( 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" 107 ) 108 109 # Don't bother to test LDAP or kerberos authentification 110 with subtest("run browser test"): 111 machine.succeed( 112 'cd ${pgadmin4SrcDir}/pgadmin4-${pkgs.pgadmin4.version}/web \ 113 && python regression/runtests.py \ 114 --pkg browser \ 115 --exclude browser.tests.test_ldap_login.LDAPLoginTestCase,browser.tests.test_ldap_login,browser.tests.test_kerberos_with_mocking' 116 ) 117 118 # fontconfig is necessary for chromium to run 119 # https://github.com/NixOS/nixpkgs/issues/136207 120 with subtest("run feature test"): 121 machine.succeed( 122 'cd ${pgadmin4SrcDir}/pgadmin4-${pkgs.pgadmin4.version}/web \ 123 && export FONTCONFIG_FILE=${pkgs.makeFontsConf { fontDirectories = [];}} \ 124 && python regression/runtests.py --pkg feature_tests' 125 ) 126 127 with subtest("run resql test"): 128 machine.succeed( 129 'cd ${pgadmin4SrcDir}/pgadmin4-${pkgs.pgadmin4.version}/web \ 130 && python regression/runtests.py --pkg resql' 131 ) 132 ''; 133 })