2012-12-21 08:51:59 +01:00
|
|
|
# coding: utf-8
|
|
|
|
|
2014-06-03 10:38:47 +02:00
|
|
|
from tests.shared import getEmptyCol
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2019-12-25 05:18:34 +01:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
def test_delete():
|
2020-07-17 05:21:01 +02:00
|
|
|
col = getEmptyCol()
|
|
|
|
note = col.newNote()
|
2020-07-17 05:18:09 +02:00
|
|
|
note["Front"] = "1"
|
|
|
|
note["Back"] = "2"
|
2020-07-17 05:21:01 +02:00
|
|
|
col.addNote(note)
|
2020-07-17 05:18:09 +02:00
|
|
|
cid = note.cards()[0].id
|
2020-07-17 05:21:01 +02:00
|
|
|
col.reset()
|
|
|
|
col.sched.answerCard(col.sched.getCard(), 2)
|
|
|
|
col.remove_cards_and_orphaned_notes([cid])
|
|
|
|
assert col.cardCount() == 0
|
|
|
|
assert col.noteCount() == 0
|
|
|
|
assert col.db.scalar("select count() from notes") == 0
|
|
|
|
assert col.db.scalar("select count() from cards") == 0
|
|
|
|
assert col.db.scalar("select count() from graves") == 2
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2019-12-25 05:18:34 +01:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
def test_misc():
|
2014-06-03 10:38:47 +02:00
|
|
|
d = getEmptyCol()
|
2020-07-17 05:18:09 +02:00
|
|
|
note = d.newNote()
|
|
|
|
note["Front"] = "1"
|
|
|
|
note["Back"] = "2"
|
|
|
|
d.addNote(note)
|
|
|
|
c = note.cards()[0]
|
2019-12-25 05:18:34 +01:00
|
|
|
id = d.models.current()["id"]
|
|
|
|
assert c.template()["ord"] == 0
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
def test_genrem():
|
2014-06-03 10:38:47 +02:00
|
|
|
d = getEmptyCol()
|
2020-07-17 05:18:09 +02:00
|
|
|
note = d.newNote()
|
|
|
|
note["Front"] = "1"
|
|
|
|
note["Back"] = ""
|
|
|
|
d.addNote(note)
|
|
|
|
assert len(note.cards()) == 1
|
2012-12-21 08:51:59 +01:00
|
|
|
m = d.models.current()
|
|
|
|
mm = d.models
|
|
|
|
# adding a new template should automatically create cards
|
|
|
|
t = mm.newTemplate("rev")
|
2019-12-25 05:18:34 +01:00
|
|
|
t["qfmt"] = "{{Front}}"
|
|
|
|
t["afmt"] = ""
|
2012-12-21 08:51:59 +01:00
|
|
|
mm.addTemplate(m, t)
|
|
|
|
mm.save(m, templates=True)
|
2020-07-17 05:18:09 +02:00
|
|
|
assert len(note.cards()) == 2
|
2012-12-21 08:51:59 +01:00
|
|
|
# if the template is changed to remove cards, they'll be removed
|
2020-04-25 12:13:46 +02:00
|
|
|
t = m["tmpls"][1]
|
2019-12-25 05:18:34 +01:00
|
|
|
t["qfmt"] = "{{Back}}"
|
2012-12-21 08:51:59 +01:00
|
|
|
mm.save(m, templates=True)
|
2020-05-23 04:58:13 +02:00
|
|
|
rep = d.backend.get_empty_cards()
|
2020-07-17 06:08:33 +02:00
|
|
|
for n in rep.notes:
|
|
|
|
d.remove_cards_and_orphaned_notes(n.card_ids)
|
2020-07-17 05:18:09 +02:00
|
|
|
assert len(note.cards()) == 1
|
2012-12-21 08:51:59 +01:00
|
|
|
# if we add to the note, a card should be automatically generated
|
2020-07-17 05:18:09 +02:00
|
|
|
note.load()
|
|
|
|
note["Back"] = "1"
|
|
|
|
note.flush()
|
|
|
|
assert len(note.cards()) == 2
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2019-12-25 05:18:34 +01:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
def test_gendeck():
|
2014-06-03 10:38:47 +02:00
|
|
|
d = getEmptyCol()
|
2012-12-21 08:51:59 +01:00
|
|
|
cloze = d.models.byName("Cloze")
|
|
|
|
d.models.setCurrent(cloze)
|
2020-07-17 05:18:09 +02:00
|
|
|
note = d.newNote()
|
|
|
|
note["Text"] = "{{c1::one}}"
|
|
|
|
d.addNote(note)
|
2012-12-21 08:51:59 +01:00
|
|
|
assert d.cardCount() == 1
|
2020-07-17 05:18:09 +02:00
|
|
|
assert note.cards()[0].did == 1
|
2020-07-17 05:21:01 +02:00
|
|
|
# set the model to a new default col
|
2012-12-21 08:51:59 +01:00
|
|
|
newId = d.decks.id("new")
|
2019-12-25 05:18:34 +01:00
|
|
|
cloze["did"] = newId
|
2019-12-20 22:25:30 +01:00
|
|
|
d.models.save(cloze, updateReqs=False)
|
2020-07-17 05:21:01 +02:00
|
|
|
# a newly generated card should share the first card's col
|
2020-07-17 05:18:09 +02:00
|
|
|
note["Text"] += "{{c2::two}}"
|
|
|
|
note.flush()
|
|
|
|
assert note.cards()[1].did == 1
|
2012-12-21 08:51:59 +01:00
|
|
|
# and same with multiple cards
|
2020-07-17 05:18:09 +02:00
|
|
|
note["Text"] += "{{c3::three}}"
|
|
|
|
note.flush()
|
|
|
|
assert note.cards()[2].did == 1
|
2020-07-17 05:21:01 +02:00
|
|
|
# if one of the cards is in a different col, it should revert to the
|
2012-12-21 08:51:59 +01:00
|
|
|
# model default
|
2020-07-17 05:18:09 +02:00
|
|
|
c = note.cards()[1]
|
2012-12-21 08:51:59 +01:00
|
|
|
c.did = newId
|
|
|
|
c.flush()
|
2020-07-17 05:18:09 +02:00
|
|
|
note["Text"] += "{{c4::four}}"
|
|
|
|
note.flush()
|
|
|
|
assert note.cards()[3].did == newId
|