deleteの改造
phone.py
def delete(self, id = None): if id is None: abort(404) ser = self.mc.get(id.encode('ascii')) if ser is None: abort(404) u = jsonpickle.Unpickler() phone = u.restore(ser) if not isinstance(phone, model.Phone): abort(404) query = meta.Session.query(model.Name) index = query.filter_by(phone_id = id).first() if index is None: abort(404) self.mc.delete(phone.id) meta.Session.delete(index) meta.Session.commit() return render('/derived/phone/deleted.html')
test_phone.py
def test_delete(self): """Tests that valid data is deleted from the database, that the response redirects to the view() action that a flash message is set in the session""" response = self.app.get( url = url_for(controller = 'phone', action = 'delete', id = self._id), ) mc = memcache.Client([config['app_conf']['memcachedb.servers']], debug = 0) ser = mc.get(self._id) assert ser is None assert '<p>This record has been deleted.</p>' in response query = meta.Session.query(Name) result = query.filter_by(phone_id = self._id).first() assert result is None
→gitコミット先: http://github.com/masayang/pylons-mdb/commit/ecf76f47f764576d2b04be9a3109f6f39eff8b92