3d0ddc8539
This splits update_card() into separate undoable/non-undoable ops like the change to notes in b4396b94abdeba3347d30025c5c0240d991006c9 It means that actions get a blanket 'Update Card' description - in the future we'll probably want to either add specific actions to the backend, or allow an enum or string to be passed in to describe the op. Other changes: - card.flush() can no longer be used to add new cards. Card creation is only supposed to be done in response to changes in a note's fields, and this functionality was only exposed because the card generation hadn't been migrated to the backend at that point. As far as I'm aware, only Arthur's "copy notes" add-on used this functionality, and that should be an easy fix - when the new note is added, the associated cards will be generated, and they can then be retrieved with note.cards() - tidy ups/PEP8
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
from tests.shared import getEmptyCol
|
|
|
|
|
|
def test_flags():
|
|
col = getEmptyCol()
|
|
n = col.newNote()
|
|
n["Front"] = "one"
|
|
n["Back"] = "two"
|
|
cnt = col.addNote(n)
|
|
c = n.cards()[0]
|
|
# make sure higher bits are preserved
|
|
origBits = 0b101 << 3
|
|
c.flags = origBits
|
|
c.flush()
|
|
# no flags to start with
|
|
assert c.user_flag() == 0
|
|
assert len(col.findCards("flag:0")) == 1
|
|
assert len(col.findCards("flag:1")) == 0
|
|
# set flag 2
|
|
col.set_user_flag_for_cards(2, [c.id])
|
|
c.load()
|
|
assert c.user_flag() == 2
|
|
assert c.flags & origBits == origBits
|
|
assert len(col.findCards("flag:0")) == 0
|
|
assert len(col.findCards("flag:2")) == 1
|
|
assert len(col.findCards("flag:3")) == 0
|
|
# change to 3
|
|
col.set_user_flag_for_cards(3, [c.id])
|
|
c.load()
|
|
assert c.user_flag() == 3
|
|
# unset
|
|
col.set_user_flag_for_cards(0, [c.id])
|
|
c.load()
|
|
assert c.user_flag() == 0
|
|
|
|
# should work with Cards method as well
|
|
c.set_user_flag(2)
|
|
assert c.user_flag() == 2
|
|
c.set_user_flag(3)
|
|
assert c.user_flag() == 3
|
|
c.set_user_flag(0)
|
|
assert c.user_flag() == 0
|