tests.compat.mock.Mock

Here are the examples of the python api tests.compat.mock.Mock taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

70 Examples 7

3 Source : test_sigv4.py
with Apache License 2.0
from gethue

    def setUp(self):
        self.provider = mock.Mock()
        self.provider.access_key = 'access_key'
        self.provider.secret_key = 'secret_key'
        self.request = HTTPRequest(
            'POST', 'https', 'glacier.us-east-1.amazonaws.com', 443,
            '/-/vaults/foo/archives', None, {},
            {'x-amz-glacier-version': '2012-06-01'}, '')

    def test_not_adding_empty_qs(self):

3 Source : test_sigv4.py
with Apache License 2.0
from gethue

    def test_not_adding_empty_qs(self):
        self.provider.security_token = None
        auth = HmacAuthV4Handler('glacier.us-east-1.amazonaws.com', mock.Mock(), self.provider)
        req = copy.copy(self.request)
        auth.add_auth(req)
        self.assertEqual(req.path, '/-/vaults/foo/archives')

    def test_inner_whitespace_is_collapsed(self):

3 Source : test_sigv4.py
with Apache License 2.0
from gethue

    def test_inner_whitespace_is_collapsed(self):
        auth = HmacAuthV4Handler('glacier.us-east-1.amazonaws.com',
                                 mock.Mock(), self.provider)
        self.request.headers['x-amz-archive-description'] = 'two  spaces'
        self.request.headers['x-amz-quoted-string'] = '  "a   b   c" '
        headers = auth.headers_to_sign(self.request)
        self.assertEqual(headers, {'Host': 'glacier.us-east-1.amazonaws.com',
                                   'x-amz-archive-description': 'two  spaces',
                                   'x-amz-glacier-version': '2012-06-01',
                                   'x-amz-quoted-string': '  "a   b   c" '})
        # Note the single space between the "two spaces".
        self.assertEqual(auth.canonical_headers(headers),
                         'host:glacier.us-east-1.amazonaws.com\n'
                         'x-amz-archive-description:two spaces\n'
                         'x-amz-glacier-version:2012-06-01\n'
                         'x-amz-quoted-string:"a   b   c"')

    def test_canonical_query_string(self):

3 Source : test_sigv4.py
with Apache License 2.0
from gethue

    def test_canonical_query_string(self):
        auth = HmacAuthV4Handler('glacier.us-east-1.amazonaws.com',
                                 mock.Mock(), self.provider)
        request = HTTPRequest(
            'GET', 'https', 'glacier.us-east-1.amazonaws.com', 443,
            '/-/vaults/foo/archives', None, {},
            {'x-amz-glacier-version': '2012-06-01'}, '')
        request.params['Foo.1'] = 'aaa'
        request.params['Foo.10'] = 'zzz'
        query_string = auth.canonical_query_string(request)
        self.assertEqual(query_string, 'Foo.1=aaa&Foo.10=zzz')

    def test_query_string(self):

3 Source : test_sigv4.py
with Apache License 2.0
from gethue

    def test_query_string(self):
        auth = HmacAuthV4Handler('sns.us-east-1.amazonaws.com',
                                 mock.Mock(), self.provider)
        params = {
            'Message': u'We \u2665 utf-8'.encode('utf-8'),
        }
        request = HTTPRequest(
            'POST', 'https', 'sns.us-east-1.amazonaws.com', 443,
            '/', None, params, {}, '')
        query_string = auth.query_string(request)
        self.assertEqual(query_string, 'Message=We%20%E2%99%A5%20utf-8')

    def test_canonical_uri(self):

3 Source : test_sigv4.py
with Apache License 2.0
from gethue

    def test_region_and_service_can_be_overriden(self):
        auth = HmacAuthV4Handler('queue.amazonaws.com',
                                 mock.Mock(), self.provider)
        self.request.headers['X-Amz-Date'] = '20121121000000'

        auth.region_name = 'us-west-2'
        auth.service_name = 'sqs'
        scope = auth.credential_scope(self.request)
        self.assertEqual(scope, '20121121/us-west-2/sqs/aws4_request')

    def test_pickle_works(self):

