def post(self, username): # get the json from the request, it's already validated req_json = request.get_json(force=True) # validate the request data given a schema for the entity err = validate(req_json, self.schema) # if it could not be validated, return why if err: return jsonify(message=err), 400 # if everything went smootly, create the new entity UserViewMapper.to_model_from_json(req_json) # indicate success return jsonify(message=strings.API_SUCCESS), 200
def test_non_required_output(self): js = { 'username': '******', 'password': '******', } model = UserViewMapper.to_model_from_json(js) assert model.username == 'username' assert model.password == 'password' assert model.is_admin is False
def test_correct_model_output(self): js = { 'username': '******', 'password': '******', 'first_name': 'first', 'last_name': 'last', 'institution': 'university', 'email': '*****@*****.**', 'is_admin': False, } model = UserViewMapper.to_model_from_json(js) assert model.username == 'username' assert model.password == 'password' assert model.first_name == 'first' assert model.last_name == 'last' assert model.institution == 'university' assert model.email == '*****@*****.**' assert model.is_admin is False