1 import ./make-test-python.nix (
4 name = "tandoor-recipes-script-name";
9 services.tandoor-recipes = {
12 SCRIPT_NAME = "/any/path";
13 STATIC_URL = "${nodes.machine.services.tandoor-recipes.extraConfig.SCRIPT_NAME}/static/";
21 inherit (nodes.machine.services.tandoor-recipes) address port;
22 inherit (nodes.machine.services.tandoor-recipes.extraConfig) SCRIPT_NAME;
25 from html.parser import HTMLParser
27 origin_url = "http://${address}:${toString port}"
28 base_url = f"{origin_url}${SCRIPT_NAME}"
29 login_path = "/admin/login/"
30 login_url = f"{base_url}{login_path}"
32 cookie_jar_path = "/tmp/cookies.txt"
33 curl = f"curl --cookie {cookie_jar_path} --cookie-jar {cookie_jar_path} --fail --header 'Origin: {origin_url}' --show-error --silent"
35 print("Wait for the service to respond")
36 machine.wait_for_unit("tandoor-recipes.service")
37 machine.wait_until_succeeds(f"{curl} {login_url}")
42 print("Create admin user")
44 f"DJANGO_SUPERUSER_PASSWORD='{password}' /var/lib/tandoor-recipes/tandoor-recipes-manage createsuperuser --no-input --username='{username}' --email=nobody@example.com"
47 print("Get CSRF token for later requests")
48 csrf_token = machine.succeed(f"grep csrftoken {cookie_jar_path} | cut --fields=7").rstrip()
50 print("Log in as admin user")
52 f"{curl} --data 'csrfmiddlewaretoken={csrf_token}' --data 'username={username}' --data 'password={password}' {login_url}"
55 print("Get the contents of the logged in main page")
56 logged_in_page = machine.succeed(f"{curl} --location {base_url}")
58 class UrlParser(HTMLParser):
62 self.urls: list[str] = []
64 def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None:
66 for name, value in attrs:
67 if name == "action" and value is not None:
68 assert not value.endswith(login_path)
74 for name, value in attrs:
75 if name == "href" and value is not None:
76 if value.startswith(base_url):
77 self.urls.append(value)
78 elif value.startswith("/"):
79 self.urls.append(f"{origin_url}{value}")
81 print(f"Ignoring non-path URL: {value}")
86 parser.feed(logged_in_page)
88 for url in parser.urls:
89 with subtest(f"Verify that {url} can be reached"):
90 machine.succeed(f"{curl} {url}")
93 meta.maintainers = with lib.maintainers; [ l0b0 ];