3 Source : test_sigv4.py
with Apache License 2.0
from gethue

    def test_bytes_header(self):
        auth = HmacAuthV4Handler('glacier.us-east-1.amazonaws.com',
                                 mock.Mock(), self.provider)
        request = HTTPRequest(
            'GET', 'http', 'glacier.us-east-1.amazonaws.com', 80,
            'x/./././x .html', None, {},
            {'x-amz-glacier-version': '2012-06-01', 'x-amz-hash': b'f00'}, '')
        canonical = auth.canonical_request(request)

        self.assertIn('f00', canonical)


class TestS3HmacAuthV4Handler(unittest.TestCase):

3 Source : test_awslambda.py
with Apache License 2.0
from gethue

    def test_upload_function_unseekable_file_cannot_tell(self):
        mock_file = mock.Mock()
        mock_file.tell.side_effect = IOError
        with self.assertRaises(TypeError):
            self.service_connection.upload_function(
                function_name='my-function',
                function_zip=mock_file,
                role='myrole',
                handler='myhandler',
                mode='event',
                runtime='nodejs'
            )

3 Source : test_invalidation_list.py
with Apache License 2.0
from gethue

    def test_auto_pagination(self, num_invals=1024):
        """
        Test that auto-pagination works properly
        """
        max_items = 100
        self.assertGreaterEqual(num_invals, max_items)
        responses = self._get_mock_responses(num=num_invals,
                                             max_items=max_items)
        self.cf.make_request = mock.Mock(side_effect=responses)
        ir = self.cf.get_invalidation_requests('dist-id-here')
        self.assertEqual(len(ir._inval_cache), max_items)
        self.assertEqual(len(list(ir)), num_invals)

if __name__ == '__main__':

3 Source : test_attribute.py
with Apache License 2.0
from gethue

    def _setup_mock(self):
        """Sets up a mock elb request.
        Returns: response, elb connection and LoadBalancer
        """
        mock_response = mock.Mock()
        mock_response.status = 200
        elb = ELBConnection(aws_access_key_id='aws_access_key_id',
                            aws_secret_access_key='aws_secret_access_key')
        elb.make_request = mock.Mock(return_value=mock_response)
        return mock_response, elb, LoadBalancer(elb, 'test_elb')

    def _verify_attributes(self, attributes, attr_tests):

3 Source : test_loadbalancer.py
with Apache License 2.0
from gethue

    def test_next_token(self):
        elb = ELBConnection(aws_access_key_id='aws_access_key_id',
                            aws_secret_access_key='aws_secret_access_key')
        mock_response = mock.Mock()
        mock_response.read.return_value = DISABLE_RESPONSE
        mock_response.status = 200
        elb.make_request = mock.Mock(return_value=mock_response)
        disabled = elb.disable_availability_zones('mine', ['sample-zone'])
        self.assertEqual(disabled, ['sample-zone'])


DESCRIBE_RESPONSE = b"""  <  ?xml version="1.0" encoding="UTF-8"?>

3 Source : test_loadbalancer.py
with Apache License 2.0
from gethue

    def test_request_with_marker(self):
        elb = ELBConnection(aws_access_key_id='aws_access_key_id',
                            aws_secret_access_key='aws_secret_access_key')
        mock_response = mock.Mock()
        mock_response.read.return_value = DESCRIBE_RESPONSE
        mock_response.status = 200
        elb.make_request = mock.Mock(return_value=mock_response)
        load_balancers1 = elb.get_all_load_balancers()
        self.assertEqual('1234', load_balancers1.marker)
        load_balancers2 = elb.get_all_load_balancers(marker=load_balancers1.marker)
        self.assertEqual(len(load_balancers2), 1)


DETACH_RESPONSE = r"""  <  ?xml version="1.0" encoding="UTF-8"?>

3 Source : test_loadbalancer.py
with Apache License 2.0
from gethue

    def test_detach_subnets(self):
        elb = ELBConnection(aws_access_key_id='aws_access_key_id',
                            aws_secret_access_key='aws_secret_access_key')
        lb = LoadBalancer(elb, "mylb")

        mock_response = mock.Mock()
        mock_response.read.return_value = DETACH_RESPONSE
        mock_response.status = 200
        elb.make_request = mock.Mock(return_value=mock_response)
        lb.detach_subnets("s-xxx")

if __name__ == '__main__':

3 Source : test_address.py
with Apache License 2.0
from gethue

    def setUp(self):
        self.address = Address()
        self.address.connection = mock.Mock()
        self.address.public_ip = "192.168.1.1"

    def check_that_attribute_has_been_set(self, name, value, attribute):

