async def test_005_add( self ): total_count = MODEL_CLASS.count() post_data = await self.post_data_with_csrf() total_count+= 1 rsp= await self.client.post("/TABLE/add", data=post_data) self.assertEqual(rsp.status, 200) self.assertEqual(total_count, MODEL_CLASS.count())
async def test_006_delete( self ): csrf = await self.receive_csrf() model_id = self.collection[0].id total_count = MODEL_CLASS.count() rsp= await self.client.post("/TABLE/{}/delete".format(model_id), data={"csrftoken": csrf}) total_count-= 1 self.assertEqual(rsp.status, 200) self.assertEqual(total_count, MODEL_CLASS.count())
async def index(self): self.collection = MODEL_CLASS.all() return { "collection": self.collection, "fields": [MODEL_FIELD_NAMES], "controller": self }
async def test_003_edit( self ): post_data = await self.post_data_with_csrf() model_id = self.collection[0].id rsp= await self.client.post("/TABLE/{}".format(model_id), data=post_data) controller=self.app.last_controller self.assertEqual(rsp.status, 200) model=MODEL_CLASS.find(model_id) self.assertEqual(getattr(model, self.test_field), self.test_field_value)
async def test_000_index( self ): rsp= await self.client.request("GET", "/TABLE") controller=self.app.last_controller self.assertEqual(rsp.status, 200) c_ids= list(map(lambda m: m.id, controller.collection)) ids= list(map(lambda m: m.id, MODEL_CLASS.all())) self.assertEqual(ids, c_ids) self.assertEqual(len(c_ids), len(self.collection))
async def set_model(ctrl): ctrl.model = MODEL_CLASS.find((await ctrl.params())["id"]) if not ctrl.model: raise web.HTTPNotFound
def new_model(ctrl): ctrl.model = MODEL_CLASS() if not ctrl.model: raise web.HTTPNotFound