def artifact_bundles(self):
        """
        Gets the Artifact Bundles API client.

        Returns:
            ArtifactBundles:
        """
        return ArtifactBundles(self.__connection)
    def artifact_bundles(self):
        """
        Gets the Artifact Bundles API client.

        Returns:
            ArtifactBundles:
        """
        if not self.__artifact_bundles:
            self.__artifact_bundles = ArtifactBundles(self.__connection)
        return self.__artifact_bundles
Esempio n. 3
0
 def setUp(self):
     self.host = '127.0.0.1'
     self.connection = connection(self.host)
     self._client = ArtifactBundles(self.connection)
Esempio n. 4
0
class ArtifactBundlesTest(TestCase):
    def setUp(self):
        self.host = '127.0.0.1'
        self.connection = connection(self.host)
        self._client = ArtifactBundles(self.connection)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_all_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name: ascending'

        self._client.get_all(2, 500, filter, sort)

        mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_all_called_once_with_default_values(self, mock_get_all):
        self._client.get_all()

        mock_get_all.assert_called_once_with(0, -1, filter='', sort='')

    @mock.patch.object(ResourceClient, 'get')
    def test_get_called_once(self, mock_get):
        self._client.get('78836581-2b6f-4e26-9969-5667fb5837b4')

        mock_get.assert_called_once_with(
            '78836581-2b6f-4e26-9969-5667fb5837b4')

    @mock.patch.object(ResourceClient, 'get')
    def test_get_with_uri_called_once(self, mock_get):
        uri = '/rest/artifact-bundles/78836581-2b6f-4e26-9969-5667fb5837b4'
        self._client.get(uri)

        mock_get.assert_called_once_with(uri)

    @mock.patch.object(ResourceClient, 'get_by')
    def test_get_by_called_once(self, mock_get_by):
        self._client.get_by('name', 'ArtifactBundle')

        mock_get_by.assert_called_once_with('name', 'ArtifactBundle')

    @mock.patch.object(ResourceClient, 'get_by_name')
    def test_get_by_name_called_once(self, mock_get_by):
        self._client.get_by_name('ArtifactBundle')

        mock_get_by.assert_called_once_with('ArtifactBundle')

    @mock.patch.object(ResourceClient, 'create')
    def test_create_called_once(self, mock_create):
        information = {"name": "ArtifactBundle"}
        mock_create.return_value = {}

        self._client.create(information)
        mock_create.assert_called_once_with(information.copy(), timeout=-1)

    @mock.patch.object(ResourceClient, 'update')
    def test_update_called_once(self, mock_update):
        information = {
            "name": "ArtifactBundleUpdate",
            "uri":
            "/rest/artifact-bundles/78836581-2b6f-4e26-9969-5667fb5837b4"
        }
        mock_update.return_value = {}

        self._client.update(information)

        default_values = {u'300': {u'type': u'ArtifactsBundle'}}

        mock_update.assert_called_once_with(information.copy(),
                                            default_values=default_values,
                                            timeout=-1)

    @mock.patch.object(ResourceClient, 'delete')
    def test_remove_called_once(self, mock_delete):
        id = '78836581-2b6f-4e26-9969-5667fb5837b4'
        self._client.delete(id)

        mock_delete.assert_called_once_with(id, timeout=-1)

    @mock.patch.object(ResourceClient, 'get_collection')
    def test_get_all_backups_called_once(self, mock_get_collection):
        uri = '/rest/artifact-bundles/backups'
        self._client.get_all_backups()

        mock_get_collection.assert_called_once_with(id_or_uri=uri)

    @mock.patch.object(ResourceClient, 'get')
    def test_get_backups_by_id_called_once(self, mock_get):
        uri = '/rest/artifact-bundles/backups'
        id = '78836581-2b6f-4e26-9969-5667fb5837b4'
        self._client.get_backup(id)

        mock_get.assert_called_once_with(id_or_uri=uri + '/' + id)

    @mock.patch.object(ResourceClient, 'download')
    def test_download_called_once_by_id(self, mock_download):
        destination = '~/image.zip'
        self._client.download_artifact_bundle('0ABDE00534F', destination)

        mock_download.assert_called_once_with(
            '/rest/artifact-bundles/download/0ABDE00534F', destination)

    @mock.patch.object(ResourceClient, 'download')
    def test_download_called_once_by_uri(self, mock_download):
        uri = '/rest/artifact-bundles/0ABDE00534F'
        destination = '~/image.zip'

        self._client.download_artifact_bundle(uri, destination)

        mock_download.assert_called_once_with(
            '/rest/artifact-bundles/download/0ABDE00534F', destination)

    @mock.patch.object(ResourceClient, 'download')
    def test_download_archive_artifact_bundle_by_id_called_once(
            self, mock_download):
        id = '78836581-2b6f-4e26-9969-5667fb5837b4'
        destination = '~/image.zip'

        self._client.download_archive_artifact_bundle(id, destination)

        expected_uri = '/rest/artifact-bundles/backups/archive/78836581-2b6f-4e26-9969-5667fb5837b4'
        mock_download.assert_called_once_with(expected_uri, destination)

    @mock.patch.object(ResourceClient, 'download')
    def test_download_archive_artifact_bundle_by_uri_called_once(
            self, mock_download):
        uri = '/rest/artifact-bundles/78836581-2b6f-4e26-9969-5667fb5837b4'
        destination = '~/image.zip'

        self._client.download_archive_artifact_bundle(uri, destination)

        expected_uri = '/rest/artifact-bundles/backups/archive/78836581-2b6f-4e26-9969-5667fb5837b4'
        mock_download.assert_called_once_with(expected_uri, destination)

    @mock.patch.object(ResourceClient, 'create')
    def test_create_backup_called_once(self, mock_create):
        information = {
            "deploymentGroupURI":
            "/rest/deployment-groups/00c1344d-e4dd-43c3-a733-1664e159a36f"
        }
        mock_create.return_value = {}

        self._client.create_backup(information)
        uri = '/rest/artifact-bundles/backups'
        mock_create.assert_called_once_with(information.copy(),
                                            uri=uri,
                                            timeout=-1)

    @mock.patch.object(ResourceClient, 'upload')
    def test_upload_artifact_bundle_called_once(self, mock_upload):
        filepath = "~/HPE-ImageStreamer-Developer-2016-09-12.zip"

        self._client.upload_bundle_from_file(filepath)

        mock_upload.assert_called_once_with(filepath)

    @mock.patch.object(ResourceClient, 'upload')
    def test_upload_backup_artifact_bundle_called_once(self, mock_upload):
        filepath = "~/HPE-ImageStreamer-Developer-2016-09-12.zip"
        deployment_groups = "/rest/deployment-groups/00c1344d-e4dd-43c3-a733-1664e159a36f"

        self._client.upload_backup_bundle_from_file(filepath,
                                                    deployment_groups)

        expected_uri = '/rest/artifact-bundles/backups/archive?deploymentGrpUri=' + deployment_groups

        mock_upload.assert_called_once_with(filepath, expected_uri)

    @mock.patch.object(ResourceClient, 'upload')
    def test_upload_backup_artifact_bundle_called_once_with_id(
            self, mock_upload):
        filepath = "~/HPE-ImageStreamer-Developer-2016-09-12.zip"
        deployment_groups = "00c1344d-e4dd-43c3-a733-1664e159a36f"

        self._client.upload_backup_bundle_from_file(filepath,
                                                    deployment_groups)

        expected_uri = '/rest/artifact-bundles/backups/archive?' \
                       'deploymentGrpUri=/rest/deployment-groups/00c1344d-e4dd-43c3-a733-1664e159a36f'
        mock_upload.assert_called_once_with(filepath, expected_uri)

    @mock.patch.object(ResourceClient, 'update')
    def test_extract_called_once(self, mock_update):
        mock_update.return_value = {}

        uri = {
            'uri':
            '/rest/artifact-bundles/78836581-2b6f-4e26-9969-5667fb5837b4'
        }
        custom_headers = {'Content-Type': 'text/plain'}

        self._client.extract_bundle(uri)

        mock_update.assert_called_once_with(uri,
                                            custom_headers=custom_headers,
                                            timeout=-1)

    @mock.patch.object(ResourceClient, 'update')
    def test_extract_backup_bundle_called_once(self, mock_update):
        mock_update.return_value = {}

        data = {
            'deploymentGroupURI':
            '/rest/deployment-groups/00c1344d-e4dd-43c3-a733-1664e159a36f'
        }

        uri = '/rest/artifact-bundles/backups/archive'

        self._client.extract_backup_bundle(data)

        mock_update.assert_called_once_with(data, uri=uri, timeout=-1)

    @mock.patch.object(ResourceClient, 'update')
    def test_stop_creation_called_once(self, mock_update):
        mock_update.return_value = {}

        artifact_uri = "/rest/artifact-bundles/04939e89-bcb0-49fc-814f-1a6bc0a2f63c"
        task_uri = "/rest/tasks/A15F9270-46FC-48DF-94A9-D11EDB52877E"

        self._client.stop_artifact_creation(artifact_uri, task_uri)

        uri = artifact_uri + '/stopArtifactCreate'

        task_uri = {'taskUri': task_uri}

        mock_update.assert_called_once_with(task_uri, uri=uri)
 def setUp(self):
     self.host = '127.0.0.1'
     self.connection = connection(self.host)
     self._client = ArtifactBundles(self.connection)
