Esempio n. 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
Esempio n. 2
0
def setup_local(loadDecks=None):
    global deck1, deck2, client, server
    if loadDecks:
        deck1 = Deck(loadDecks[0], backup=False)
        deck2 = Deck(loadDecks[1], backup=False)
    else:
        deck1 = Deck()
        deck1.addModel(BasicModel())
        deck1.currentModel.cardModels[1].active = True
        deck1.newCardOrder = 1
        f = deck1.newFact()
        f['Front'] = u"foo"; f['Back'] = u"bar"; f.tags = u"foo"
        deck1.addFact(f)
        deck2 = Deck()
        deck2.addModel(BasicModel())
        deck2.currentModel.cardModels[1].active = True
        f = deck2.newFact()
        f['Front'] = u"baz"; f['Back'] = u"qux"; f.tags = u"bar"
        deck2.addFact(f)
        deck2.newCardOrder = 1
    # normally such syncs would trigger a conflict, but we ignore it
    deck1.setVar("schemaMod", 0)
    deck2.setVar("schemaMod", 0)
    client = SyncClient(deck1)
    server = SyncServer(deck2)
    client.setServer(server)
Esempio n. 3
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
Esempio n. 4
0
def setup_local(loadDecks=None):
    global deck1, deck2, client, server
    if loadDecks:
        deck1 = Deck(loadDecks[0], backup=False)
        deck2 = Deck(loadDecks[1], backup=False)
    else:
        deck1 = Deck()
        deck1.addModel(BasicModel())
        deck1.currentModel.cardModels[1].active = True
        deck1.newCardOrder = 1
        f = deck1.newFact()
        f['Front'] = u"foo"
        f['Back'] = u"bar"
        f.tags = u"foo"
        deck1.addFact(f)
        deck2 = Deck()
        deck2.addModel(BasicModel())
        deck2.currentModel.cardModels[1].active = True
        f = deck2.newFact()
        f['Front'] = u"baz"
        f['Back'] = u"qux"
        f.tags = u"bar"
        deck2.addFact(f)
        deck2.newCardOrder = 1
    # normally such syncs would trigger a conflict, but we ignore it
    deck1.setVar("schemaMod", 0)
    deck2.setVar("schemaMod", 0)
    client = SyncClient(deck1)
    server = SyncServer(deck2)
    client.setServer(server)
Esempio n. 5
0
def setup1():
    global deck
    deck = Deck()
    deck.addModel(BasicModel())
    deck.currentModel.cardModels[1].active = True
    f = deck.newFact()
    f['Front'] = u"foo"; f['Back'] = u"bar"; f.tags = u"tag, tag2"
    deck.addFact(f)
    f = deck.newFact()
    f['Front'] = u"baz"; f['Back'] = u"qux"
    deck.addFact(f)
Esempio n. 6
0
def setup_local(loadDecks=None):
    global deck1, deck2, client, server
    if loadDecks:
        deck1 = Deck(loadDecks[0], backup=False)
        deck2 = Deck(loadDecks[1], backup=False)
    else:
        deck1 = getEmptyDeck()
        f = deck1.newFact()
        f['Front'] = u"foo"; f['Back'] = u"bar"; f.tags = [u"foo"]
        deck1.addFact(f)
        deck1.syncName = "abc"
        deck2 = getEmptyDeck()
        f = deck2.newFact()
        f['Front'] = u"foo"; f['Back'] = u"bar"; f.tags = [u"foo"]
        deck2.addFact(f)
        deck2.syncName = "abc"
        deck1.lastSync = deck2.lastSync = intTime()
        deck1.scm = deck2.scm = 0
        time.sleep(1)
        # now add another fact to deck1 that hasn't been synced yet
        f = deck1.newFact()
        f['Front'] = u"bar"; f['Back'] = u"baz"
        deck1.addFact(f)
        # and another to deck2
        f = deck2.newFact()
        f['Front'] = u"qux"; f['Back'] = u"baz"
        deck2.addFact(f)
        deck2.reset()
        c = deck2.sched.getCard()
        deck2.sched.answerCard(c, 3)
        # change deck1's model
        deck1.currentModel().flush()
        deck1.save(); deck2.save()
    client = SyncClient(deck1)
    server = SyncServer(deck2)
    print "deck1", client.deck.db.all("select * from facts")
    print "deck2", server.deck.db.all("select * from facts")
    client.setServer(server)