# Path: internetarchive/api.py
# def get_item(identifier,
#              config=None,
#              config_file=None,
#              archive_session=None,
#              debug=None,
#              http_adapter_kwargs=None,
#              request_kwargs=None):
#     """Get an :class:`Item` object.
# 
#     :type identifier: str
#     :param identifier: The globally unique Archive.org item identifier.
# 
#     :type config: dict
#     :param config: (optional) A dictionary used to configure your session.
# 
#     :type config_file: str
#     :param config_file: (optional) A path to a config file used to configure your session.
# 
#     :type archive_session: :class:`ArchiveSession`
#     :param archive_session: (optional) An :class:`ArchiveSession` object can be provided
#                             via the ``archive_session`` parameter.
# 
#     :type http_adapter_kwargs: dict
#     :param http_adapter_kwargs: (optional) Keyword arguments that
#                                 :py:class:`requests.adapters.HTTPAdapter` takes.
# 
#     :type request_kwargs: dict
#     :param request_kwargs: (optional) Keyword arguments that
#                            :py:class:`requests.Request` takes.
# 
#     Usage:
#         >>> from internetarchive import get_item
#         >>> item = get_item('nasa')
#         >>> item.item_size
#         121084
#     """
#     if not archive_session:
#         archive_session = get_session(config, config_file, debug, http_adapter_kwargs)
#     return archive_session.get_item(identifier, request_kwargs=request_kwargs)
# 
# Path: tests/conftest.py
# class IaRequestsMock(RequestsMock):
#     def add_metadata_mock(self, identifier, body=None, method=responses.GET,
#                           protocol='https?', transform_body=None):
#         url = re.compile(f'{protocol}://archive.org/metadata/{identifier}')
#         if body is None:
#             body = load_test_data_file(f'metadata/{identifier}.json')
#         if transform_body:
#             body = transform_body(body)
#         self.add(method, url, body=body, content_type='application/json')
# 
#     def mock_all_downloads(self, num_calls=1, body='test content', protocol='https?'):
#         url = re.compile(f'{protocol}://archive.org/download/.*')
#         for _ in range(6):
#             self.add(responses.GET, url, body=body)


from internetarchive.api import get_item
from tests.conftest import IaRequestsMock


def test_bad_mediatype():
    # this identifier actually has this malformed data
    ident = 'CIA-RDP96-00789R000700210007-5'
    body = '{"metadata": {"mediatype":["texts","texts"]}}'
    with IaRequestsMock() as rsps:

# Path: internetarchive/api.py
# def get_item(identifier,
#              config=None,
#              config_file=None,
#              archive_session=None,
#              debug=None,
#              http_adapter_kwargs=None,
#              request_kwargs=None):
#     """Get an :class:`Item` object.
# 
#     :type identifier: str
#     :param identifier: The globally unique Archive.org item identifier.
# 
#     :type config: dict
#     :param config: (optional) A dictionary used to configure your session.
# 
#     :type config_file: str
#     :param config_file: (optional) A path to a config file used to configure your session.
# 
#     :type archive_session: :class:`ArchiveSession`
#     :param archive_session: (optional) An :class:`ArchiveSession` object can be provided
#                             via the ``archive_session`` parameter.
# 
#     :type http_adapter_kwargs: dict
#     :param http_adapter_kwargs: (optional) Keyword arguments that
#                                 :py:class:`requests.adapters.HTTPAdapter` takes.
# 
#     :type request_kwargs: dict
#     :param request_kwargs: (optional) Keyword arguments that
#                            :py:class:`requests.Request` takes.
# 
#     Usage:
#         >>> from internetarchive import get_item
#         >>> item = get_item('nasa')
#         >>> item.item_size
#         121084
#     """
#     if not archive_session:
#         archive_session = get_session(config, config_file, debug, http_adapter_kwargs)
#     return archive_session.get_item(identifier, request_kwargs=request_kwargs)
# 
# Path: tests/conftest.py
# class IaRequestsMock(RequestsMock):
#     def add_metadata_mock(self, identifier, body=None, method=responses.GET,
#                           protocol='https?', transform_body=None):
#         url = re.compile(f'{protocol}://archive.org/metadata/{identifier}')
#         if body is None:
#             body = load_test_data_file(f'metadata/{identifier}.json')
#         if transform_body:
#             body = transform_body(body)
#         self.add(method, url, body=body, content_type='application/json')
# 
#     def mock_all_downloads(self, num_calls=1, body='test content', protocol='https?'):
#         url = re.compile(f'{protocol}://archive.org/download/.*')
#         for _ in range(6):
#             self.add(responses.GET, url, body=body)


# Path: tests/test_bad_data.py
from internetarchive.api import get_item
from tests.conftest import IaRequestsMock



def test_bad_mediatype():
    # this identifier actually has this malformed data
    ident = 'CIA-RDP96-00789R000700210007-5'
    body = '{"metadata": {"mediatype":["texts","texts"]}}'
    with IaRequestsMock() as rsps:

        rsps.add_metadata_mock(ident, body=body)