class ArtifactBundlesTest(TestCase):
    def setUp(self):
        self.host = '127.0.0.1'
        self.connection = connection(self.host)
        self._client = ArtifactBundles(self.connection)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_all_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name: ascending'

        self._client.get_all(2, 500, filter, sort)

        mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_all_called_once_with_default_values(self, mock_get_all):
        self._client.get_all()

        mock_get_all.assert_called_once_with(0, -1, filter='', sort='')

    @mock.patch.object(ResourceClient, 'get')
    def test_get_called_once(self, mock_get):
        self._client.get('78836581-2b6f-4e26-9969-5667fb5837b4')

        mock_get.assert_called_once_with(
            '78836581-2b6f-4e26-9969-5667fb5837b4')

    @mock.patch.object(ResourceClient, 'get')
    def test_get_with_uri_called_once(self, mock_get):
        uri = '/rest/artifact-bundles/78836581-2b6f-4e26-9969-5667fb5837b4'
        self._client.get(uri)

        mock_get.assert_called_once_with(uri)

    @mock.patch.object(ResourceClient, 'get_by')
    def test_get_by_called_once(self, mock_get_by):
        self._client.get_by('name', 'ArtifactBundle')

        mock_get_by.assert_called_once_with(
            'name', 'ArtifactBundle')

    @mock.patch.object(ResourceClient, 'get_by_name')
    def test_get_by_name_called_once(self, mock_get_by):
        self._client.get_by_name('ArtifactBundle')

        mock_get_by.assert_called_once_with('ArtifactBundle')

    @mock.patch.object(ResourceClient, 'create')
    def test_create_called_once(self, mock_create):
        information = {
            "name": "ArtifactBundle"
        }
        mock_create.return_value = {}

        self._client.create(information)
        mock_create.assert_called_once_with(information.copy(), timeout=-1)

    @mock.patch.object(ResourceClient, 'update')
    def test_update_called_once(self, mock_update):
        information = {
            "name": "ArtifactBundleUpdate",
            "uri": "/rest/artifact-bundles/78836581-2b6f-4e26-9969-5667fb5837b4"
        }
        mock_update.return_value = {}

        self._client.update(information)

        default_values = {u'300': {u'type': u'ArtifactsBundle'}}

        mock_update.assert_called_once_with(information.copy(), default_values=default_values, timeout=-1)

    @mock.patch.object(ResourceClient, 'delete')
    def test_remove_called_once(self, mock_delete):
        id = '78836581-2b6f-4e26-9969-5667fb5837b4'
        self._client.delete(id)

        mock_delete.assert_called_once_with(id, timeout=-1)

    @mock.patch.object(ResourceClient, 'get_collection')
    def test_get_all_backups_called_once(self, mock_get_collection):
        uri = '/rest/artifact-bundles/backups'
        self._client.get_all_backups()

        mock_get_collection.assert_called_once_with(id_or_uri=uri)

    @mock.patch.object(ResourceClient, 'get')
    def test_get_backups_by_id_called_once(self, mock_get):
        uri = '/rest/artifact-bundles/backups'
        id = '78836581-2b6f-4e26-9969-5667fb5837b4'
        self._client.get_backup(id)

        mock_get.assert_called_once_with(id_or_uri=uri + '/' + id)

    @mock.patch.object(ResourceClient, 'download')
    def test_download_called_once_by_id(self, mock_download):
        destination = '~/image.zip'
        self._client.download_artifact_bundle('0ABDE00534F', destination)

        mock_download.assert_called_once_with('/rest/artifact-bundles/download/0ABDE00534F', destination)

    @mock.patch.object(ResourceClient, 'download')
    def test_download_called_once_by_uri(self, mock_download):
        uri = '/rest/artifact-bundles/0ABDE00534F'
        destination = '~/image.zip'

        self._client.download_artifact_bundle(uri, destination)

        mock_download.assert_called_once_with('/rest/artifact-bundles/download/0ABDE00534F', destination)

    @mock.patch.object(ResourceClient, 'download')
    def test_download_archive_artifact_bundle_by_id_called_once(self, mock_download):
        id = '78836581-2b6f-4e26-9969-5667fb5837b4'
        destination = '~/image.zip'

        self._client.download_archive_artifact_bundle(id, destination)

        expected_uri = '/rest/artifact-bundles/backups/archive/78836581-2b6f-4e26-9969-5667fb5837b4'
        mock_download.assert_called_once_with(expected_uri, destination)

    @mock.patch.object(ResourceClient, 'download')
    def test_download_archive_artifact_bundle_by_uri_called_once(self, mock_download):
        uri = '/rest/artifact-bundles/78836581-2b6f-4e26-9969-5667fb5837b4'
        destination = '~/image.zip'

        self._client.download_archive_artifact_bundle(uri, destination)

        expected_uri = '/rest/artifact-bundles/backups/archive/78836581-2b6f-4e26-9969-5667fb5837b4'
        mock_download.assert_called_once_with(expected_uri, destination)

    @mock.patch.object(ResourceClient, 'create')
    def test_create_backup_called_once(self, mock_create):
        information = {
            "deploymentGroupURI": "/rest/deployment-groups/00c1344d-e4dd-43c3-a733-1664e159a36f"
        }
        mock_create.return_value = {}

        self._client.create_backup(information)
        uri = '/rest/artifact-bundles/backups'
        mock_create.assert_called_once_with(information.copy(), uri=uri, timeout=-1)

    @mock.patch.object(ResourceClient, 'upload')
    def test_upload_artifact_bundle_called_once(self, mock_upload):
        filepath = "~/HPE-ImageStreamer-Developer-2016-09-12.zip"

        self._client.upload_bundle_from_file(filepath)

        mock_upload.assert_called_once_with(filepath)

    @mock.patch.object(ResourceClient, 'upload')
    def test_upload_backup_artifact_bundle_called_once(self, mock_upload):
        filepath = "~/HPE-ImageStreamer-Developer-2016-09-12.zip"
        deployment_groups = "/rest/deployment-groups/00c1344d-e4dd-43c3-a733-1664e159a36f"

        self._client.upload_backup_bundle_from_file(filepath, deployment_groups)

        expected_uri = '/rest/artifact-bundles/backups/archive?deploymentGrpUri=' + deployment_groups

        mock_upload.assert_called_once_with(filepath, expected_uri)

    @mock.patch.object(ResourceClient, 'upload')
    def test_upload_backup_artifact_bundle_called_once_with_id(self, mock_upload):
        filepath = "~/HPE-ImageStreamer-Developer-2016-09-12.zip"
        deployment_groups = "00c1344d-e4dd-43c3-a733-1664e159a36f"

        self._client.upload_backup_bundle_from_file(filepath, deployment_groups)

        expected_uri = '/rest/artifact-bundles/backups/archive?' \
                       'deploymentGrpUri=/rest/deployment-groups/00c1344d-e4dd-43c3-a733-1664e159a36f'
        mock_upload.assert_called_once_with(filepath, expected_uri)

    @mock.patch.object(ResourceClient, 'update')
    def test_extract_called_once(self, mock_update):
        mock_update.return_value = {}

        uri = {'uri': '/rest/artifact-bundles/78836581-2b6f-4e26-9969-5667fb5837b4'}
        custom_headers = {'Content-Type': 'text/plain'}

        self._client.extract_bundle(uri)

        mock_update.assert_called_once_with(uri, custom_headers=custom_headers, timeout=-1)

    @mock.patch.object(ResourceClient, 'update')
    def test_extract_backup_bundle_called_once(self, mock_update):
        mock_update.return_value = {}

        data = {
            'deploymentGroupURI': '/rest/deployment-groups/00c1344d-e4dd-43c3-a733-1664e159a36f'
        }

        uri = '/rest/artifact-bundles/backups/archive'

        self._client.extract_backup_bundle(data)

        mock_update.assert_called_once_with(data, uri=uri, timeout=-1)

    @mock.patch.object(ResourceClient, 'update')
    def test_stop_creation_called_once(self, mock_update):
        mock_update.return_value = {}

        artifact_uri = "/rest/artifact-bundles/04939e89-bcb0-49fc-814f-1a6bc0a2f63c"
        task_uri = "/rest/tasks/A15F9270-46FC-48DF-94A9-D11EDB52877E"

        self._client.stop_artifact_creation(artifact_uri, task_uri)

        uri = artifact_uri + '/stopArtifactCreate'

        task_uri = {
            'taskUri': task_uri
        }

        mock_update.assert_called_once_with(task_uri, uri=uri)
