1import ./make-test-python.nix ({ pkgs, lib, ...}:
2
3{
4 name = "shiori";
5 meta.maintainers = with lib.maintainers; [ minijackson ];
6
7 nodes.machine =
8 { ... }:
9 { services.shiori.enable = true; };
10
11 testScript = let
12 authJSON = pkgs.writeText "auth.json" (builtins.toJSON {
13 username = "shiori";
14 password = "gopher";
15 owner = true;
16 });
17
18 insertBookmark = {
19 url = "http://example.org";
20 title = "Example Bookmark";
21 };
22
23 insertBookmarkJSON = pkgs.writeText "insertBookmark.json" (builtins.toJSON insertBookmark);
24 in ''
25 import json
26
27 machine.wait_for_unit("shiori.service")
28 machine.wait_for_open_port(8080)
29 machine.succeed("curl --fail http://localhost:8080/")
30 machine.succeed("curl --fail --location http://localhost:8080/ | grep -i shiori")
31
32 with subtest("login"):
33 auth_json = machine.succeed(
34 "curl --fail --location http://localhost:8080/api/login "
35 "-X POST -H 'Content-Type:application/json' -d @${authJSON}"
36 )
37 auth_ret = json.loads(auth_json)
38 session_id = auth_ret["session"]
39
40 with subtest("bookmarks"):
41 with subtest("first use no bookmarks"):
42 bookmarks_json = machine.succeed(
43 (
44 "curl --fail --location http://localhost:8080/api/bookmarks "
45 "-H 'X-Session-Id:{}'"
46 ).format(session_id)
47 )
48
49 if json.loads(bookmarks_json)["bookmarks"] != []:
50 raise Exception("Shiori have a bookmark on first use")
51
52 with subtest("insert bookmark"):
53 machine.succeed(
54 (
55 "curl --fail --location http://localhost:8080/api/bookmarks "
56 "-X POST -H 'X-Session-Id:{}' "
57 "-H 'Content-Type:application/json' -d @${insertBookmarkJSON}"
58 ).format(session_id)
59 )
60
61 with subtest("get inserted bookmark"):
62 bookmarks_json = machine.succeed(
63 (
64 "curl --fail --location http://localhost:8080/api/bookmarks "
65 "-H 'X-Session-Id:{}'"
66 ).format(session_id)
67 )
68
69 bookmarks = json.loads(bookmarks_json)["bookmarks"]
70 if len(bookmarks) != 1:
71 raise Exception("Shiori didn't save the bookmark")
72
73 bookmark = bookmarks[0]
74 if (
75 bookmark["url"] != "${insertBookmark.url}"
76 or bookmark["title"] != "${insertBookmark.title}"
77 ):
78 raise Exception("Inserted bookmark doesn't have same URL or title")
79 '';
80})