# 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
# -*- coding: utf-8 -*-



class FakeAPISession:
    # TODO: We should migrate this to use responses vs. a faked API session
    adapters = {}

    def post(self, url, **kwargs):
        resp = lambda: None  # noqa
        resp.json = lambda: {"code": 200}
        resp.status_code = 201 if "auth" in kwargs else 200
        resp.raise_for_status = lambda: None  # noqa

        if url.endswith("s3_confirm"):
            resp.status_code = 200
            resp.json = lambda: {"sample_id": "s3_confirm_sample_id"}  # noqa

        return resp

    def mount(self, url, adapter):
        self.adapters[url] = adapter


class FakeSamplesResource:
    def __init__(self, what_fails=None):
        self.what_fails = what_fails

    @staticmethod
    def err_resp():

# 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

# -*- coding: utf-8 -*-



class FakeAPISession:
    # TODO: We should migrate this to use responses vs. a faked API session
    adapters = {}

    def post(self, url, **kwargs):
        resp = lambda: None  # noqa
        resp.json = lambda: {"code": 200}
        resp.status_code = 201 if "auth" in kwargs else 200
        resp.raise_for_status = lambda: None  # noqa

        if url.endswith("s3_confirm"):
            resp.status_code = 200
            resp.json = lambda: {"sample_id": "s3_confirm_sample_id"}  # noqa

        return resp

    def mount(self, url, adapter):
        self.adapters[url] = adapter


class FakeSamplesResource:
    def __init__(self, what_fails=None):
        self.what_fails = what_fails

    @staticmethod
    def err_resp():

        resp = lambda: None  # noqa