3 Source : test_address.py
with Apache License 2.0
from gethue

    def setUp(self):
        self.address = Address()
        self.address.connection = mock.Mock()
        self.address.public_ip = "192.168.1.1"
        self.address.allocation_id = "aid1"

    def check_that_attribute_has_been_set(self, name, value, attribute):

3 Source : test_instancestatus.py
with Apache License 2.0
from gethue

    def test_next_token(self):
        ec2 = EC2Connection(aws_access_key_id='aws_access_key_id',
                            aws_secret_access_key='aws_secret_access_key')
        mock_response = mock.Mock()
        mock_response.read.return_value = INSTANCE_STATUS_RESPONSE
        mock_response.status = 200
        ec2.make_request = mock.Mock(return_value=mock_response)
        all_statuses = ec2.get_all_instance_status()
        self.assertNotIn('IncludeAllInstances', ec2.make_request.call_args[0][1])
        self.assertEqual(all_statuses.next_token, 'page-2')

    def test_include_all_instances(self):

3 Source : test_instancestatus.py
with Apache License 2.0
from gethue

    def test_include_all_instances(self):
        ec2 = EC2Connection(aws_access_key_id='aws_access_key_id',
                            aws_secret_access_key='aws_secret_access_key')
        mock_response = mock.Mock()
        mock_response.read.return_value = INSTANCE_STATUS_RESPONSE
        mock_response.status = 200
        ec2.make_request = mock.Mock(return_value=mock_response)
        all_statuses = ec2.get_all_instance_status(include_all_instances=True)
        self.assertIn('IncludeAllInstances', ec2.make_request.call_args[0][1])
        self.assertEqual('true', ec2.make_request.call_args[0][1]['IncludeAllInstances'])
        self.assertEqual(all_statuses.next_token, 'page-2')


if __name__ == '__main__':

3 Source : test_networkinterface.py
with Apache License 2.0
from gethue

    def test_update_with_validate_true_raises_value_error(self):
        self.eni_one.connection = mock.Mock()
        self.eni_one.connection.get_all_network_interfaces.return_value = []
        with self.assertRaisesRegexp(ValueError, "^eni-1 is not a valid ENI ID$"):
            self.eni_one.update(True)

    def test_update_with_result_set_greater_than_0_updates_dict(self):

3 Source : test_networkinterface.py
with Apache License 2.0
from gethue

    def test_update_returns_status(self):
        self.eni_one.connection = mock.Mock()
        self.eni_one.connection.get_all_network_interfaces.return_value = [self.eni_two]
        retval = self.eni_one.update()
        self.assertEqual(retval, "two_status")

    def test_attach_calls_attach_eni(self):

3 Source : test_networkinterface.py
with Apache License 2.0
from gethue

    def test_attach_calls_attach_eni(self):
        self.eni_one.connection = mock.Mock()
        self.eni_one.attach("instance_id", 11)
        self.eni_one.connection.attach_network_interface.assert_called_with(
            'eni-1',
            "instance_id",
            11,
            dry_run=False
        )

    def test_detach_calls_detach_network_interface(self):

3 Source : test_networkinterface.py
with Apache License 2.0
from gethue

    def test_detach_calls_detach_network_interface(self):
        self.eni_one.connection = mock.Mock()
        self.eni_one.detach()
        self.eni_one.connection.detach_network_interface.assert_called_with(
            'eni-attach-1',
            False,
            dry_run=False
        )

    def test_detach_with_no_attach_data(self):

3 Source : test_networkinterface.py
with Apache License 2.0
from gethue

    def test_detach_with_no_attach_data(self):
        self.eni_two.connection = mock.Mock()
        self.eni_two.detach()
        self.eni_two.connection.detach_network_interface.assert_called_with(
            None, False, dry_run=False)

    def test_detach_with_force_calls_detach_network_interface_with_force(self):

3 Source : test_networkinterface.py
with Apache License 2.0
from gethue

    def test_detach_with_force_calls_detach_network_interface_with_force(self):
        self.eni_one.connection = mock.Mock()
        self.eni_one.detach(True)
        self.eni_one.connection.detach_network_interface.assert_called_with(
            'eni-attach-1', True, dry_run=False)


class TestNetworkInterfaceCollection(unittest.TestCase):

