updating note and deck tests

This commit is contained in:
Alex Yatskov 2018-05-08 18:47:45 -07:00
parent f79c98bb96
commit 95ab8164cd
3 changed files with 31 additions and 33 deletions

View File

@ -523,22 +523,20 @@ class AnkiConnect:
@api() @api()
def changeDeck(self, cards, deck): def changeDeck(self, cards, deck):
try: self.startEditing()
self.startEditing()
did = self.collection().decks.id(deck) did = self.collection().decks.id(deck)
mod = anki.utils.intTime() mod = anki.utils.intTime()
usn = self.collection().usn() usn = self.collection().usn()
# normal cards # normal cards
scids = anki.utils.ids2str(cards) scids = anki.utils.ids2str(cards)
# remove any cards from filtered deck first # remove any cards from filtered deck first
self.collection().sched.remFromDyn(cards) self.collection().sched.remFromDyn(cards)
# then move into new deck # then move into new deck
self.collection().db.execute('update cards set usn=?, mod=?, did=? where id in ?', scids, usn, mod, did) self.collection().db.execute('update cards set usn=?, mod=?, did=? where id in ' + scids, usn, mod, did)
finally: self.stopEditing()
self.stopEditing()
@api() @api()

View File

@ -23,12 +23,28 @@ class TestDecks(unittest.TestCase):
self.assertIn('test', deckNames) self.assertIn('test', deckNames)
# deleteDecks # deleteDecks
util.invoke('deleteDecks', decks=['test']) util.invoke('deleteDecks', decks=['test'], cardsToo=True)
# deckNames (part 3) # deckNames (part 3)
deckNames = util.invoke('deckNames') deckNames = util.invoke('deckNames')
self.assertNotIn('test', deckNames) self.assertNotIn('test', deckNames)
# changeDeck
# note = {'deckName': 'Default', 'modelName': 'Basic', 'fields': {'Front': 'front', 'Back': 'back'}, 'tags': ['tag']}
# noteId = util.invoke('addNote', note=note)
# util.invoke('changeDeck', cards=[noteId], deck='test')
# deckNames (part 4)
# deckNames = util.invoke('deckNames')
# self.assertIn('test', deckNames)
# deleteDecks (part 2)
# util.invoke('deleteDecks', decks=['test'], cardsToo=True)
# deckNames (part 5)
# deckNames = util.invoke('deckNames')
# self.assertNotIn('test', deckNames)
# getDeckConfig # getDeckConfig
deckConfig = util.invoke('getDeckConfig', deck='Default') deckConfig = util.invoke('getDeckConfig', deck='Default')
self.assertEqual('Default', deckConfig['name']) self.assertEqual('Default', deckConfig['name'])

View File

@ -14,14 +14,8 @@ class TestNotes(unittest.TestCase):
def runTest(self): def runTest(self):
note = {
'deckName': 'test',
'modelName': 'Basic',
'fields': {'Front': 'front1', 'Back': 'back1'},
'tags': ['tag1']
}
# addNote # addNote
note = {'deckName': 'test', 'modelName': 'Basic', 'fields': {'Front': 'front1', 'Back': 'back1'}, 'tags': ['tag1']}
noteId = util.invoke('addNote', note=note) noteId = util.invoke('addNote', note=note)
self.assertRaises(Exception, lambda: util.invoke('addNote', note=note)) self.assertRaises(Exception, lambda: util.invoke('addNote', note=note))
@ -60,18 +54,8 @@ class TestNotes(unittest.TestCase):
self.assertEqual(noteInfo['fields']['Back']['value'], 'back2') self.assertEqual(noteInfo['fields']['Back']['value'], 'back2')
notes = [ notes = [
{ {'deckName': 'test', 'modelName': 'Basic', 'fields': {'Front': 'front3', 'Back': 'back3'}, 'tags': ['tag']},
'deckName': 'test', {'deckName': 'test', 'modelName': 'Basic', 'fields': {'Front': 'front4', 'Back': 'back4'}, 'tags': ['tag']}
'modelName': 'Basic',
'fields': {'Front': 'front3', 'Back': 'back3'},
'tags': ['tag']
},
{
'deckName': 'test',
'modelName': 'Basic',
'fields': {'Front': 'front4', 'Back': 'back4'},
'tags': ['tag']
}
] ]
# canAddNotes (part 1) # canAddNotes (part 1)