# Path: sevenbridges/errors.py
# class SbgError(Exception):
#     """Base class for SBG errors.
# 
#     Provides a base exception for all errors
#     that are thrown by sevenbridges-python library.
#     """
# 
#     def __init__(self, message=None, code=None, status=None, more_info=None):
#         """
#         :param code: Custom error code
#         :param status: Http status code.
#         :param message: Message describing the error.
#         """
#         self.code = code
#         self.status = status
#         self.message = message
#         self.more_info = more_info
# 
#     def __str__(self):
#         return str(self.message)
# 
# Path: sevenbridges/transfer/upload.py
# class CodePackageUpload(Upload):
#     _URL = {
#         'upload_init': '/automation/upload',
#         'upload_info': '/automation/upload/{upload_id}',
#         'upload_complete': '/automation/upload/{upload_id}/complete'
#     }
# 
#     def __init__(
#         self, file_path, automation_id, file_name=None, part_size=None,
#         retry_count=RequestParameters.DEFAULT_RETRY_COUNT,
#         timeout=RequestParameters.DEFAULT_TIMEOUT, parent=None, api=None
#     ):
#         """
#             Multipart File uploader for automation code packages.
# 
#             "overwrite" input is disabled as we don't allow overwriting
#             code packages.
# 
#             :param file_path: File path on the disc.
#             :param automation_id: ID of the automation to which
#             the package is uploaded.
#             :param file_name: Optional file name.
#             :param part_size: Size of part in bytes.
#             :param retry_count: Retry count.
#             :param timeout: Timeout for s3/google session.
#             :param api: Api instance.
#         """
#         super().__init__(
#             file_path=file_path,
#             project=None,
#             parent=parent,
#             file_name=file_name,
#             overwrite=False,
#             part_size=part_size,
#             retry_count=retry_count,
#             timeout=timeout,
#             api=api
#         )
#         if self._file_size == 0:
#             raise SbgError('File size must not be 0.')
# 
#         self._automation_id = automation_id
# 
#     def _validate_project_parent(self, parent, project):
#         # Skip for code packages
#         pass
# 
#     def partition_file(self, fp):
#         return CodePackageUPartedFile(
#             fp, self._file_size, self._part_size, self._upload_id,
#             self._timeout, self.session, self._api
#         )
# 
#     def _create_init_data(self):
#         init_data = {
#             'name': self._file_name,
#             'size': self._file_size,
#             'automation_id': self._automation_id
#         }
#         if self._part_size:
#             init_data['part_size'] = self._part_size
#         return init_data


import faker
import pytest
import tempfile
import os
from sevenbridges.errors import SbgError
from sevenbridges.transfer.upload import CodePackageUpload

generator = faker.Factory.create()


def test_get_automation(api, given, verifier):
    # precondition
    api.aa = True
    id = generator.uuid4()

    given.automations.exists(id=id)

    # action
    automation = api.automations.get(id=id)

    # verification
    assert automation.id == id
    verifier.automations.fetched(id=id)


@pytest.mark.parametrize("name", [generator.name(), None])
def test_create_automation(api, given, verifier, name):
    # preconditions
    automation_description = generator.name()
    billing_group = generator.uuid4()
    settings = {
        "secret_token": generator.uuid4()
    }

    given.automations.can_be_created(
        name=name,

# Path: sevenbridges/errors.py
# class SbgError(Exception):
#     """Base class for SBG errors.
# 
#     Provides a base exception for all errors
#     that are thrown by sevenbridges-python library.
#     """
# 
#     def __init__(self, message=None, code=None, status=None, more_info=None):
#         """
#         :param code: Custom error code
#         :param status: Http status code.
#         :param message: Message describing the error.
#         """
#         self.code = code
#         self.status = status
#         self.message = message
#         self.more_info = more_info
# 
#     def __str__(self):
#         return str(self.message)
# 
# Path: sevenbridges/transfer/upload.py
# class CodePackageUpload(Upload):
#     _URL = {
#         'upload_init': '/automation/upload',
#         'upload_info': '/automation/upload/{upload_id}',
#         'upload_complete': '/automation/upload/{upload_id}/complete'
#     }
# 
#     def __init__(
#         self, file_path, automation_id, file_name=None, part_size=None,
#         retry_count=RequestParameters.DEFAULT_RETRY_COUNT,
#         timeout=RequestParameters.DEFAULT_TIMEOUT, parent=None, api=None
#     ):
#         """
#             Multipart File uploader for automation code packages.
# 
#             "overwrite" input is disabled as we don't allow overwriting
#             code packages.
# 
#             :param file_path: File path on the disc.
#             :param automation_id: ID of the automation to which
#             the package is uploaded.
#             :param file_name: Optional file name.
#             :param part_size: Size of part in bytes.
#             :param retry_count: Retry count.
#             :param timeout: Timeout for s3/google session.
#             :param api: Api instance.
#         """
#         super().__init__(
#             file_path=file_path,
#             project=None,
#             parent=parent,
#             file_name=file_name,
#             overwrite=False,
#             part_size=part_size,
#             retry_count=retry_count,
#             timeout=timeout,
#             api=api
#         )
#         if self._file_size == 0:
#             raise SbgError('File size must not be 0.')
# 
#         self._automation_id = automation_id
# 
#     def _validate_project_parent(self, parent, project):
#         # Skip for code packages
#         pass
# 
#     def partition_file(self, fp):
#         return CodePackageUPartedFile(
#             fp, self._file_size, self._part_size, self._upload_id,
#             self._timeout, self.session, self._api
#         )
# 
#     def _create_init_data(self):
#         init_data = {
#             'name': self._file_name,
#             'size': self._file_size,
#             'automation_id': self._automation_id
#         }
#         if self._part_size:
#             init_data['part_size'] = self._part_size
#         return init_data


# Path: tests/test_automations.py
import faker
import pytest
import tempfile
import os
from sevenbridges.errors import SbgError
from sevenbridges.transfer.upload import CodePackageUpload


generator = faker.Factory.create()


def test_get_automation(api, given, verifier):
    # precondition
    api.aa = True
    id = generator.uuid4()

    given.automations.exists(id=id)

    # action
    automation = api.automations.get(id=id)

    # verification
    assert automation.id == id
    verifier.automations.fetched(id=id)


@pytest.mark.parametrize("name", [generator.name(), None])
def test_create_automation(api, given, verifier, name):
    # preconditions
    automation_description = generator.name()
    billing_group = generator.uuid4()
    settings = {
        "secret_token": generator.uuid4()
    }

    given.automations.can_be_created(
        name=name,

        billing_group=billing_group,