Esempio n. 7
0
 def setUp(self):
     self.host = '127.0.0.1'
     self.connection = connection(self.host)
     self._artifact_bundles = ArtifactBundles(self.connection)
     self.uri = "/rest/artifact-bundles/test"
     self._artifact_bundles.data = {"uri": self.uri}
Esempio n. 8
0
class ArtifactBundlesTest(TestCase):
    def setUp(self):
        self.host = '127.0.0.1'
        self.connection = connection(self.host)
        self._artifact_bundles = ArtifactBundles(self.connection)
        self.uri = "/rest/artifact-bundles/test"
        self._artifact_bundles.data = {"uri": self.uri}

    @mock.patch.object(Resource, 'get_all')
    def test_get_all_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'

        self._artifact_bundles.get_all(2, 500, filter=filter, sort=sort)
        mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort)

    @mock.patch.object(Resource, 'get_all')
    def test_get_all_called_once_with_default(self, mock_get_all):
        self._artifact_bundles.get_all()
        mock_get_all.assert_called_once_with()

    @mock.patch.object(ResourceHelper, 'get_collection')
    def test_get_all_backups_called_once(self, mock_get_collection):
        uri = '/rest/artifact-bundles/backups'
        self._artifact_bundles.get_all_backups()
        mock_get_collection.assert_called_once_with(uri=uri)

    @mock.patch.object(Resource, 'get_by_uri')
    def test_get_backups_by_id_called_once(self, mock_get):
        uri = '/rest/artifact-bundles/backups/test'
        self._artifact_bundles.get_backup(uri)
        mock_get.assert_called_once_with(uri)

    @mock.patch.object(ResourceFileHandlerMixin, 'download')
    def test_download_archive_artifact_bundle_by_uri_called_once(
            self, mock_download):
        destination = '~/image.zip'
        expected_uri = '/rest/artifact-bundles/backups/archive/test'

        self._artifact_bundles.download_archive(destination)
        mock_download.assert_called_once_with(expected_uri, destination)

    @mock.patch.object(ResourceFileHandlerMixin, 'download')
    def test_download_called_once_by_uri(self, mock_download):
        destination = '~/image.zip'

        self._artifact_bundles.download(destination)
        mock_download.assert_called_once_with(
            '/rest/artifact-bundles/download/test', destination)

    @mock.patch.object(Resource, 'create')
    def test_create_backup_called_once(self, mock_create):
        information = {
            "deploymentGroupURI":
            "/rest/deployment-groups/00c1344d-e4dd-43c3-a733-1664e159a36f"
        }
        uri = '/rest/artifact-bundles/backups'
        mock_create.return_value = {}

        self._artifact_bundles.create_backup(information)
        mock_create.assert_called_once_with(information.copy(),
                                            uri=uri,
                                            timeout=-1)

    @mock.patch.object(ResourceFileHandlerMixin, 'upload')
    def test_upload_artifact_bundle_called_once(self, mock_upload):
        filepath = "~/upload.zip"

        self._artifact_bundles.upload_bundle_from_file(filepath)
        mock_upload.assert_called_once_with(filepath)

    @mock.patch.object(ResourceFileHandlerMixin, 'upload')
    def test_upload_backup_artifact_bundle_called_once(self, mock_upload):
        filepath = "~/upload.zip"
        deployment_groups = "/rest/deployment-groups/00c1344d-e4dd-43c3-a733-1664e159a36f"
        expected_uri = '/rest/artifact-bundles/backups/archive?deploymentGrpUri=' + deployment_groups

        self._artifact_bundles.upload_backup_bundle_from_file(
            filepath, deployment_groups)
        mock_upload.assert_called_once_with(filepath, expected_uri)

    @mock.patch.object(ResourceHelper, 'update')
    def test_extract_called_once(self, mock_update):
        mock_update.return_value = {}
        resource = {}
        uri = '/rest/artifact-bundles/test?extract=true&forceImport=true'
        custom_headers = {'Content-Type': 'text/plain;charset=UTF-8'}

        self._artifact_bundles.extract(resource)
        mock_update.assert_called_once_with(resource,
                                            uri,
                                            custom_headers=custom_headers,
                                            timeout=-1)

    @mock.patch.object(ResourceHelper, 'update')
    def test_extract_backup_bundle_called_once(self, mock_update):
        mock_update.return_value = {}

        data = {
            'deploymentGroupURI':
            '/rest/deployment-groups/00c1344d-e4dd-43c3-a733-1664e159a36f'
        }

        uri = '/rest/artifact-bundles/backups/test'

        self._artifact_bundles.extract_backup(data)
        mock_update.assert_called_once_with(data, uri, timeout=-1)

    @mock.patch.object(ResourceHelper, 'update')
    def test_stop_creation_called_once(self, mock_update):
        mock_update.return_value = {}

        task_uri = "/rest/tasks/A15F9270-46FC-48DF-94A9-D11EDB52877E"

        artifact_uri = "/rest/artifact-bundles/test"
        uri = artifact_uri + '/stopArtifactCreate'

        data = {'taskUri': task_uri}

        self._artifact_bundles.stop_artifact_creation(task_uri)
        mock_update.assert_called_once_with(data, uri=uri)