# 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)
# 
# NASA_METADATA_PATH = os.path.join(ROOT_DIR, 'tests/data/metadata/nasa.json')


import string
import internetarchive.utils
from tests.conftest import IaRequestsMock, NASA_METADATA_PATH
        rsps.add_metadata_mock('nasa')
        it = internetarchive.utils.IdentifierListAsItems('nasa', session)
        assert it[0].identifier == 'nasa'
        assert it.nasa.identifier == 'nasa'


def test_IdentifierListAsItems_len(session):
    assert len(internetarchive.utils.IdentifierListAsItems(['foo', 'bar'], session)) == 2

# TODO: Add test of slice access to IdenfierListAsItems


def test_get_s3_xml_text():
    xml_str = ('<Error><Code>NoSuchBucket</Code>'
               '<Message>The specified bucket does not exist.</Message>'
               '<Resource>'
               'does-not-exist-! not found by Metadata::get_obj()[server]'
               '</Resource>'
               '<RequestId>d56bdc63-169b-4b4f-8c47-0fac6de39040</RequestId></Error>')

    expected_txt = internetarchive.utils.get_s3_xml_text(xml_str)
    assert expected_txt == ('The specified bucket does not exist. - does-not-exist-! '
                            'not found by Metadata::get_obj()[server]')


def test_get_file_size():
    try:
        s = internetarchive.utils.get_file_size(NASA_METADATA_PATH)
    except AttributeError as exc:
        assert "object has no attribute 'seek'" in str(exc)

# 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)
# 
# NASA_METADATA_PATH = os.path.join(ROOT_DIR, 'tests/data/metadata/nasa.json')


# Path: tests/test_utils.py
import string
import internetarchive.utils
from tests.conftest import IaRequestsMock, NASA_METADATA_PATH

        rsps.add_metadata_mock('nasa')
        it = internetarchive.utils.IdentifierListAsItems('nasa', session)
        assert it[0].identifier == 'nasa'
        assert it.nasa.identifier == 'nasa'


def test_IdentifierListAsItems_len(session):
    assert len(internetarchive.utils.IdentifierListAsItems(['foo', 'bar'], session)) == 2

# TODO: Add test of slice access to IdenfierListAsItems


def test_get_s3_xml_text():
    xml_str = ('<Error><Code>NoSuchBucket</Code>'
               '<Message>The specified bucket does not exist.</Message>'
               '<Resource>'
               'does-not-exist-! not found by Metadata::get_obj()[server]'
               '</Resource>'
               '<RequestId>d56bdc63-169b-4b4f-8c47-0fac6de39040</RequestId></Error>')

    expected_txt = internetarchive.utils.get_s3_xml_text(xml_str)
    assert expected_txt == ('The specified bucket does not exist. - does-not-exist-! '
                            'not found by Metadata::get_obj()[server]')


def test_get_file_size():
    try:
        s = internetarchive.utils.get_file_size(NASA_METADATA_PATH)
    except AttributeError as exc:
        assert "object has no attribute 'seek'" in str(exc)

    with open(NASA_METADATA_PATH) as fp: