def test_metrics_empty_dates(self):
request = {
'start_date': '',
'end_date': ''
}
with self.assertRaises(HttpException) as cm:
self.client.request_json('Metrics', 'POST', request)
self.assertEqual(cm.exception.code, httplib.BAD_REQUEST)
python类BAD_REQUEST的实例源码
physical_measurements_api_test.py 文件源码
项目:raw-data-repository
作者: all-of-us
项目源码
文件源码
阅读 15
收藏 0
点赞 0
评论 0
def test_insert_before_consent_fails(self):
measurements_1 = load_measurement_json(self.participant_id)
path_1 = 'Participant/%s/PhysicalMeasurements' % self.participant_id
self.send_post(path_1, measurements_1, expected_status=httplib.BAD_REQUEST)
def test_update_no_ifmatch_specified(self):
response = self.send_post('Participant', self.participant)
# Change the provider link for the participant
participant_id = response['participantId']
response['providerLink'] = [ self.provider_link_2 ]
path = 'Participant/%s' % participant_id
self.send_put(path, response, expected_status=httplib.BAD_REQUEST)
def test_update_bad_ifmatch_specified(self):
response = self.send_post('Participant', self.participant)
# Change the provider link for the participant
participant_id = response['participantId']
response['providerLink'] = [ self.provider_link_2 ]
path = 'Participant/%s' % participant_id
self.send_put(path, response, headers={ 'If-Match': 'Blah' },
expected_status=httplib.BAD_REQUEST)
def test_error_missing_required_fields(self):
order_json = load_biobank_order_json(self.participant.participantId)
del order_json['identifier']
self.send_post(self.path, order_json, expected_status=httplib.BAD_REQUEST)
def test_no_duplicate_test_within_order(self):
order_json = load_biobank_order_json(self.participant.participantId)
order_json['samples'].extend(list(order_json['samples']))
self.send_post(self.path, order_json, expected_status=httplib.BAD_REQUEST)
def test_update_before_insert(self):
with open(data_path('questionnaire1.json')) as f:
questionnaire = json.load(f)
self.send_put('Questionnaire/1', questionnaire, expected_status=httplib.BAD_REQUEST)
def test_update_no_ifmatch_specified(self):
response = self.insert_questionnaire()
with open(data_path('questionnaire2.json')) as f2:
questionnaire2 = json.load(f2)
self.send_put('Questionnaire/%s' % response['id'], questionnaire2,
expected_status=httplib.BAD_REQUEST)
def test_update_invalid_ifmatch_specified(self):
response = self.insert_questionnaire()
with open(data_path('questionnaire2.json')) as f2:
questionnaire2 = json.load(f2)
self.send_put('Questionnaire/%s' % response['id'], questionnaire2,
expected_status=httplib.BAD_REQUEST,
headers={ 'If-Match': 'Blah' })
def check_resp_status_and_retry(resp, image_id, url):
# Note(Jesse): This branch sorts errors into those that are permanent,
# those that are ephemeral, and those that are unexpected.
if resp.status in (httplib.BAD_REQUEST, # 400
httplib.UNAUTHORIZED, # 401
httplib.PAYMENT_REQUIRED, # 402
httplib.FORBIDDEN, # 403
httplib.METHOD_NOT_ALLOWED, # 405
httplib.NOT_ACCEPTABLE, # 406
httplib.PROXY_AUTHENTICATION_REQUIRED, # 407
httplib.CONFLICT, # 409
httplib.GONE, # 410
httplib.LENGTH_REQUIRED, # 411
httplib.PRECONDITION_FAILED, # 412
httplib.REQUEST_ENTITY_TOO_LARGE, # 413
httplib.REQUEST_URI_TOO_LONG, # 414
httplib.UNSUPPORTED_MEDIA_TYPE, # 415
httplib.REQUESTED_RANGE_NOT_SATISFIABLE, # 416
httplib.EXPECTATION_FAILED, # 417
httplib.UNPROCESSABLE_ENTITY, # 422
httplib.LOCKED, # 423
httplib.FAILED_DEPENDENCY, # 424
httplib.UPGRADE_REQUIRED, # 426
httplib.NOT_IMPLEMENTED, # 501
httplib.HTTP_VERSION_NOT_SUPPORTED, # 505
httplib.NOT_EXTENDED, # 510
):
raise PluginError("Got Permanent Error response [%i] while "
"uploading image [%s] to glance [%s]"
% (resp.status, image_id, url))
# Nova service would process the exception
elif resp.status == httplib.NOT_FOUND: # 404
exc = XenAPI.Failure('ImageNotFound')
raise exc
# NOTE(nikhil): Only a sub-set of the 500 errors are retryable. We
# optimistically retry on 500 errors below.
elif resp.status in (httplib.REQUEST_TIMEOUT, # 408
httplib.INTERNAL_SERVER_ERROR, # 500
httplib.BAD_GATEWAY, # 502
httplib.SERVICE_UNAVAILABLE, # 503
httplib.GATEWAY_TIMEOUT, # 504
httplib.INSUFFICIENT_STORAGE, # 507
):
raise RetryableError("Got Ephemeral Error response [%i] while "
"uploading image [%s] to glance [%s]"
% (resp.status, image_id, url))
else:
# Note(Jesse): Assume unexpected errors are retryable. If you are
# seeing this error message, the error should probably be added
# to either the ephemeral or permanent error list.
raise RetryableError("Got Unexpected Error response [%i] while "
"uploading image [%s] to glance [%s]"
% (resp.status, image_id, url))
def _handle_put(gcs_stub, filename, param_dict, headers, payload):
"""Handle PUT."""
if _iscopy(headers):
return _copy(gcs_stub, filename, headers)
token = _get_param('upload_id', param_dict)
content_range = _ContentRange(headers)
if _is_query_progress(content_range):
return _find_progress(gcs_stub, filename, token)
if not content_range.value:
raise ValueError('Missing header content-range.', httplib.BAD_REQUEST)
if (headers.get('x-goog-if-generation-match', None) == '0' and
gcs_stub.head_object(filename) is not None):
return _FakeUrlFetchResult(httplib.PRECONDITION_FAILED, {}, '')
if not token:
if content_range.length is None:
raise ValueError('Content-Range must have a final length.',
httplib.BAD_REQUEST)
elif not content_range.no_data and content_range.range[0] != 0:
raise ValueError('Content-Range must specify complete object.',
httplib.BAD_REQUEST)
else:
token = gcs_stub.post_start_creation(filename, headers)
try:
gcs_stub.put_continue_creation(token,
payload,
content_range.range,
content_range.length)
except ValueError, e:
return _FakeUrlFetchResult(e.args[1], {}, e.args[0])
if content_range.length is not None:
response_headers = {
'content-length': 0,
}
response_status = httplib.OK
else:
response_headers = {}
response_status = 308
return _FakeUrlFetchResult(response_status, response_headers, '')