Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. @api.route('/listings', methods=['POST'])
  2. @jwt_required
  3. def create_listing():
  4. payload = request.json
  5. listing = listing_svc.create(payload)
  6. return listing
  7.  
  8.  
  9. def create(payload):
  10. listing = ListingSchema().load(payload, db.session).data
  11.  
  12.  
  13. class ListingSchema(ModelSchema):
  14. id = field_for(Project, 'id', dump_only=True)
  15. creator_user_id = field_for(Project, 'creator_user_id')
  16. # ...
  17.  
  18. @pre_load
  19. def set_creator_id(self, data):
  20. current_user = flask_jwt_extended.get_current_user()
  21. data['creator_user_id'] = current_user.id
  22.  
  23. with client.application.app_context():
  24. rv = client.post('/listings',
  25. # ...
  26. )
  27.  
  28. fake_payload = {}
  29. with client.application.test_request_context('/listings', headers={'Authorization': 'Bearer ' + access_token}):
  30. create(fake_payload)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement