Esempio n. 1
0
    def test_generic_save_view_handles_non_json_data(self):
        with current_app.test_request_context('/whatever',
                                              headers={'Content-Type':'application/not_json'},
                                              data='{"cant_drive": "55"}'):
            resp_object = tv.generic_save_view(args_dict={}, document_type='careless_whisper')

            assert resp_object.status_code == 409
            assert resp_object.data == '"problem with saving careless_whisper: content type is not application/json"'
Esempio n. 2
0
 def test_generic_save_view_handles_abend(self,
                                          tv_save_generic):
     tv_save_generic.side_effect = ThermalBaseError('phenomenon')
     with current_app.test_request_context('/whatever',
                                           headers={'Content-Type':'application/json'},
                                           data='{"thermo":"plastic"}'):
         resp_object = tv.generic_save_view(args_dict={'feed': 'bag'}, document_type='headache')
         assert resp_object.status_code == 400
         assert resp_object.data == '"phenomenon"'
Esempio n. 3
0
 def test_generic_save_view_handles_abend(self, tv_save_generic):
     tv_save_generic.side_effect = ThermalBaseError('phenomenon')
     with current_app.test_request_context(
             '/whatever',
             headers={'Content-Type': 'application/json'},
             data='{"thermo":"plastic"}'):
         resp_object = tv.generic_save_view(args_dict={'feed': 'bag'},
                                            document_type='headache')
         assert resp_object.status_code == 400
         assert resp_object.data == '"phenomenon"'
Esempio n. 4
0
    def test_generic_save_view_handles_non_json_data(self):
        with current_app.test_request_context(
                '/whatever',
                headers={'Content-Type': 'application/not_json'},
                data='{"cant_drive": "55"}'):
            resp_object = tv.generic_save_view(
                args_dict={}, document_type='careless_whisper')

            assert resp_object.status_code == 409
            assert resp_object.data == '"problem with saving careless_whisper: content type is not application/json"'
Esempio n. 5
0
    def test_generic_save_view_saves_document_with_args_dict_and_request_args_and_generated_id_and_generated_type(self):

        with current_app.test_request_context('/whatever',
                                              headers={'Content-Type':'application/json'},
                                              data='{"thermo":"plastic"}'):
            resp_object = tv.generic_save_view(args_dict={'feed': 'bag'}, document_type='headache')
            assert resp_object.status_code == 200
            assert json.loads(resp_object.data) == {'_id': ANY,
                                                    'type': 'headache',
                                                    'thermo': 'plastic',
                                                    '_rev': ANY,
                                                    'feed': 'bag'}
Esempio n. 6
0
    def test_generic_save_view_saves_document_with_args_dict_and_request_args_and_generated_id_and_generated_type(
            self):

        with current_app.test_request_context(
                '/whatever',
                headers={'Content-Type': 'application/json'},
                data='{"thermo":"plastic"}'):
            resp_object = tv.generic_save_view(args_dict={'feed': 'bag'},
                                               document_type='headache')
            assert resp_object.status_code == 200
            assert json.loads(resp_object.data) == {
                '_id': ANY,
                'type': 'headache',
                'thermo': 'plastic',
                '_rev': ANY,
                'feed': 'bag'
            }
Esempio n. 7
0
def save_group():
    '''
    Creates a new group record, saves it as the new current group in the settings document
    Won't let you specify _id, _rev or type
    Automatically sets settings.current_group_id to the groups id as well
    '''
    return_value = generic_save_view(args_dict=default_group_dict(), document_type='group')
    if return_value.status_code == 200:
        try:
            group_id = json.loads(return_value.data)['_id']
            settings = get_settings_document()
            settings['current_group_id'] = group_id
            save_generic(settings, 'settings')
            return return_value
        except Exception as e:
            return Response(json.dumps('error saving settings: '+e.message), status=e.status_code, mimetype='application/json')
    else:
        return return_value
Esempio n. 8
0
def create_distortion_pair():
    try:
        if 'distortion_set_id' not in request.json:
            distortion_set_id = cast_uuid_to_string(uuid.uuid4())
            request.json['distortion_set_id'] = distortion_set_id
        else:
            distortion_set_id = request.json['distortion_set_id']

        if not item_exists(distortion_set_id, 'distortion_set'):
            distortion_set_dict = {'_id': distortion_set_id, 'type': 'distortion_set'}
            save_generic(distortion_set_dict, 'distortion_set')

        # TODO add a lot more tests to the request json, we need start_x, y, end_x, y and they need to be ints, range tests, etc
        #  ^^^^^ have this be a validation function which is optionally passed to save_generic
        return_value = generic_save_view(document_type='distortion_pair')
        return return_value
    except Exception as e:
        return Response(json.dumps(e.message), status=e.status_code, mimetype='application/json')
Esempio n. 9
0
def save_group():
    '''
    Creates a new group record, saves it as the new current group in the settings document
    Won't let you specify _id, _rev or type
    Automatically sets settings.current_group_id to the groups id as well
    '''
    return_value = generic_save_view(args_dict=default_group_dict(),
                                     document_type='group')
    if return_value.status_code == 200:
        try:
            group_id = json.loads(return_value.data)['_id']
            settings = get_settings_document()
            settings['current_group_id'] = group_id
            save_generic(settings, 'settings')
            return return_value
        except Exception as e:
            return Response(json.dumps('error saving settings: ' + e.message),
                            status=e.status_code,
                            mimetype='application/json')
    else:
        return return_value
Esempio n. 10
0
def create_distortion_pair():
    try:
        if 'distortion_set_id' not in request.json:
            distortion_set_id = cast_uuid_to_string(uuid.uuid4())
            request.json['distortion_set_id'] = distortion_set_id
        else:
            distortion_set_id = request.json['distortion_set_id']

        if not item_exists(distortion_set_id, 'distortion_set'):
            distortion_set_dict = {
                '_id': distortion_set_id,
                'type': 'distortion_set'
            }
            save_generic(distortion_set_dict, 'distortion_set')

        # TODO add a lot more tests to the request json, we need start_x, y, end_x, y and they need to be ints, range tests, etc
        #  ^^^^^ have this be a validation function which is optionally passed to save_generic
        return_value = generic_save_view(document_type='distortion_pair')
        return return_value
    except Exception as e:
        return Response(json.dumps(e.message),
                        status=e.status_code,
                        mimetype='application/json')
Esempio n. 11
0
def create_distortion_set():
    return generic_save_view(document_type='distortion_set')
Esempio n. 12
0
def create_calibration_session():
    return generic_save_view(document_type='calibration_session')
Esempio n. 13
0
def create_distortion_set():
    return generic_save_view(document_type='distortion_set')
Esempio n. 14
0
def create_calibration_session():
    return generic_save_view(document_type='calibration_session')