def test_remove_entry_repr(session): entry = DatabaseEntry(id=3) expected_repr_result = ( '<RemoveEntry(' 'session <sqlalchemy.orm.session.Session object at *>, ' 'entry <DatabaseEntry(id 3)>)>'.format(id(session))) assert fnmatch.fnmatch(repr(RemoveEntry(session, entry)), expected_repr_result)
def test_remove_existing_entry(session): entry = DatabaseEntry() session.add(entry) assert session.query(DatabaseEntry).count() == 1 assert entry.id == 1 RemoveEntry(session, entry)() assert entry in session.deleted assert session.query(DatabaseEntry).count() == 0
def test_remove_entry_undo(session): entry = DatabaseEntry() session.add(entry) cmd = RemoveEntry(session, entry) session.commit() cmd() assert session.query(DatabaseEntry).count() == 0 cmd.undo() assert session.query(DatabaseEntry).count() == 1
def test_add_removed_entry(session): entry = DatabaseEntry() AddEntry(session, entry)() session.commit() RemoveEntry(session, entry)() session.commit() AddEntry(session, entry)() session.commit() assert not session.new assert entry.id == 1
def test_remove_nonexisting_entry(session): with pytest.raises(NoSuchEntryError): RemoveEntry(session, DatabaseEntry())()