Exemplo n.º 1
0
def test_anki10_modtime():
    deck1 = DeckStorage.Deck()
    deck2 = DeckStorage.Deck()
    client = SyncClient(deck1)
    server = SyncServer(deck2)
    client.setServer(server)
    deck1.addModel(BasicModel())
    f = deck1.newFact()
    f['Front'] = u"foo"; f['Back'] = u"bar"
    deck1.addFact(f)
    assert deck1.cardCount == 1
    assert deck2.cardCount == 0
    client.sync()
    assert deck1.cardCount == 1
    assert deck2.cardCount == 1
    file_ = unicode(os.path.join(testDir, "importing/test10-3.anki"))
    file = "/tmp/test10-3.anki"
    shutil.copy(file_, file)
    i = anki10.Anki10Importer(deck1, file)
    i.doImport()
    client.sync()
    assert i.total == 1
    assert deck2.s.scalar("select count(*) from cards") == 2
    assert deck2.s.scalar("select count(*) from facts") == 2
    assert deck2.s.scalar("select count(*) from models") == 2
Exemplo n.º 2
0
def test_anki10_modtime():
    deck1 = Deck()
    deck2 = Deck()
    client = SyncClient(deck1)
    server = SyncServer(deck2)
    client.setServer(server)
    deck1.addModel(BasicModel())
    f = deck1.newFact()
    f['Front'] = u"foo"
    f['Back'] = u"bar"
    deck1.addFact(f)
    assert deck1.cardCount() == 1
    assert deck2.cardCount() == 0
    client.sync()
    assert deck1.cardCount() == 1
    assert deck2.cardCount() == 1
    file_ = unicode(os.path.join(testDir, "importing/test10-3.anki"))
    file = "/tmp/test10-3.anki"
    shutil.copy(file_, file)
    i = anki10.Anki10Importer(deck1, file)
    i.doImport()
    client.sync()
    assert i.total == 1
    assert deck2.db.scalar("select count(*) from cards") == 2
    assert deck2.db.scalar("select count(*) from facts") == 2
    assert deck2.db.scalar("select count(*) from models") == 2
Exemplo n.º 3
0
def test_localsync_threeway():
    # deck1 (client) <-> deck2 (server) <-> deck3 (client)
    deck3 = DeckStorage.Deck()
    client2 = SyncClient(deck3)
    server2 = SyncServer(deck2)
    client2.setServer(server2)
    client.sync()
    client2.sync()
    # add a new question
    f = deck1.newFact()
    f['Front'] = u"a"; f['Back'] = u"b"
    f = deck1.addFact(f)
    card = f.cards[0]
    client.sync()
    assert deck1.cardCount == 6
    assert deck2.cardCount == 6
    # check it propagates from server to deck3
    client2.sync()
    assert deck3.cardCount == 6
    # delete a card on deck1
    deck1.deleteCard(card.id)
    client.sync()
    assert deck1.cardCount == 5
    assert deck2.cardCount == 5
    # make sure the delete is now propagated from the server to deck3
    client2.sync()
    assert deck3.cardCount == 5
Exemplo n.º 4
0
def test_localsync_threeway():
    # deck1 (client) <-> deck2 (server) <-> deck3 (client)
    deck3 = DeckStorage.Deck()
    client2 = SyncClient(deck3)
    server2 = SyncServer(deck2)
    client2.setServer(server2)
    client.sync()
    client2.sync()
    # add a new question
    f = deck1.newFact()
    f['Front'] = u"a"
    f['Back'] = u"b"
    f = deck1.addFact(f)
    card = f.cards[0]
    client.sync()
    assert deck1.cardCount == 6
    assert deck2.cardCount == 6
    # check it propagates from server to deck3
    client2.sync()
    assert deck3.cardCount == 6
    # delete a card on deck1
    deck1.deleteCard(card.id)
    client.sync()
    assert deck1.cardCount == 5
    assert deck2.cardCount == 5
    # make sure the delete is now propagated from the server to deck3
    client2.sync()
    assert deck3.cardCount == 5