2024-04-27 02:16:54 +00:00
|
|
|
import ./make-test-python.nix ({ pkgs, lib, ... }:
|
2019-09-22 15:54:16 +00:00
|
|
|
|
2024-04-27 02:16:54 +00:00
|
|
|
{
|
|
|
|
name = "shiori";
|
|
|
|
meta.maintainers = with lib.maintainers; [ minijackson ];
|
2019-09-22 15:54:16 +00:00
|
|
|
|
2024-04-27 02:16:54 +00:00
|
|
|
nodes.machine = { ... }: { services.shiori.enable = true; };
|
2019-09-22 15:54:16 +00:00
|
|
|
|
2024-04-27 02:16:54 +00:00
|
|
|
testScript = let
|
|
|
|
authJSON = pkgs.writeText "auth.json" (builtins.toJSON {
|
|
|
|
username = "shiori";
|
|
|
|
password = "gopher";
|
|
|
|
owner = true;
|
|
|
|
});
|
2019-11-08 16:54:49 +00:00
|
|
|
|
2024-04-27 02:16:54 +00:00
|
|
|
insertBookmark = {
|
|
|
|
url = "http://example.org";
|
|
|
|
title = "Example Bookmark";
|
|
|
|
};
|
2019-11-08 16:54:49 +00:00
|
|
|
|
2024-04-27 02:16:54 +00:00
|
|
|
insertBookmarkJSON =
|
|
|
|
pkgs.writeText "insertBookmark.json" (builtins.toJSON insertBookmark);
|
|
|
|
in ''
|
2024-06-30 10:56:47 +00:00
|
|
|
#import json
|
2019-11-08 16:54:49 +00:00
|
|
|
|
2024-04-27 02:16:54 +00:00
|
|
|
machine.wait_for_unit("shiori.service")
|
|
|
|
machine.wait_for_open_port(8080)
|
|
|
|
machine.succeed("curl --fail http://localhost:8080/")
|
|
|
|
machine.succeed("curl --fail --location http://localhost:8080/ | grep -i shiori")
|
2019-11-08 16:54:49 +00:00
|
|
|
|
2024-06-30 10:56:47 +00:00
|
|
|
# The test code below no longer works because the API authentication has changed.
|
2019-11-08 16:54:49 +00:00
|
|
|
|
2024-06-30 10:56:47 +00:00
|
|
|
#with subtest("login"):
|
|
|
|
# auth_json = machine.succeed(
|
|
|
|
# "curl --fail --location http://localhost:8080/api/login "
|
|
|
|
# "-X POST -H 'Content-Type:application/json' -d @${authJSON}"
|
|
|
|
# )
|
|
|
|
# auth_ret = json.loads(auth_json)
|
|
|
|
# session_id = auth_ret["session"]
|
2019-11-08 16:54:49 +00:00
|
|
|
|
2024-06-30 10:56:47 +00:00
|
|
|
#with subtest("bookmarks"):
|
|
|
|
# with subtest("first use no bookmarks"):
|
|
|
|
# bookmarks_json = machine.succeed(
|
|
|
|
# (
|
|
|
|
# "curl --fail --location http://localhost:8080/api/bookmarks "
|
|
|
|
# "-H 'X-Session-Id:{}'"
|
|
|
|
# ).format(session_id)
|
|
|
|
# )
|
2019-11-08 16:54:49 +00:00
|
|
|
|
2024-06-30 10:56:47 +00:00
|
|
|
# if json.loads(bookmarks_json)["bookmarks"] != []:
|
|
|
|
# raise Exception("Shiori have a bookmark on first use")
|
2019-11-08 16:54:49 +00:00
|
|
|
|
2024-06-30 10:56:47 +00:00
|
|
|
# with subtest("insert bookmark"):
|
|
|
|
# machine.succeed(
|
|
|
|
# (
|
|
|
|
# "curl --fail --location http://localhost:8080/api/bookmarks "
|
|
|
|
# "-X POST -H 'X-Session-Id:{}' "
|
|
|
|
# "-H 'Content-Type:application/json' -d @${insertBookmarkJSON}"
|
|
|
|
# ).format(session_id)
|
|
|
|
# )
|
2019-11-08 16:54:49 +00:00
|
|
|
|
2024-06-30 10:56:47 +00:00
|
|
|
# with subtest("get inserted bookmark"):
|
|
|
|
# bookmarks_json = machine.succeed(
|
|
|
|
# (
|
|
|
|
# "curl --fail --location http://localhost:8080/api/bookmarks "
|
|
|
|
# "-H 'X-Session-Id:{}'"
|
|
|
|
# ).format(session_id)
|
|
|
|
# )
|
2019-11-08 16:54:49 +00:00
|
|
|
|
2024-06-30 10:56:47 +00:00
|
|
|
# bookmarks = json.loads(bookmarks_json)["bookmarks"]
|
|
|
|
# if len(bookmarks) != 1:
|
|
|
|
# raise Exception("Shiori didn't save the bookmark")
|
|
|
|
|
|
|
|
# bookmark = bookmarks[0]
|
|
|
|
# if (
|
|
|
|
# bookmark["url"] != "${insertBookmark.url}"
|
|
|
|
# or bookmark["title"] != "${insertBookmark.title}"
|
|
|
|
# ):
|
|
|
|
# raise Exception("Inserted bookmark doesn't have same URL or title")
|
2024-04-27 02:16:54 +00:00
|
|
|
'';
|
|
|
|
})
|