nixosTests.ihatemoney: Port to python

This commit is contained in:
Jacek Galowicz 2020-01-26 16:54:53 +01:00
parent afc3d25824
commit 8f6f418e42

View File

@ -1,13 +1,5 @@
{ system ? builtins.currentSystem
, config ? {}
, pkgs ? import ../.. { inherit system config; }
}:
let let
inherit (import ../lib/testing.nix { inherit system pkgs; }) makeTest; f = backend: import ./make-test-python.nix ({ pkgs, ... }: {
in
map (
backend: makeTest {
name = "ihatemoney-${backend}"; name = "ihatemoney-${backend}";
machine = { lib, ... }: { machine = { lib, ... }: {
services.ihatemoney = { services.ihatemoney = {
@ -30,23 +22,34 @@ map (
}; };
}; };
testScript = '' testScript = ''
$machine->waitForOpenPort(8000); machine.wait_for_open_port(8000)
$machine->waitForUnit("uwsgi.service"); machine.wait_for_unit("uwsgi.service")
my $return = $machine->succeed("curl -X POST http://localhost:8000/api/projects -d 'name=yay&id=yay&password=yay&contact_email=yay\@example.com'");
die "wrong project id $return" unless "\"yay\"\n" eq $return; assert '"yay"' in machine.succeed(
my $timestamp = $machine->succeed("stat --printf %Y /var/lib/ihatemoney/secret_key"); "curl -X POST http://localhost:8000/api/projects -d 'name=yay&id=yay&password=yay&contact_email=yay\@example.com'"
my $owner = $machine->succeed("stat --printf %U:%G /var/lib/ihatemoney/secret_key"); )
die "wrong ownership for the secret key: $owner, is uwsgi running as the right user ?" unless $owner eq "ihatemoney:ihatemoney"; owner, timestamp = machine.succeed(
$machine->shutdown(); "stat --printf %U:%G___%Y /var/lib/ihatemoney/secret_key"
$machine->start(); ).split("___")
$machine->waitForOpenPort(8000); assert "ihatemoney:ihatemoney" == owner
$machine->waitForUnit("uwsgi.service");
# check that the database is really persistent with subtest("Restart machine and service"):
print $machine->succeed("curl --basic -u yay:yay http://localhost:8000/api/projects/yay"); machine.shutdown()
# check that the secret key is really persistent machine.start()
my $timestamp2 = $machine->succeed("stat --printf %Y /var/lib/ihatemoney/secret_key"); machine.wait_for_open_port(8000)
die unless $timestamp eq $timestamp2; machine.wait_for_unit("uwsgi.service")
$machine->succeed("curl http://localhost:8000 | grep ihatemoney");
with subtest("check that the database is really persistent"):
machine.succeed("curl --basic -u yay:yay http://localhost:8000/api/projects/yay")
with subtest("check that the secret key is really persistent"):
timestamp2 = machine.succeed("stat --printf %Y /var/lib/ihatemoney/secret_key")
assert timestamp == timestamp2
assert "ihatemoney" in machine.succeed("curl http://localhost:8000")
''; '';
} });
) [ "sqlite" "postgresql" ] in {
ihatemoney-sqlite = f "sqlite";
ihatemoney-postgresql = f "postgresql";
}