at 22.05-pre 2.7 kB view raw
1import ./make-test-python.nix ({ pkgs, lib, ...}: 2 3{ 4 name = "shiori"; 5 meta.maintainers = with lib.maintainers; [ minijackson ]; 6 7 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 remember = 1; # hour 16 owner = true; 17 }); 18 19 insertBookmark = { 20 url = "http://example.org"; 21 title = "Example Bookmark"; 22 }; 23 24 insertBookmarkJSON = pkgs.writeText "insertBookmark.json" (builtins.toJSON insertBookmark); 25 in '' 26 import json 27 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 -i shiori") 32 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}" 37 ) 38 auth_ret = json.loads(auth_json) 39 session_id = auth_ret["session"] 40 41 with subtest("bookmarks"): 42 with subtest("first use no bookmarks"): 43 bookmarks_json = machine.succeed( 44 ( 45 "curl --fail --location http://localhost:8080/api/bookmarks " 46 "-H 'X-Session-Id:{}'" 47 ).format(session_id) 48 ) 49 50 if json.loads(bookmarks_json)["bookmarks"] != []: 51 raise Exception("Shiori have a bookmark on first use") 52 53 with subtest("insert bookmark"): 54 machine.succeed( 55 ( 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) 60 ) 61 62 with subtest("get inserted bookmark"): 63 bookmarks_json = machine.succeed( 64 ( 65 "curl --fail --location http://localhost:8080/api/bookmarks " 66 "-H 'X-Session-Id:{}'" 67 ).format(session_id) 68 ) 69 70 bookmarks = json.loads(bookmarks_json)["bookmarks"] 71 if len(bookmarks) != 1: 72 raise Exception("Shiori didn't save the bookmark") 73 74 bookmark = bookmarks[0] 75 if ( 76 bookmark["url"] != "${insertBookmark.url}" 77 or bookmark["title"] != "${insertBookmark.title}" 78 ): 79 raise Exception("Inserted bookmark doesn't have same URL or title") 80 ''; 81})