@@ -158,8 +158,6 @@ def invalid_argument(arg):
158
158
raise ValueError ("Unexpected query variable: %s" % quoteattr (arg ))
159
159
160
160
161
- # requests
162
-
163
161
class ValidationReport (RuntimeError ):
164
162
def __init__ (self , errors_by_field ):
165
163
self .errors_by_field = errors_by_field
@@ -204,6 +202,7 @@ def _is_string_and_non_empty(value):
204
202
password = _is_string_and_non_empty ,
205
203
))
206
204
205
+
207
206
def validate_payload (definition , payload ):
208
207
args = definition (* [payload .get (field , None ) for field in definition ._fields ])
209
208
@@ -217,6 +216,7 @@ def validate_payload(definition, payload):
217
216
else :
218
217
return args
219
218
219
+
220
220
def _create_and_expose_server (server , configuration ):
221
221
app = Flask ('coreapi' )
222
222
@@ -232,26 +232,16 @@ def GET_user_username(username):
232
232
def POST_user ():
233
233
payload = request .get_json ()
234
234
235
- # unpack the payload to a series of arguments
236
235
try :
237
236
validated = validate_payload (_REQUEST_ARGS_POST_USER , payload )
238
237
except ValidationReport as vr :
239
238
return http_error_from_status_code (400 , None , vr .serialize ())
240
239
241
240
args = list (validated )
242
241
243
- try :
244
-
245
- # user_dict = canonical_user(configuration, raw_user, raw_user.keys())
246
- # except (AttributeError, IndexError, KeyError) as e:
247
- # raise http_error_from_status_code(400, None)
248
- # except Exception as e:
249
- # pass
250
-
251
- # try:
252
- createuser (configuration , args )
253
- except Exception as e :
254
- pass
242
+ ret = createuser (configuration , args )
243
+ if ret != 0 :
244
+ raise http_error_from_status_code (400 , None )
255
245
256
246
greeting = 'hello client!'
257
247
return Response (greeting , 201 )
0 commit comments