def test_remove_tag_undo(session): tag = Tag('tag') entry = DatabaseEntry() entry.tags.append(tag) session.add(entry) session.commit() assert tag in entry.tags cmd = RemoveTag(session, entry, tag) cmd() assert tag not in entry.tags cmd.undo() assert tag in entry.tags
def test_remove_tag_undo(session): tag = Tag('tag') entry = DatabaseEntry() entry.tags.append(tag) session.add(entry) session.commit() assert tag in entry.tags cmd = RemoveTag(session, entry, tag) cmd() assert tag not in entry.tags cmd.undo() assert tag in entry.tags
def test_remove_tag_repr(session): entry = DatabaseEntry(id=8) tag = Tag('foo') expected_repr_result = ( "<RemoveTag(" "tag 'foo', " "session <sqlalchemy.orm.session.Session object at *>, " "entry id 8)>".format(id(session))) assert fnmatch.fnmatch(repr(RemoveTag(session, entry, tag)), expected_repr_result)
def test_remove_nonexisting_tag(session): cmd = RemoveTag(session, DatabaseEntry(), Tag('tag')) with pytest.raises(NonRemovableTagError): cmd()