# Path: auto_forensicate/errors.py
# class BadConfigOption(Exception):
# class ForensicateError(Exception):
# class RecipeException(Exception):
# class RetryableError(ForensicateError):
# 
# Path: auto_forensicate/uploader.py
# class BaseUploader(object):
# class LocalCopier(BaseUploader):
# class GCSUploader(BaseUploader):
#   def __init__(self, stamp_manager, stamp=None):
#   def _UploadStamp(self):
#   def _MakeRemotePath(self, destination):
#   def _UploadStream(self, stream, remote_path, update_callback=None):
#   def UploadArtifact(self, artifact, update_callback=None):
#   def __init__(self, destination_dir, stamp_manager, stamp=None):
#   def _UploadStream(self, stream, remote_path, update_callback=None):
#   def _MakeRemotePath(self, destination):
#   def __init__(self, gs_url, gs_keyfile, client_id, stamp_manager, stamp=None):
#   def _InitBoto(self):
#   def _SplitGCSUrl(self):
#   def _MakeRemotePath(self, destination):
#   def _UploadStream(self, stream, remote_path, update_callback=None):
# 
# Path: auto_forensicate/recipes/base.py
# class BaseArtifact(object):
# class StringArtifact(BaseArtifact):
# class FileArtifact(BaseArtifact):
# class ProcessOutputArtifact(BaseArtifact):
# class BaseRecipe(object):
#   def __init__(self, name):
#   def _GetStream(self):
#   def CloseStream(self):
#   def OpenStream(self):
#   def size(self):
#   def readable_size(self):
#   def __init__(self, path, string_content):
#   def _GetStream(self):
#   def CloseStream(self):
#   def __init__(self, path):
#   def _GetStream(self):
#   def __init__(self, command, path, ignore_failure=False):
#   def _RunCommand(self):
#   def _GetStream(self):
#   def __init__(self, name, options=None):
#   def __enter__(self):
#   def __exit__(self, exc_type, exc_value, traceback):
#   def GetArtifacts(self):
# 
# Path: auto_forensicate/stamp/manager.py
# class BaseStampManager(object):
#   def BasePathElements(self, stamp):
#   def GetStamp(self):


import argparse
import json
import tempfile
import unittest
import boto
import mock
import shutil
from collections import namedtuple
  from BytesIO import BytesIO
  from io import BytesIO
from auto_forensicate import errors
from auto_forensicate import uploader
from auto_forensicate.recipes import base
from auto_forensicate.stamp import manager

    result_path = uploader_object.UploadArtifact(test_artifact)
    self.assertEqual(result_path, expected_resultpath)
    self.assertEqual(
        uploader_object._uploaded_streams, expected_uploaded_streams)

  @mock.patch.object(base.BaseArtifact, '_GetStream')
  @mock.patch.object(boto, 'storage_uri')
  def testFailUploadRetryWorthy(self, patched_storage, patched_getstream):
    patched_getstream.return_value = BytesIO(b'fake_content')
    patched_storage.side_effect = boto.exception.GSDataError('boom')

    test_artifact = base.BaseArtifact('test_artifact')

    uploader_object = uploader.GCSUploader(
        'gs://fake_bucket/', 'no_keyfile', 'client_id', FakeStampManager())
    uploader_object._boto_configured = True

    with self.assertRaises(errors.RetryableError):
      uploader_object._UploadStream(
          test_artifact.OpenStream(), 'gs://fake_bucket/remote/path')

  @mock.patch.object(base.BaseArtifact, '_GetStream')
  @mock.patch.object(boto, 'storage_uri')
  def testFailUploadNoRetry(self, patched_storage, patched_getstream):
    patched_getstream.return_value = BytesIO(b'fake_content')
    patched_storage.side_effect = errors.ForensicateError('random_error')

    test_artifact = base.BaseArtifact('test_artifact')


