'Test Model add, delete, edit'

def test_model_crud(self):

    client = self.app.test_client()
    rv = self.login(client, DEFAULT_ADMIN_USER, DEFAULT_ADMIN_PASSWORD)
    rv = client.post('/model1view/add', data=dict(field_string='test1', field_integer='1', field_float='0.12', field_date='2014-01-01    23:10:07'), follow_redirects=True)
    eq_(rv.status_code, 200)
    model = Model1.objects[0]
    eq_(model.field_string, u'test1')
    eq_(model.field_integer, 1)
    model1 = Model1.objects(field_string='test1')[0]
    rv = client.post('/model1view/edit/{0}'.format(model1.id), data=dict(field_string='test2', field_integer='2'), follow_redirects=True)
    eq_(rv.status_code, 200)
    model = Model1.objects[0]
    eq_(model.field_string, u'test2')
    eq_(model.field_integer, 2)
    rv = client.get('/model1view/delete/{0}'.format(model.id), follow_redirects=True)
    eq_(rv.status_code, 200)
    model = Model1.objects
    eq_(len(model), 0)
    self.clean_data()
