示例#1
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
示例#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
示例#3
0
文件: test_sync.py 项目: ChYi/libanki
def test_localsync_threeway():
    # deck1 (client) <-> deck2 (server) <-> deck3 (client)
    deck3 = 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()
    deck1.reset(); deck2.reset()
    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
示例#4
0
文件: test_sync.py 项目: ChYi/libanki
def test_localsync_threeway():
    # deck1 (client) <-> deck2 (server) <-> deck3 (client)
    deck3 = 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()
    deck1.reset()
    deck2.reset()
    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
示例#5
0
def test_export_anki():
    oldTime = deck.modified
    e = AnkiExporter(deck)
    newname = unicode(tempfile.mkstemp(prefix="ankitest")[1])
    os.unlink(newname)
    e.exportInto(newname)
    assert deck.modified == oldTime
    # connect to new deck
    d2 = Deck(newname, backup=False)
    assert d2.cardCount() == 4
    # try again, limited to a tag
    newname = unicode(tempfile.mkstemp(prefix="ankitest")[1])
    os.unlink(newname)
    e.limitTags = ['tag']
    e.exportInto(newname)
    d2 = Deck(newname, backup=False)
    assert d2.cardCount() == 2