def test_add_tag_undo_unsaved_entry(session): tag = Tag('tag') entry = DatabaseEntry() cmd = AddTag(session, entry, tag) cmd() cmd.undo() assert entry.tags == [] cmd() assert tag in entry.tags
def test_add_removed_tag(session): entry = DatabaseEntry() tag = Tag('tag') entry.tags.append(tag) session.add(tag) session.commit() session.delete(tag) AddTag(session, entry, tag)() assert tag in entry.tags
def test_add_tag_repr(session): entry = DatabaseEntry(id=12) tag = Tag('spam') expected_repr_result = ( "<AddTag(" "tag 'spam', " "session <sqlalchemy.orm.session.Session object at *>, " "entry id 12)>".format(id(session))) assert fnmatch.fnmatch(repr(AddTag(session, entry, tag)), expected_repr_result)