Release NixOS 23.11
[NixPkgs.git] / nixos / tests / castopod.nix
blob4435ec617d4e673ffdf34fd5bbbf37955ad28db4
1 import ./make-test-python.nix ({ pkgs, lib, ... }:
3   name = "castopod";
4   meta = with lib.maintainers; {
5     maintainers = [ alexoundos misuzu ];
6   };
7   nodes.castopod = { nodes, ... }: {
8     networking.firewall.allowedTCPPorts = [ 80 ];
9     networking.extraHosts = ''
10       127.0.0.1 castopod.example.com
11     '';
12     services.castopod = {
13       enable = true;
14       database.createLocally = true;
15       localDomain = "castopod.example.com";
16     };
17     environment.systemPackages =
18       let
19         username = "admin";
20         email = "admin@castood.example.com";
21         password = "v82HmEp5";
22         testRunner = pkgs.writers.writePython3Bin "test-runner"
23           {
24             libraries = [ pkgs.python3Packages.selenium ];
25             flakeIgnore = [
26               "E501"
27             ];
28           } ''
29           from selenium.webdriver.common.by import By
30           from selenium.webdriver import Firefox
31           from selenium.webdriver.firefox.options import Options
32           from selenium.webdriver.support.ui import WebDriverWait
33           from selenium.webdriver.support import expected_conditions as EC
35           options = Options()
36           options.add_argument('--headless')
37           driver = Firefox(options=options)
38           try:
39               driver.implicitly_wait(20)
40               driver.get('http://castopod.example.com/cp-install')
42               wait = WebDriverWait(driver, 10)
44               wait.until(EC.title_contains("installer"))
46               driver.find_element(By.CSS_SELECTOR, '#username').send_keys(
47                   '${username}'
48               )
49               driver.find_element(By.CSS_SELECTOR, '#email').send_keys(
50                   '${email}'
51               )
52               driver.find_element(By.CSS_SELECTOR, '#password').send_keys(
53                   '${password}'
54               )
55               driver.find_element(By.XPATH, "//button[contains(., 'Finish install')]").click()
57               wait.until(EC.title_contains("Auth"))
59               driver.find_element(By.CSS_SELECTOR, '#email').send_keys(
60                   '${email}'
61               )
62               driver.find_element(By.CSS_SELECTOR, '#password').send_keys(
63                   '${password}'
64               )
65               driver.find_element(By.XPATH, "//button[contains(., 'Login')]").click()
67               wait.until(EC.title_contains("Admin dashboard"))
68           finally:
69               driver.close()
70               driver.quit()
71         '';
72       in
73       [ pkgs.firefox-unwrapped pkgs.geckodriver testRunner ];
74   };
75   testScript = ''
76     start_all()
77     castopod.wait_for_unit("castopod-setup.service")
78     castopod.wait_for_file("/run/phpfpm/castopod.sock")
79     castopod.wait_for_unit("nginx.service")
80     castopod.wait_for_open_port(80)
81     castopod.wait_until_succeeds("curl -sS -f http://castopod.example.com")
82     castopod.succeed("curl -s http://localhost/cp-install | grep 'Create your Super Admin account' > /dev/null")
84     with subtest("Create superadmin and log in"):
85         castopod.succeed("PYTHONUNBUFFERED=1 systemd-cat -t test-runner test-runner")
86   '';