def test_generic_update_view_fails_when_document_not_present(self, tv_get_document_with_exception): tv_get_document_with_exception.side_effect = NotFoundError('no picture there, friend') resp_object = tv.generic_update_view(item_id='4231', document_type='misunderstanding') tv_get_document_with_exception.assert_called_once_with('4231', 'misunderstanding') assert resp_object.status_code == 404 assert resp_object.data == '"no picture there, friend"'
def test_generic_update_view_fails_when_document_not_present( self, tv_get_document_with_exception): tv_get_document_with_exception.side_effect = NotFoundError( 'no picture there, friend') resp_object = tv.generic_update_view(item_id='4231', document_type='misunderstanding') tv_get_document_with_exception.assert_called_once_with( '4231', 'misunderstanding') assert resp_object.status_code == 404 assert resp_object.data == '"no picture there, friend"'
def test_generic_update_view_handles_non_json_data(self, tv_get_document_with_exception): tv_get_document_with_exception.return_value = {'xena': 'warrior_princess'} with current_app.test_request_context('/whatever', headers={'Content-Type':'application/not_json'}, data='{"cant_drive": "55"}'): resp_object = tv.generic_update_view(item_id='wango', document_type='tango') tv_get_document_with_exception.assert_called_once_with('wango', 'tango') assert resp_object.status_code == 409 assert resp_object.data == '"problem with update: content type is not application/json"'
def test_generic_update_view_adds_request_args_parms_to_item(self, tv_get_document_with_exception, tv_update_generic): tv_get_document_with_exception.return_value = {'e': 'd', 'thermo': 'set'} with current_app.test_request_context('/whatever', headers={'Content-Type':'application/json'}, data='{"thermo":"plastic", "monkey": "chow"}'): resp_object = tv.generic_update_view(item_id='1234', document_type='headache') assert resp_object.status_code == 200 the_dict = json.loads(resp_object.data) assert the_dict == {'thermo': 'plastic', 'monkey': 'chow', 'e': 'd'} tv_get_document_with_exception.assert_called_once_with('1234', 'headache') tv_update_generic.assert_called_once_with(the_dict, 'headache')
def test_generic_update_view_handles_non_json_data( self, tv_get_document_with_exception): tv_get_document_with_exception.return_value = { 'xena': 'warrior_princess' } with current_app.test_request_context( '/whatever', headers={'Content-Type': 'application/not_json'}, data='{"cant_drive": "55"}'): resp_object = tv.generic_update_view(item_id='wango', document_type='tango') tv_get_document_with_exception.assert_called_once_with( 'wango', 'tango') assert resp_object.status_code == 409 assert resp_object.data == '"problem with update: content type is not application/json"'
def test_generic_update_view_adds_request_args_parms_to_item( self, tv_get_document_with_exception, tv_update_generic): tv_get_document_with_exception.return_value = { 'e': 'd', 'thermo': 'set' } with current_app.test_request_context( '/whatever', headers={'Content-Type': 'application/json'}, data='{"thermo":"plastic", "monkey": "chow"}'): resp_object = tv.generic_update_view(item_id='1234', document_type='headache') assert resp_object.status_code == 200 the_dict = json.loads(resp_object.data) assert the_dict == { 'thermo': 'plastic', 'monkey': 'chow', 'e': 'd' } tv_get_document_with_exception.assert_called_once_with( '1234', 'headache') tv_update_generic.assert_called_once_with(the_dict, 'headache')
def update_snap(snap_id): ''' Updates an individual snap ''' return generic_update_view(item_id=snap_id, document_type='snap')
def update_distortion_pair(distortion_pair_id): return generic_update_view(item_id=distortion_pair_id, document_type='distortion_pair')
def update_distortion_set(distortion_set_id): return generic_update_view(item_id=distortion_set_id, document_type='distortion_set')
def update_calibration_session(calibration_session_id): return generic_update_view(item_id=calibration_session_id, document_type='calibration_session')