def test_delete_qa(fn_params, col_tuple): "Test that we can delete a previously imported question and answer." _sync_note_with_edits(fn_params, col_tuple, "BasicQuestionAndAnswer") assert len(col_tuple.col.find_notes("")) == 1 userlog = sync(set(), col_tuple.col, 'Default') assert not col_tuple.col.find_notes("") assert 'Removed 1 note' in userlog
def test_add_with_scheduling(col_tuple): """ Check that we can add a manually created note with scheduling information. """ days_until_due = 4 sched_param = { 'due': datetime.datetime.now().date() + datetime.timedelta(days=days_until_due), 'ivl': 5, 'ease': 1800, 'lapses': 1 } n = QuestionNote(id_="20200101120000000", wiki=Wiki("MyTestWiki", Path("."), Path("."), WikiType.FOLDER), tidref="TestTiddler", question="Does this question get correctly scheduled?", answer="I hope so", target_tags="", target_deck="Default", schedule=SchedulingInfo(**sched_param)) sync((n, ), col_tuple.col, 'Default') anki_notes = col_tuple.col.find_notes("") assert len(anki_notes) == 1 anki_note = col_tuple.col.getNote(anki_notes[0]) assert anki_note.fields[0] == "Does this question get correctly scheduled?" card = col_tuple.col.get_card( col_tuple.col.find_cards(f"nid:{anki_note.id}")[0]) assert card.factor == sched_param['ease'] assert card.lapses == sched_param['lapses'] assert card.ivl == sched_param['ivl'] assert card.due == days_until_due
def _sync_note_with_edits(fn_params, col_tuple, from_tiddler: str, edit_callable: Callable = None) -> str: fn_params['filter_'] = from_tiddler os.chdir(col_tuple.cwd) notes = find_notes(**fn_params) assert len(notes) == 1 if edit_callable is not None: note = notes.pop() edit_callable(note) notes.add(note) return sync(notes, col_tuple.col, 'Default')
def test_import_qa(fn_params, col_tuple): "Test that we can import a simple question and answer into Anki." # Arguably it might be better for separation of concerns to create a TwNote # manually here instead of importing it from TiddlyWiki. For now, this is # easier and gives a more complete integration test, so given the limited testing # I currently have time to put in here, I think this is a smarter choice. fn_params['filter_'] = "BasicQuestionAndAnswer" os.chdir(col_tuple.cwd) notes = find_notes(**fn_params) # sanity check assert len(notes) == 1 anki_notes = col_tuple.col.find_notes("") assert len(anki_notes) == 0 userlog = sync(notes, col_tuple.col, 'Default') assert 'Added 1 note' in userlog anki_notes = col_tuple.col.find_notes("") assert len(anki_notes) == 1 anki_note = col_tuple.col.getNote(anki_notes[0]) assert anki_note.fields[0] == "What is TiddlyRemember good for?"