1{ system ? builtins.currentSystem,
2 config ? {},
3 pkgs ? import ../.. { inherit system config; }
4}:
5
6let
7 inherit (import ../lib/testing-python.nix { inherit system pkgs; }) makeTest;
8 f = backend: makeTest {
9 name = "ihatemoney-${backend}";
10 machine = { lib, ... }: {
11 services.ihatemoney = {
12 enable = true;
13 enablePublicProjectCreation = true;
14 inherit backend;
15 uwsgiConfig = {
16 http = ":8000";
17 };
18 };
19 boot.cleanTmpDir = true;
20 # ihatemoney needs a local smtp server otherwise project creation just crashes
21 services.opensmtpd = {
22 enable = true;
23 serverConfiguration = ''
24 listen on lo
25 action foo relay
26 match from any for any action foo
27 '';
28 };
29 };
30 testScript = ''
31 machine.wait_for_open_port(8000)
32 machine.wait_for_unit("uwsgi.service")
33 machine.wait_until_succeeds("curl http://localhost:8000")
34
35 assert '"yay"' in machine.succeed(
36 "curl -X POST http://localhost:8000/api/projects -d 'name=yay&id=yay&password=yay&contact_email=yay@example.com'"
37 )
38 owner, timestamp = machine.succeed(
39 "stat --printf %U:%G___%Y /var/lib/ihatemoney/secret_key"
40 ).split("___")
41 assert "ihatemoney:ihatemoney" == owner
42
43 with subtest("Restart machine and service"):
44 machine.shutdown()
45 machine.start()
46 machine.wait_for_open_port(8000)
47 machine.wait_for_unit("uwsgi.service")
48
49 with subtest("check that the database is really persistent"):
50 machine.succeed("curl --basic -u yay:yay http://localhost:8000/api/projects/yay")
51
52 with subtest("check that the secret key is really persistent"):
53 timestamp2 = machine.succeed("stat --printf %Y /var/lib/ihatemoney/secret_key")
54 assert timestamp == timestamp2
55
56 assert "ihatemoney" in machine.succeed("curl http://localhost:8000")
57 '';
58 };
59in {
60 ihatemoney-sqlite = f "sqlite";
61 ihatemoney-postgresql = f "postgresql";
62}