createのテスト追加

テストコードも直しておく。

from phonebook.model import meta, Name

#..... 
 
    def test_create(self):
        """Tests that valid data is saved to the database, that the response
        redirects to the view() action that a flash message is set in the session"""
        response = self.app.post(
            url = url_for(controller = 'phone', action = 'create'),
            params = {'mobile_number': u'Created',
                      'name': u'Created',
                      'address': u'Created',
                      'home_number': u'Created',
                      'dob': u'2000/01/01'},
            )

        from urlparse import urlparse
        path = urlparse(response.response.location).path

        from phonebook.config import routing
        m = routing.make_map()
        r = m.match(path)

        mc = memcache.Client([config['app_conf']['memcachedb.servers']], debug = 0)
        ser = mc.get(str(r['id']))

        u = Unpickler()
        c = u.restore(ser)

        assert c.__class__.__name__ == 'Phone'
        assert c.mobile_number == u'Created'
        assert c.name == u'Created'
        assert c.address == u'Created'
        assert c.home_number == u'Created'
        assert c.dob == u'2000/01/01'
        assert response.status_int == 302


        query = meta.Session.query(Name)
        result = query.filter_by(phone_id = str(r['id'])).first()
        assert result.name == u'Created' 

→gitコミット先:http://github.com/masayang/pylons-mdb/commit/28d0944e68257bf73b7f9da0ee924f606e6c7093


目次に戻る