1 import ./make-test-python.nix ({ pkgs, ... }:
3 ankiSyncTest = pkgs.writeScript "anki-sync-test.py" ''
4 #!${pkgs.python3}/bin/python
8 # get site paths from anki itself
9 from runpy import run_path
10 run_path("${pkgs.anki}/bin/.anki-wrapped")
13 col = anki.collection.Collection('test_collection')
14 endpoint = 'http://localhost:27701'
16 # Sanity check: verify bad login fails
18 col.sync_login('baduser', 'badpass', endpoint)
19 print("bad user login worked?!")
21 except anki.errors.SyncError:
24 # test logging in to users
25 col.sync_login('user', 'password', endpoint)
26 col.sync_login('passfileuser', 'passfilepassword', endpoint)
28 # Test actual sync. login apparently doesn't remember the endpoint...
29 login = col.sync_login('user', 'password', endpoint)
30 login.endpoint = endpoint
31 sync = col.sync_collection(login, False)
32 assert sync.required == sync.NO_CHANGES
33 # TODO: create an archive with server content including a test card
34 # and check we got it?
36 testPasswordFile = pkgs.writeText "anki-password" "passfilepassword";
39 name = "anki-sync-server";
40 meta = with pkgs.lib.maintainers; {
41 maintainers = [ martinetd ];
44 nodes.machine = { pkgs, ...}: {
45 services.anki-sync-server = {
49 password = "password";
51 { username = "passfileuser";
52 passwordFile = testPasswordFile;
63 with subtest("Server starts successfully"):
64 # service won't start without users
65 machine.wait_for_unit("anki-sync-server.service")
66 machine.wait_for_open_port(27701)
68 with subtest("Can sync"):
69 machine.succeed("${ankiSyncTest}")