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)
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
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
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)
def test_mnemosyne10(): deck = Deck() deck.addModel(BasicModel()) file = unicode(os.path.join(testDir, "importing/test.mem")) i = mnemosyne10.Mnemosyne10Importer(deck, file) i.doImport() assert i.total == 5 deck.close()
def test_dingsbums(): deck = Deck() deck.addModel(BasicModel()) startNumberOfFacts = deck.factCount() file = unicode(os.path.join(testDir, "importing/dingsbums.xml")) i = dingsbums.DingsBumsImporter(deck, file) i.doImport() assert 7 == i.total deck.close()
def test_supermemo_xml_01_unicode(): deck = Deck() deck.addModel(BasicModel()) file = unicode(os.path.join(testDir, "importing/supermemo1.xml")) i = supermemo_xml.SupermemoXmlImporter(deck, file) #i.META.logToStdOutput = True i.doImport() # only returning top-level elements? assert i.total == 1 deck.close()
def test_csv_tags(): deck = Deck() deck.addModel(BasicModel()) file = unicode(os.path.join(testDir, "importing/text-tags.txt")) i = csvfile.TextImporter(deck, file) i.doImport() facts = deck.db.query(Fact).all() assert len(facts) == 2 assert facts[0].tags == "baz qux" or facts[1].tags == "baz qux" deck.close()
def test_csv(): deck = Deck() deck.addModel(BasicModel()) file = unicode(os.path.join(testDir, "importing/text-2fields.txt")) i = csvfile.TextImporter(deck, file) i.doImport() # four problems - missing front, dupe front, wrong num of fields assert len(i.log) == 4 assert i.total == 5 deck.close()
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)
def test_updating(): # get the standard csv deck first deck = Deck() deck.addModel(BasicModel()) file = unicode(os.path.join(testDir, "importing/text-2fields.txt")) i = csvfile.TextImporter(deck, file) i.doImport() # now update file = unicode(os.path.join(testDir, "importing/text-update.txt")) i = csvfile.TextImporter(deck, file) # first field i.updateKey = (0, deck.currentModel.fieldModels[0].id) i.multipleCardsAllowed = False i.doImport() ans = deck.db.scalar( u"select answer from cards where question like '%食べる%'") assert "to ate" in ans # try again with tags i.updateKey = (0, deck.currentModel.fieldModels[0].id) i.mapping[1] = 0 i.doImport() deck.close()