# Path: invenio_deposit/bundles.py

# 
# Path: invenio_deposit/ext.py
# class InvenioDeposit(object):
#     """Invenio-Deposit extension."""
# 
#     def __init__(self, app=None):
#         """Extension initialization."""
#         if app:
#             self.init_app(app)
# 
#     def init_app(self, app):
#         """Flask application initialization.
# 
#         Initialize the UI endpoints.  Connect all signals if
#         `DEPOSIT_REGISTER_SIGNALS` is ``True``.
# 
#         :param app: An instance of :class:`flask.Flask`.
#         """
#         self.init_config(app)
#         app.register_blueprint(ui.create_blueprint(
#             app.config['DEPOSIT_RECORDS_UI_ENDPOINTS']
#         ))
#         app.extensions['invenio-deposit'] = _DepositState(app)
#         if app.config['DEPOSIT_REGISTER_SIGNALS']:
#             post_action.connect(index_deposit_after_publish, sender=app,
#                                 weak=False)
# 
#     def init_config(self, app):
#         """Initialize configuration.
# 
#         :param app: An instance of :class:`flask.Flask`.
#         """
#         app.config.setdefault(
#             'DEPOSIT_BASE_TEMPLATE',
#             app.config.get('BASE_TEMPLATE',
#                            'invenio_deposit/base.html'))
#         for k in dir(config):
#             if k.startswith('DEPOSIT_'):
#                 app.config.setdefault(k, getattr(config, k))
# 
# class InvenioDepositREST(object):
#     """Invenio-Deposit REST extension."""
# 
#     def __init__(self, app=None):
#         """Extension initialization.
# 
#         :param app: An instance of :class:`flask.Flask`.
#         """
#         if app:
#             self.init_app(app)
# 
#     def init_app(self, app):
#         """Flask application initialization.
# 
#         Initialize the REST endpoints.  Connect all signals if
#         `DEPOSIT_REGISTER_SIGNALS` is True.
# 
#         :param app: An instance of :class:`flask.Flask`.
#         """
#         self.init_config(app)
#         blueprint = rest.create_blueprint(
#             app.config['DEPOSIT_REST_ENDPOINTS']
#         )
# 
#         # FIXME: This is a temporary fix. This means that
#         # invenio-records-rest's endpoint_prefixes cannot be used before
#         # the first request or in other processes, ex: Celery tasks.
#         @app.before_first_request
#         def extend_default_endpoint_prefixes():
#             """Extend redirects between PID types."""
#             endpoint_prefixes = utils.build_default_endpoint_prefixes(
#                 dict(app.config['DEPOSIT_REST_ENDPOINTS'])
#             )
#             current_records_rest = app.extensions['invenio-records-rest']
#             overlap = set(endpoint_prefixes.keys()) & set(
#                 current_records_rest.default_endpoint_prefixes
#             )
#             if overlap:
#                 raise RuntimeError(
#                     'Deposit wants to override endpoint prefixes {0}.'.format(
#                         ', '.join(overlap)
#                     )
#                 )
#             current_records_rest.default_endpoint_prefixes.update(
#                 endpoint_prefixes
#             )
# 
#         app.register_blueprint(blueprint)
#         app.extensions['invenio-deposit-rest'] = _DepositState(app)
#         if app.config['DEPOSIT_REGISTER_SIGNALS']:
#             post_action.connect(index_deposit_after_publish, sender=app,
#                                 weak=False)
# 
#     def init_config(self, app):
#         """Initialize configuration.
# 
#         :param app: An instance of :class:`flask.Flask`.
#         """
#         for k in dir(config):
#             if k.startswith('DEPOSIT_'):
#                 app.config.setdefault(k, getattr(config, k))
# 
# Path: invenio_deposit/proxies.py



from copy import deepcopy
from flask import Flask, render_template_string
from invenio_records_rest import InvenioRecordsREST
from invenio_records_rest.utils import PIDConverter
from invenio_deposit import InvenioDeposit, InvenioDepositREST, bundles
from invenio_deposit.proxies import current_deposit
    from invenio_deposit import __version__
import pytest
def test_init():
    """Test extension initialization."""
    app = Flask('testapp')
    app.url_map.converters['pid'] = PIDConverter
    ext = InvenioDeposit(app)
    assert 'invenio-deposit' in app.extensions

    app = Flask('testapp')
    app.url_map.converters['pid'] = PIDConverter

    # check that current_deposit cannot be resolved
    with app.app_context():
        with pytest.raises(KeyError):
            current_deposit.app

    ext = InvenioDeposit()
    assert 'invenio-deposit' not in app.extensions
    ext.init_app(app)
    assert 'invenio-deposit' in app.extensions

    # check that current_deposit resolves correctly
    with app.app_context():
        current_deposit.app


def test_conflict_in_endpoint_prefixes():
    """Test conflict in endpoint prefixes."""
    app = Flask('testapp')
    app.url_map.converters['pid'] = PIDConverter
    InvenioRecordsREST(app)

# Path: invenio_deposit/bundles.py

