예제 #1
0
def test_input_parameters_for_valid_image_ids(args_dict):
    # TODO consider replacing this with an get_document_with_exception, and modifying GDWE to optionally accept an error string
    if not item_exists(args_dict['img1_id'], 'picture'):  # TODO add testing for no picture id and invalid picture id
        err_msg = 'Source image 1 not found.  A valid id for a source image must be supplied to this endpoint as a get '\
                  'parameter named img1_id in order to call this endpoint'
        raise NotFoundError(err_msg)

    if not item_exists(args_dict['img2_id'], 'picture'):  # TODO add testing for no picture id and invalid picture id
        err_msg = 'Source image 2 not found.  A valid id for a source image must be supplied to this endpoint as a get '\
                  'parameter named img2_id in order to call this endpoint'
        raise NotFoundError(err_msg)
예제 #2
0
 def test_get_group_fails_when_group_not_found(self, av_get_group_document):
     av_get_group_document.side_effect = NotFoundError(
         'no group document found for 4422')
     resp_object = av.get_group('4422')
     av_get_group_document.assert_called_once_with('4422')
     assert resp_object.status_code == 404
     assert resp_object.data == '"no group document found for 4422"'
예제 #3
0
def find_picture(picture_id):
    picture_id = str(picture_id)  # deal with non-stringified UUIDs coming in
    if picture_id in current_app.db:
        picture_dict = current_app.db[picture_id]
    else:
        raise NotFoundError("picture not found for id {0}".format(picture_id))
    return picture_dict
예제 #4
0
    def test_get_group_gallery_catches_exception(self, av_get_group_document):

        av_get_group_document.side_effect = NotFoundError('no_hway')

        resp_object = av.get_group_gallery('jibba_jabba')

        av_get_group_document.assert_called_once_with('jibba_jabba')
        assert resp_object.status_code == 404
        assert resp_object.data == '"no_hway"'
예제 #5
0
    def test_get_picture_fails_as_expected(self, pv_find_picture):
        pv_find_picture.side_effect = NotFoundError('no picture there, friend')

        resp_object = pv.get_picture('4231')
        response_data_dict = json.loads(resp_object.data)

        pv_find_picture.assert_called_once_with('4231')
        assert resp_object.status_code == 404
        assert resp_object.data == '"no picture there, friend"'
예제 #6
0
파일: utils.py 프로젝트: ibivibiv/thermal
def get_document_with_exception(doc_id, document_type='any'):
    '''
    Fetches a document with the supplied id from the database.
    Throws a NotFoundError if a document of that type isn't available.  Accepts 'any' as a wildcard for document type
    '''
    # TODO add a test here for picture - it should throw FileCleanedUpException if you're trying to access a pic after cleanup
    doc_id = cast_uuid_to_string(doc_id)
    if not item_exists(doc_id, document_type):
        raise NotFoundError("No document of type {0} found for id {1}".format(document_type, doc_id))
    return get_document(doc_id)
예제 #7
0
파일: services.py 프로젝트: epodak/thermal
def get_group_document(group_id):
    if group_id == 'current':
        settings_dict = get_settings_document()
        group_id = settings_dict['current_group_id']
    if group_id in current_app.db:
        group_dict = current_app.db[group_id]
        if group_dict['type'] == 'group':
            return group_dict
    raise NotFoundError('no group document found for id {0}'.format(
        str(group_id)))
예제 #8
0
    def test_clean_up_files_catches_exception(self,
                                              av_get_document_with_exception):
        av_get_document_with_exception.side_effect = NotFoundError(
            'no snap there, friend')

        resp_object = av.clean_up_files('jibba_jabba')

        av_get_document_with_exception.assert_called_once_with(
            'jibba_jabba', document_type='snap')
        assert resp_object.status_code == 404
        assert resp_object.data == '"no snap there, friend"'
예제 #9
0
 def test_get_group_fails_when_group_not_found(
         self, av_get_group_document,
         av_get_group_document_with_child_links,
         av_get_group_document_with_child_objects):
     av_get_group_document.side_effect = NotFoundError(
         'no group document found for 4422')
     resp_object = current_app.test_client().get(
         '/api/v1/admin/groups/4422')
     av_get_group_document.assert_called_once_with('4422')
     assert resp_object.status_code == 404
     assert resp_object.data == '"no group document found for 4422"'
예제 #10
0
    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"'
예제 #11
0
    def test_generic_get_view_fails_as_expected(
            self, tv_get_document_with_exception):
        tv_get_document_with_exception.side_effect = NotFoundError(
            'no picture there, friend')

        resp_object = tv.generic_get_view(item_id='4231',
                                          document_type='misunderstanding')
        response_data_dict = json.loads(resp_object.data)

        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"'
예제 #12
0
파일: utils.py 프로젝트: ibivibiv/thermal
def get_singleton_document(doc_type):
    '''
    Fetches a document that we expect only of its type to exist
    Throws NotFoundError if there are zero or more than one of them in the db
    Throws DocumentConfigurationError if more than one of them are found
    '''
    top_level_document_dict = get_documents_from_criteria({'type': doc_type})
    if len(top_level_document_dict.keys()) > 1:
        raise DocumentConfigurationError('more than one document found of type {0}, expected singleton'.format(doc_type))
    elif len(top_level_document_dict.keys()) == 0:
        raise NotFoundError('no document found of type {0}, expected singleton'.format(doc_type))
    else:
        return top_level_document_dict[top_level_document_dict.keys()[0]]