···
1
-
import ./make-test.nix ({ lib, ...}:
1
+
import ./make-test-python.nix ({ pkgs, lib, ...}:
···
{ services.shiori.enable = true; };
12
-
$machine->waitForUnit('shiori.service');
13
-
$machine->waitForOpenPort('8080');
14
-
$machine->succeed("curl --fail http://localhost:8080/");
15
-
$machine->succeed("curl --fail --location http://localhost:8080/ | grep -qi shiori");
12
+
authJSON = pkgs.writeText "auth.json" (builtins.toJSON {
13
+
username = "shiori";
14
+
password = "gopher";
15
+
remember = 1; # hour
20
+
url = "http://example.org";
21
+
title = "Example Bookmark";
24
+
insertBookmarkJSON = pkgs.writeText "insertBookmark.json" (builtins.toJSON insertBookmark);
28
+
machine.wait_for_unit("shiori.service")
29
+
machine.wait_for_open_port(8080)
30
+
machine.succeed("curl --fail http://localhost:8080/")
31
+
machine.succeed("curl --fail --location http://localhost:8080/ | grep -qi shiori")
33
+
with subtest("login"):
34
+
auth_json = machine.succeed(
35
+
"curl --fail --location http://localhost:8080/api/login "
36
+
"-X POST -H 'Content-Type:application/json' -d @${authJSON}"
38
+
auth_ret = json.loads(auth_json)
39
+
session_id = auth_ret["session"]
41
+
with subtest("bookmarks"):
42
+
with subtest("first use no bookmarks"):
43
+
bookmarks_json = machine.succeed(
45
+
"curl --fail --location http://localhost:8080/api/bookmarks "
46
+
"-H 'X-Session-Id:{}'"
47
+
).format(session_id)
50
+
if json.loads(bookmarks_json)["bookmarks"] != []:
51
+
raise Exception("Shiori have a bookmark on first use")
53
+
with subtest("insert bookmark"):
56
+
"curl --fail --location http://localhost:8080/api/bookmarks "
57
+
"-X POST -H 'X-Session-Id:{}' "
58
+
"-H 'Content-Type:application/json' -d @${insertBookmarkJSON}"
59
+
).format(session_id)
62
+
with subtest("get inserted bookmark"):
63
+
bookmarks_json = machine.succeed(
65
+
"curl --fail --location http://localhost:8080/api/bookmarks "
66
+
"-H 'X-Session-Id:{}'"
67
+
).format(session_id)
70
+
bookmarks = json.loads(bookmarks_json)["bookmarks"]
71
+
if len(bookmarks) != 1:
72
+
raise Exception("Shiori didn't save the bookmark")
74
+
bookmark = bookmarks[0]
76
+
bookmark["url"] != "${insertBookmark.url}"
77
+
or bookmark["title"] != "${insertBookmark.title}"
79
+
raise Exception("Inserted bookmark doesn't have same URL or title")