# 
# Path: invenio_deposit/ext.py
# class InvenioDeposit(object):
#     """Invenio-Deposit extension."""
# 
#     def __init__(self, app=None):
#         """Extension initialization."""
#         if app:
#             self.init_app(app)
# 
#     def init_app(self, app):
#         """Flask application initialization.
# 
#         Initialize the UI endpoints.  Connect all signals if
#         `DEPOSIT_REGISTER_SIGNALS` is ``True``.
# 
#         :param app: An instance of :class:`flask.Flask`.
#         """
#         self.init_config(app)
#         app.register_blueprint(ui.create_blueprint(
#             app.config['DEPOSIT_RECORDS_UI_ENDPOINTS']
#         ))
#         app.extensions['invenio-deposit'] = _DepositState(app)
#         if app.config['DEPOSIT_REGISTER_SIGNALS']:
#             post_action.connect(index_deposit_after_publish, sender=app,
#                                 weak=False)
# 
#     def init_config(self, app):
#         """Initialize configuration.
# 
#         :param app: An instance of :class:`flask.Flask`.
#         """
#         app.config.setdefault(
#             'DEPOSIT_BASE_TEMPLATE',
#             app.config.get('BASE_TEMPLATE',
#                            'invenio_deposit/base.html'))
#         for k in dir(config):
#             if k.startswith('DEPOSIT_'):
#                 app.config.setdefault(k, getattr(config, k))
# 
# class InvenioDepositREST(object):
#     """Invenio-Deposit REST extension."""
# 
#     def __init__(self, app=None):
#         """Extension initialization.
# 
#         :param app: An instance of :class:`flask.Flask`.
#         """
#         if app:
#             self.init_app(app)
# 
#     def init_app(self, app):
#         """Flask application initialization.
# 
#         Initialize the REST endpoints.  Connect all signals if
#         `DEPOSIT_REGISTER_SIGNALS` is True.
# 
#         :param app: An instance of :class:`flask.Flask`.
#         """
#         self.init_config(app)
#         blueprint = rest.create_blueprint(
#             app.config['DEPOSIT_REST_ENDPOINTS']
#         )
# 
#         # FIXME: This is a temporary fix. This means that
#         # invenio-records-rest's endpoint_prefixes cannot be used before
#         # the first request or in other processes, ex: Celery tasks.
#         @app.before_first_request
#         def extend_default_endpoint_prefixes():
#             """Extend redirects between PID types."""
#             endpoint_prefixes = utils.build_default_endpoint_prefixes(
#                 dict(app.config['DEPOSIT_REST_ENDPOINTS'])
#             )
#             current_records_rest = app.extensions['invenio-records-rest']
#             overlap = set(endpoint_prefixes.keys()) & set(
#                 current_records_rest.default_endpoint_prefixes
#             )
#             if overlap:
#                 raise RuntimeError(
#                     'Deposit wants to override endpoint prefixes {0}.'.format(
#                         ', '.join(overlap)
#                     )
#                 )
#             current_records_rest.default_endpoint_prefixes.update(
#                 endpoint_prefixes
#             )
# 
#         app.register_blueprint(blueprint)
#         app.extensions['invenio-deposit-rest'] = _DepositState(app)
#         if app.config['DEPOSIT_REGISTER_SIGNALS']:
#             post_action.connect(index_deposit_after_publish, sender=app,
#                                 weak=False)
# 
#     def init_config(self, app):
#         """Initialize configuration.
# 
#         :param app: An instance of :class:`flask.Flask`.
#         """
#         for k in dir(config):
#             if k.startswith('DEPOSIT_'):
#                 app.config.setdefault(k, getattr(config, k))
# 
# Path: invenio_deposit/proxies.py



# Path: tests/test_invenio_deposit.py
from copy import deepcopy
from flask import Flask, render_template_string
from invenio_records_rest import InvenioRecordsREST
from invenio_records_rest.utils import PIDConverter
from invenio_deposit import InvenioDeposit, InvenioDepositREST, bundles
from invenio_deposit.proxies import current_deposit
    from invenio_deposit import __version__
import pytest

def test_init():
    """Test extension initialization."""
    app = Flask('testapp')
    app.url_map.converters['pid'] = PIDConverter
    ext = InvenioDeposit(app)
    assert 'invenio-deposit' in app.extensions

    app = Flask('testapp')
    app.url_map.converters['pid'] = PIDConverter

    # check that current_deposit cannot be resolved
    with app.app_context():
        with pytest.raises(KeyError):
            current_deposit.app

    ext = InvenioDeposit()
    assert 'invenio-deposit' not in app.extensions
    ext.init_app(app)
    assert 'invenio-deposit' in app.extensions

    # check that current_deposit resolves correctly
    with app.app_context():
        current_deposit.app


def test_conflict_in_endpoint_prefixes():
    """Test conflict in endpoint prefixes."""
    app = Flask('testapp')
    app.url_map.converters['pid'] = PIDConverter
    InvenioRecordsREST(app)

    ext = InvenioDepositREST()