# Path: auto_forensicate/errors.py
# class BadConfigOption(Exception):
# class ForensicateError(Exception):
# class RecipeException(Exception):
# class RetryableError(ForensicateError):
# 
# Path: auto_forensicate/uploader.py
# class BaseUploader(object):
# class LocalCopier(BaseUploader):
# class GCSUploader(BaseUploader):
#   def __init__(self, stamp_manager, stamp=None):
#   def _UploadStamp(self):
#   def _MakeRemotePath(self, destination):
#   def _UploadStream(self, stream, remote_path, update_callback=None):
#   def UploadArtifact(self, artifact, update_callback=None):
#   def __init__(self, destination_dir, stamp_manager, stamp=None):
#   def _UploadStream(self, stream, remote_path, update_callback=None):
#   def _MakeRemotePath(self, destination):
#   def __init__(self, gs_url, gs_keyfile, client_id, stamp_manager, stamp=None):
#   def _InitBoto(self):
#   def _SplitGCSUrl(self):
#   def _MakeRemotePath(self, destination):
#   def _UploadStream(self, stream, remote_path, update_callback=None):
# 
# Path: auto_forensicate/recipes/base.py
# class BaseArtifact(object):
# class StringArtifact(BaseArtifact):
# class FileArtifact(BaseArtifact):
# class ProcessOutputArtifact(BaseArtifact):
# class BaseRecipe(object):
#   def __init__(self, name):
#   def _GetStream(self):
#   def CloseStream(self):
#   def OpenStream(self):
#   def size(self):
#   def readable_size(self):
#   def __init__(self, path, string_content):
#   def _GetStream(self):
#   def CloseStream(self):
#   def __init__(self, path):
#   def _GetStream(self):
#   def __init__(self, command, path, ignore_failure=False):
#   def _RunCommand(self):
#   def _GetStream(self):
#   def __init__(self, name, options=None):
#   def __enter__(self):
#   def __exit__(self, exc_type, exc_value, traceback):
#   def GetArtifacts(self):
# 
# Path: auto_forensicate/stamp/manager.py
# class BaseStampManager(object):
#   def BasePathElements(self, stamp):
#   def GetStamp(self):


# Path: tests/uploader_tests.py
import argparse
import json
import tempfile
import unittest
import boto
import mock
import shutil
from collections import namedtuple
  from BytesIO import BytesIO
  from io import BytesIO
from auto_forensicate import errors
from auto_forensicate import uploader
from auto_forensicate.recipes import base
from auto_forensicate.stamp import manager


    result_path = uploader_object.UploadArtifact(test_artifact)
    self.assertEqual(result_path, expected_resultpath)
    self.assertEqual(
        uploader_object._uploaded_streams, expected_uploaded_streams)

  @mock.patch.object(base.BaseArtifact, '_GetStream')
  @mock.patch.object(boto, 'storage_uri')
  def testFailUploadRetryWorthy(self, patched_storage, patched_getstream):
    patched_getstream.return_value = BytesIO(b'fake_content')
    patched_storage.side_effect = boto.exception.GSDataError('boom')

    test_artifact = base.BaseArtifact('test_artifact')

    uploader_object = uploader.GCSUploader(
        'gs://fake_bucket/', 'no_keyfile', 'client_id', FakeStampManager())
    uploader_object._boto_configured = True

    with self.assertRaises(errors.RetryableError):
      uploader_object._UploadStream(
          test_artifact.OpenStream(), 'gs://fake_bucket/remote/path')

  @mock.patch.object(base.BaseArtifact, '_GetStream')
  @mock.patch.object(boto, 'storage_uri')
  def testFailUploadNoRetry(self, patched_storage, patched_getstream):
    patched_getstream.return_value = BytesIO(b'fake_content')
    patched_storage.side_effect = errors.ForensicateError('random_error')

    test_artifact = base.BaseArtifact('test_artifact')


    uploader_object = uploader.GCSUploader(