コード例 #1
0
    def test_download_bit_raises_exception_when_bit_is_not_found(
            self, http_client, filesystem):
        connector = CpmHubConnectorV1()
        http_client.get.return_value = HttpResponse(HTTPStatus.NOT_FOUND, '')

        self.assertRaises(BitNotFound, connector.download_bit, 'cest',
                          'latest')

        http_client.get.assert_called_once_with(
            f'{connector.repository_url}/cest')
コード例 #2
0
    def test_download_template_raises_exception_when_template_is_not_found(
            self, http_client):
        connector = CpmHubConnectorV1()
        http_client.get.return_value = HttpResponse(HTTPStatus.NOT_FOUND, '')

        self.assertRaises(TemplateNotFound, connector.download_template,
                          'arduino', 'latest')

        http_client.get.assert_called_once_with(
            f'{connector.repository_url}/templates/arduino')
コード例 #3
0
    def test_publish_bit_raises_publication_error_when_status_code_is_not_200(
            self, getpass, input, http_client, filesystem):
        project = Project('cpm-hub')
        connector = CpmHubConnectorV1()
        http_client.post.return_value = HttpResponse(409, '')
        filesystem.read_file.return_value = b'bit payload'
        getpass.return_value = 'password'
        input.return_value = 'username'

        self.assertRaises(PublicationFailure, connector.publish_bit, project,
                          'cpm-hub.zip')
コード例 #4
0
    def test_publish_bit_raises_invalid_cpm_hub_url_on_status_code_404(
            self, getpass, input, http_client, filesystem):
        project = Project('cpm-hub')
        connector = CpmHubConnectorV1()
        http_client.post.return_value = HttpResponse(404, '')
        filesystem.read_file.return_value = b'bit payload'
        getpass.return_value = 'password'
        input.return_value = 'username'

        self.assertRaises(InvalidCpmHubUrl, connector.publish_bit, project,
                          'cpm-hub.zip')
コード例 #5
0
    def test_download_bit_gets_bit_with_specific_version(self, http_client):
        connector = CpmHubConnectorV1()
        http_client.get.return_value = HttpResponse(
            HTTPStatus.OK,
            '{"bit_name": "cpm-hub", "version": "1.0", "payload": "Yml0IHBheWxvYWQ="}'
        )

        bit_download = connector.download_bit('cest', '1.0')

        http_client.get.assert_called_once_with(
            f'{connector.repository_url}/bits/cest/1.0')
        assert bit_download == BitDownload("cpm-hub", "1.0",
                                           "Yml0IHBheWxvYWQ=")
コード例 #6
0
    def test_download_bit_gets_bit_with_base64_encoded_payload(
            self, http_client, filesystem):
        connector = CpmHubConnectorV1()
        http_client.get.return_value = HttpResponse(
            HTTPStatus.OK,
            '{"bit_name": "cpm-hub", "version": "0.1", "payload": "Yml0IHBheWxvYWQ="}'
        )

        bit_download = connector.download_bit('cest', 'latest')

        http_client.get.assert_called_once_with(
            f'{connector.repository_url}/cest')
        assert bit_download == BitDownload("cpm-hub", "0.1",
                                           "Yml0IHBheWxvYWQ=")
コード例 #7
0
    def test_download_template_gets_bit_with_base64_encoded_payload(
            self, http_client):
        connector = CpmHubConnectorV1()
        http_client.get.return_value = HttpResponse(
            HTTPStatus.OK,
            '{"template_name": "arduino", "version": "1.0.0", "payload": "Yml0IHBheWxvYWQ="}'
        )

        template_download = connector.download_template('arduino', 'latest')

        http_client.get.assert_called_once_with(
            f'{connector.repository_url}/templates/arduino')
        assert template_download == TemplateDownload("arduino", "1.0.0",
                                                     "Yml0IHBheWxvYWQ=")
コード例 #8
0
    def test_publish_bit_posts_bit_with_base64_encoded_payload_and_user_credentials(
            self, getpass, input, http_client, filesystem):
        project = Project('cpm-hub')
        connector = CpmHubConnectorV1()
        http_client.post.return_value = HttpResponse(200, '')
        filesystem.read_file.return_value = b'bit payload'
        getpass.return_value = 'password'
        input.return_value = 'username'

        connector.publish_bit(project, 'cpm-hub.zip')

        http_client.post.assert_called_once_with(
            connector.repository_url,
            data=
            '{"bit_name": "cpm-hub", "version": "0.1", "payload": "Yml0IHBheWxvYWQ=", "username": "******", "password": "******"}'
        )