3 Source : test_volume.py
with Apache License 2.0
from gethue

    def test_startElement_retval_not_None_returns_correct_thing(self, startElement):
        tag_set = mock.Mock(TagSet)
        startElement.return_value = tag_set
        volume = Volume()
        retval = volume.startElement(None, None, None)
        self.assertEqual(retval, tag_set)

    @mock.patch("boto.ec2.volume.TaggedEC2Object.startElement")

3 Source : test_volume.py
with Apache License 2.0
from gethue

    def test_startElement_with_name_tagSet_calls_ResultSet(self, ResultSet, startElement):
        startElement.return_value = None
        result_set = mock.Mock(ResultSet([("item", Tag)]))
        volume = Volume()
        volume.tags = result_set
        retval = volume.startElement("tagSet", None, None)
        self.assertEqual(retval, volume.tags)

    @mock.patch("boto.ec2.volume.TaggedEC2Object.startElement")

3 Source : test_volume.py
with Apache License 2.0
from gethue

    def test_update_with_validate_true_raises_value_error(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.connection.get_all_volumes.return_value = []
        with self.assertRaisesRegexp(ValueError, "^1 is not a valid Volume ID$"):
            self.volume_one.update(True)

    def test_update_returns_status(self):

3 Source : test_volume.py
with Apache License 2.0
from gethue

    def test_update_returns_status(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.connection.get_all_volumes.return_value = [self.volume_two]
        retval = self.volume_one.update()
        self.assertEqual(retval, "two_status")

    def test_delete_calls_delete_volume(self):

3 Source : test_volume.py
with Apache License 2.0
from gethue

    def test_delete_calls_delete_volume(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.delete()
        self.volume_one.connection.delete_volume.assert_called_with(
            1,
            dry_run=False
        )

    def test_attach_calls_attach_volume(self):

3 Source : test_volume.py
with Apache License 2.0
from gethue

    def test_attach_calls_attach_volume(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.attach("instance_id", "/dev/null")
        self.volume_one.connection.attach_volume.assert_called_with(
            1,
            "instance_id",
            "/dev/null",
            dry_run=False
        )

    def test_detach_calls_detach_volume(self):

3 Source : test_volume.py
with Apache License 2.0
from gethue

    def test_detach_calls_detach_volume(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.detach()
        self.volume_one.connection.detach_volume.assert_called_with(
            1, 2, "/dev/null", False, dry_run=False)

    def test_detach_with_no_attach_data(self):

3 Source : test_volume.py
with Apache License 2.0
from gethue

    def test_detach_with_no_attach_data(self):
        self.volume_two.connection = mock.Mock()
        self.volume_two.detach()
        self.volume_two.connection.detach_volume.assert_called_with(
            1, None, None, False, dry_run=False)

    def test_detach_with_force_calls_detach_volume_with_force(self):

3 Source : test_volume.py
with Apache License 2.0
from gethue

    def test_detach_with_force_calls_detach_volume_with_force(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.detach(True)
        self.volume_one.connection.detach_volume.assert_called_with(
            1, 2, "/dev/null", True, dry_run=False)

    def test_create_snapshot_calls_connection_create_snapshot(self):

3 Source : test_volume.py
with Apache License 2.0
from gethue

    def test_create_snapshot_calls_connection_create_snapshot(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.create_snapshot()
        self.volume_one.connection.create_snapshot.assert_called_with(
            1,
            None,
            dry_run=False
        )

    def test_create_snapshot_with_description(self):

3 Source : test_volume.py
with Apache License 2.0
from gethue

    def test_create_snapshot_with_description(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.create_snapshot("some description")
        self.volume_one.connection.create_snapshot.assert_called_with(
            1,
            "some description",
            dry_run=False
        )

    def test_volume_state_returns_status(self):

3 Source : test_volume.py
with Apache License 2.0
from gethue

    def test_snapshots_returns_snapshots(self):
        snapshot_one = Snapshot()
        snapshot_one.volume_id = 1
        snapshot_two = Snapshot()
        snapshot_two.volume_id = 2

        self.volume_one.connection = mock.Mock()
        self.volume_one.connection.get_all_snapshots.return_value = [snapshot_one, snapshot_two]
        retval = self.volume_one.snapshots()
        self.assertEqual(retval, [snapshot_one])

    def test_snapshots__with_owner_and_restorable_by(self):

3 Source : test_volume.py
with Apache License 2.0
from gethue

    def test_snapshots__with_owner_and_restorable_by(self):
        self.volume_one.connection = mock.Mock()
        self.volume_one.connection.get_all_snapshots.return_value = []
        self.volume_one.snapshots("owner", "restorable_by")
        self.volume_one.connection.get_all_snapshots.assert_called_with(
            owner="owner", restorable_by="restorable_by", dry_run=False)


class AttachmentSetTests(unittest.TestCase):

3 Source : test_concurrent.py
with Apache License 2.0
from gethue

    def test_calculate_required_part_size(self):
        self.stat_mock.return_value.st_size = 1024 * 1024 * 8
        uploader = ConcurrentUploader(mock.Mock(), 'vault_name')
        total_parts, part_size = uploader._calculate_required_part_size(
            1024 * 1024 * 8)
        self.assertEqual(total_parts, 2)
        self.assertEqual(part_size, 4 * 1024 * 1024)

    def test_calculate_required_part_size_too_small(self):

3 Source : test_concurrent.py
with Apache License 2.0
from gethue

    def test_calculate_required_part_size_too_small(self):
        too_small = 1 * 1024 * 1024
        self.stat_mock.return_value.st_size = 1024 * 1024 * 1024
        uploader = ConcurrentUploader(mock.Mock(), 'vault_name',
                                      part_size=too_small)
        total_parts, part_size = uploader._calculate_required_part_size(
            1024 * 1024 * 1024)
        self.assertEqual(total_parts, 256)
        # Part size if 4MB not the passed in 1MB.
        self.assertEqual(part_size, 4 * 1024 * 1024)

    def test_work_queue_is_correctly_populated(self):

3 Source : test_concurrent.py
with Apache License 2.0
from gethue

    def test_fileobj_closed_when_thread_shuts_down(self):
        thread = UploadWorkerThread(mock.Mock(), 'vault_name',
                                    self.filename, 'upload_id',
                                    Queue(), Queue())
        fileobj = thread._fileobj
        self.assertFalse(fileobj.closed)
        # By settings should_continue to False, it should immediately
        # exit, and we can still verify cleanup behavior.
        thread.should_continue = False
        thread.run()
        self.assertTrue(fileobj.closed)

    def test_upload_errors_have_exception_messages(self):

3 Source : test_concurrent.py
with Apache License 2.0
from gethue

    def test_upload_errors_have_exception_messages(self):
        api = mock.Mock()
        job_queue = Queue()
        result_queue = Queue()
        upload_thread = UploadWorkerThread(
            api, 'vault_name', self.filename,
            'upload_id', job_queue, result_queue, num_retries=1,
            time_between_retries=0)
        api.upload_part.side_effect = Exception("exception message")
        job_queue.put((0, 1024))
        job_queue.put(_END_SENTINEL)

        upload_thread.run()
        result = result_queue.get(timeout=1)
        self.assertIn("exception message", str(result))

    def test_num_retries_is_obeyed(self):

3 Source : test_job.py
with Apache License 2.0
from gethue

    def setUp(self):
        self.api = mock.Mock(spec=Layer1)
        self.vault = mock.Mock()
        self.vault.layer1 = self.api
        self.job = Job(self.vault)

    def test_get_job_validate_checksum_success(self):

3 Source : test_job.py
with Apache License 2.0
from gethue

    def test_get_job_validate_checksum_success(self):
        response = GlacierResponse(mock.Mock(), None)
        response['TreeHash'] = 'tree_hash'
        self.api.get_job_output.return_value = response
        with mock.patch('boto.glacier.job.tree_hash_from_str') as t:
            t.return_value = 'tree_hash'
            self.job.get_output(byte_range=(1, 1024), validate_checksum=True)

    def test_get_job_validation_fails(self):

3 Source : test_job.py
with Apache License 2.0
from gethue

    def test_get_job_validation_fails(self):
        response = GlacierResponse(mock.Mock(), None)
        response['TreeHash'] = 'tree_hash'
        self.api.get_job_output.return_value = response
        with mock.patch('boto.glacier.job.tree_hash_from_str') as t:
            t.return_value = 'BAD_TREE_HASH_VALUE'
            with self.assertRaises(TreeHashDoesNotMatchError):
                # With validate_checksum set to True, this call fails.
                self.job.get_output(byte_range=(1, 1024), validate_checksum=True)
            # With validate_checksum set to False, this call succeeds.
            self.job.get_output(byte_range=(1, 1024), validate_checksum=False)

    def test_download_to_fileobj(self):

3 Source : test_job.py
with Apache License 2.0
from gethue

    def test_download_to_fileobj(self):
        http_response = mock.Mock(read=mock.Mock(return_value='xyz'))
        response = GlacierResponse(http_response, None)
        response['TreeHash'] = 'tree_hash'
        self.api.get_job_output.return_value = response
        fileobj = StringIO()
        self.job.archive_size = 3
        with mock.patch('boto.glacier.job.tree_hash_from_str') as t:
            t.return_value = 'tree_hash'
            self.job.download_to_fileobj(fileobj)
        fileobj.seek(0)
        self.assertEqual(http_response.read.return_value, fileobj.read())

    def test_calc_num_chunks(self):

3 Source : test_vault.py
with Apache License 2.0
from gethue

    def test_small_part_size_is_obeyed(self):
        self.vault.DefaultPartSize = 2 * 1024 * 1024
        self.vault.create_archive_writer = mock.Mock()

        self.getsize.return_value = 1

        with mock.patch('boto.glacier.vault.open', self.mock_open,
                        create=True):
            self.vault.create_archive_from_file('myfile')
        # The write should be created with the default part size of the
        # instance (2 MB).
        self.vault.create_archive_writer.assert_called_with(
            description=mock.ANY, part_size=self.vault.DefaultPartSize)

    def test_large_part_size_is_obeyed(self):

3 Source : test_vault.py
with Apache License 2.0
from gethue

    def test_large_part_size_is_obeyed(self):
        self.vault.DefaultPartSize = 8 * 1024 * 1024
        self.vault.create_archive_writer = mock.Mock()
        self.getsize.return_value = 1
        with mock.patch('boto.glacier.vault.open', self.mock_open,
                        create=True):
            self.vault.create_archive_from_file('myfile')
        # The write should be created with the default part size of the
        # instance (8 MB).
        self.vault.create_archive_writer.assert_called_with(
            description=mock.ANY, part_size=self.vault.DefaultPartSize)

    def test_part_size_needs_to_be_adjusted(self):

3 Source : test_vault.py
with Apache License 2.0
from gethue

    def test_part_size_needs_to_be_adjusted(self):
        # If we have a large file (400 GB)
        self.getsize.return_value = 400 * 1024 * 1024 * 1024
        self.vault.create_archive_writer = mock.Mock()
        # When we try to upload the file.
        with mock.patch('boto.glacier.vault.open', self.mock_open,
                        create=True):
            self.vault.create_archive_from_file('myfile')
        # We should automatically bump up the part size used to
        # 64 MB.
        expected_part_size = 64 * 1024 * 1024
        self.vault.create_archive_writer.assert_called_with(
            description=mock.ANY, part_size=expected_part_size)

    def test_retrieve_inventory(self):

3 Source : test_ssh.py
with Apache License 2.0
from gethue

    def test_timeout(self):
        client_tmp = paramiko.SSHClient

        def client_mock():
            client = client_tmp()
            client.connect = mock.Mock(name='connect')
            return client

        paramiko.SSHClient = client_mock
        paramiko.RSAKey.from_private_key_file = mock.Mock()

        server = mock.Mock()
        test = SSHClient(server)

        self.assertEqual(test._ssh_client.connect.call_args[1]['timeout'], None)

        test2 = SSHClient(server, timeout=30)

        self.assertEqual(test2._ssh_client.connect.call_args[1]['timeout'], 30)

3 Source : test_key.py
with Apache License 2.0
from gethue

    def test_file_error(self):
        key = Key()

        class CustomException(Exception): pass

        key.get_contents_to_file = mock.Mock(
            side_effect=CustomException('File blew up!'))

        # Ensure our exception gets raised instead of a file or IO error
        with self.assertRaises(CustomException):
            key.get_contents_to_filename('foo.txt')

if __name__ == '__main__':

3 Source : test_connection.py
with Apache License 2.0
from gethue

    def test_content_length_str(self):
        request = HTTPRequest('PUT', 'https', 'amazon.com', 443, None,
                              None, {}, {}, 'Body')
        mock_connection = mock.Mock()
        request.authorize(mock_connection)

        # Ensure Content-Length header is a str. This is more explicit than
        # relying on other code cast the value later. (Python 2.7.0, for
        # example, assumes headers are of type str.)
        self.assertIsInstance(request.headers['Content-Length'], str)

if __name__ == '__main__':

See More Examples