async def post(self): async with self.request.app['db'].acquire() as conn: if self.request.content_type == 'application/json': data = await self.request.json() else: data = await self.request.post() validated_data = profile_schema.load(data) profile = await insert_object(conn, Profile, validated_data) result = profile_schema.dump(profile) return web.json_response(result, status=201)
async def update(self, partial): async with self.request.app['db'].acquire() as conn: if self.request.content_type == 'application/json': data = await self.request.json() else: data = await self.request.post() profile_id = self.request.match_info['profile_id'] validated_data = profile_schema.load(data, partial=partial) profile = await update_object_by_id(conn, Profile, profile_id, validated_data) result = profile_schema.dump(profile) return web.json_response(result)
async def test_profiles_detail_view_200(self): async with self.app['db'].acquire() as conn: validated_data = profile_schema.load({ 'firstname': 'ivan', 'surname': 'petrov', 'birthdate': '1990-02-04', 'user_id': 2001 }) profile = await insert_object(conn, Profile, validated_data) pr = profile_schema.dump(profile) headers = {'Authorization': f'Bearer {self.admin_access_token}'} resp = await self.client.get(f'/profiles/{pr["id"]}', headers=headers) assert resp.status == 200
async def test_profiles_detail_patch_200(self): async with self.app['db'].acquire() as conn: validated_data = profile_schema.load({ 'firstname': 'ivan', 'surname': 'smirnov', 'birthdate': '1990-02-04', 'user_id': 2004 }) profile = await insert_object(conn, Profile, validated_data) pr = profile_schema.dump(profile) headers = { 'Authorization': f'Bearer {self.admin_access_token}', 'Content-Type': 'application/json' } data = { 'birthdate': '1994-02-04', } resp = await self.client.patch(f'/profiles/{pr["id"]}', headers=headers, data=json.dumps(data)) assert resp.status == 200
async def delete(self): async with self.request.app['db'].acquire() as conn: profile_id = self.request.match_info['profile_id'] profile = await delete_object_by_id(conn, Profile, profile_id) result = profile_schema.dump(profile) return web.json_response(result)
async def get(self): async with self.request.app['db'].acquire() as conn: profiles = await get_objects(conn, Profile) result = profile_schema.dump(profiles, many=True) return web.json_response(result)