# Path: onecodex/exceptions.py
# class OneCodexException(Exception):
#     pass
# 
# class UploadException(Exception):
#     """An exception for when things go wrong with uploading."""
# 
#     pass
# 
# Path: onecodex/lib/upload.py
# DEFAULT_THREADS = 4
# def _choose_boto3_chunksize(file_obj):
#     def __init__(self):
#     def __enter__(self):
#     def __exit__(self, *args):
#     def finish(self):
#     def update(self, size):
# def build_upload_dict(metadata, tags, project):
# def _get_init_multipart_upload_payload(
#     fobj, is_paired, metadata, tags, project, sample_id=None, external_sample_id=None
# ):
# def preupload_sample(samples_resource, metadata=None, tags=None, project=None):
# def upload_sequence(
#     file,
#     samples_resource,
#     metadata=None,
#     tags=None,
#     project=None,
#     coerce_ascii=False,
#     progressbar=None,
#     sample_id=None,
#     external_sample_id=None,
# ):
#         def cancel_atexit():
# def _upload_sequence_fileobj(file_obj, file_name, fields, samples_resource, callback=True):
# def upload_document(file_path, documents_resource, progressbar=None):
# def _upload_document_fileobj(file_obj, file_name, documents_resource):
# def _s3_intermediate_upload(file_obj, file_name, fields, session, callback_url):
# class FakeProgressBar(object):


from collections import OrderedDict
from io import BytesIO
from mock import patch
from requests_toolbelt import MultipartEncoder
from requests.exceptions import HTTPError
from onecodex.exceptions import OneCodexException, UploadException
from onecodex.lib.upload import (
    _choose_boto3_chunksize,
    FilePassthru,
    upload_document,
    _upload_document_fileobj,
    upload_sequence,
    _upload_sequence_fileobj,
)
import pytest
        sample_resource = FakeSamplesResource()
        with patch(uso) as upload_sequence_fileobj, patch(fxi) as paired, patch(fxp) as passthru:
            with patch(sz, size_effect=fake_size):
                upload_sequence(files, sample_resource)

                assert upload_sequence_fileobj.call_count == n_uploads
                assert paired.call_count == fxi_calls
                assert passthru.call_count == fxp_calls

        # Need to patch from `upload.` instead of `files.` for that test
        with patch(udo) as upload_document_fileobj, patch(
            "onecodex.lib.upload.FilePassthru"
        ) as passthru:
            with patch(sz, size_effect=fake_size):
                files = files[0] if isinstance(files, tuple) else files
                upload_document(files, FakeDocumentsResource())

                assert (
                    upload_document_fileobj.call_count == n_uploads - 1
                    if isinstance(files, tuple)
                    else n_uploads
                )
                assert passthru.call_count == fxp_calls + fxi_calls


def test_api_failures(caplog):
    with patch("boto3.session.Session"):
        files = ("tests/data/files/test_R1_L001.fq.gz", "tests/data/files/test_R2_L001.fq.gz")

        with pytest.raises(UploadException) as e:

# Path: onecodex/exceptions.py
# class OneCodexException(Exception):
#     pass
# 
# class UploadException(Exception):
#     """An exception for when things go wrong with uploading."""
# 
#     pass
# 
# Path: onecodex/lib/upload.py
# DEFAULT_THREADS = 4
# def _choose_boto3_chunksize(file_obj):
#     def __init__(self):
#     def __enter__(self):
#     def __exit__(self, *args):
#     def finish(self):
#     def update(self, size):
# def build_upload_dict(metadata, tags, project):
# def _get_init_multipart_upload_payload(
#     fobj, is_paired, metadata, tags, project, sample_id=None, external_sample_id=None
# ):
# def preupload_sample(samples_resource, metadata=None, tags=None, project=None):
# def upload_sequence(
#     file,
#     samples_resource,
#     metadata=None,
#     tags=None,
#     project=None,
#     coerce_ascii=False,
#     progressbar=None,
#     sample_id=None,
#     external_sample_id=None,
# ):
#         def cancel_atexit():
# def _upload_sequence_fileobj(file_obj, file_name, fields, samples_resource, callback=True):
# def upload_document(file_path, documents_resource, progressbar=None):
# def _upload_document_fileobj(file_obj, file_name, documents_resource):
# def _s3_intermediate_upload(file_obj, file_name, fields, session, callback_url):
# class FakeProgressBar(object):


# Path: tests/test_upload.py
from collections import OrderedDict
from io import BytesIO
from mock import patch
from requests_toolbelt import MultipartEncoder
from requests.exceptions import HTTPError
from onecodex.exceptions import OneCodexException, UploadException
from onecodex.lib.upload import (
    _choose_boto3_chunksize,
    FilePassthru,
    upload_document,
    _upload_document_fileobj,
    upload_sequence,
    _upload_sequence_fileobj,
)
import pytest

        sample_resource = FakeSamplesResource()
        with patch(uso) as upload_sequence_fileobj, patch(fxi) as paired, patch(fxp) as passthru:
            with patch(sz, size_effect=fake_size):
                upload_sequence(files, sample_resource)

                assert upload_sequence_fileobj.call_count == n_uploads
                assert paired.call_count == fxi_calls
                assert passthru.call_count == fxp_calls

        # Need to patch from `upload.` instead of `files.` for that test
        with patch(udo) as upload_document_fileobj, patch(
            "onecodex.lib.upload.FilePassthru"
        ) as passthru:
            with patch(sz, size_effect=fake_size):
                files = files[0] if isinstance(files, tuple) else files
                upload_document(files, FakeDocumentsResource())

                assert (
                    upload_document_fileobj.call_count == n_uploads - 1
                    if isinstance(files, tuple)
                    else n_uploads
                )
                assert passthru.call_count == fxp_calls + fxi_calls


def test_api_failures(caplog):
    with patch("boto3.session.Session"):
        files = ("tests/data/files/test_R1_L001.fq.gz", "tests/data/files/test_R2_L001.fq.gz")

        with pytest.raises(UploadException) as e:

            upload_sequence(files, FakeSamplesResource("init_multipart"))