Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @api.route('/listings', methods=['POST'])
- @jwt_required
- def create_listing():
- payload = request.json
- listing = listing_svc.create(payload)
- return listing
- def create(payload):
- listing = ListingSchema().load(payload, db.session).data
- class ListingSchema(ModelSchema):
- id = field_for(Project, 'id', dump_only=True)
- creator_user_id = field_for(Project, 'creator_user_id')
- # ...
- @pre_load
- def set_creator_id(self, data):
- current_user = flask_jwt_extended.get_current_user()
- data['creator_user_id'] = current_user.id
- with client.application.app_context():
- rv = client.post('/listings',
- # ...
- )
- fake_payload = {}
- with client.application.test_request_context('/listings', headers={'Authorization': 'Bearer ' + access_token}):
- create(fake_payload)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement