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