def test_download_retry_exceeded_error(caplog): """Tests whether a retry exceeded error is handled as expected when downloading.""" caplog.set_level(logging.DEBUG, "snowflake.connector") mock_resource = MagicMock() mock_resource.download_file.side_effect = RetriesExceededError( Boto3Error()) client_meta = { "cloud_client": mock_resource, "stage_info": { "location": "loc" }, } meta = { "name": "f", "src_file_name": "f", "stage_location_type": "S3", "client_meta": SFResourceMeta(**client_meta), "sha256_digest": "asd", "src_file_size": 99, "get_callback_output_stream": None, "show_progress_bar": False, "get_callback": None, } meta = SnowflakeFileMeta(**meta) with mock.patch( "snowflake.connector.s3_util.SnowflakeS3Util._get_s3_object", return_value=mock_resource, ): SnowflakeS3Util._native_download_file(meta, "f", 4) assert meta.last_error is mock_resource.download_file.side_effect assert meta.result_status == ResultStatus.NEED_RETRY
def __assume_role(self, mfa_code): # This is a way to get around the strange way of handling arguments (not accepting none) assume_role_args = { "RoleArn": self._profile.role_arn, "RoleSessionName": self._profile.role_session_name, "DurationSeconds": self._profile.duration_seconds, } if self._profile.external_id: assume_role_args['ExternalId'] = self._profile.external_id if self._profile.mfa_serial: assume_role_args['SerialNumber'] = self._profile.mfa_serial if mfa_code: assume_role_args['TokenCode'] = mfa_code response = self._client.assume_role(**assume_role_args) if 'Credentials' in response: self._credential = AWSCredential( aws_access_key_id=response['Credentials']['AccessKeyId'], aws_secret_access_key=response['Credentials'] ['SecretAccessKey'], aws_session_token=response['Credentials']['SessionToken'], expiration=response['Credentials']['Expiration'], profile=self) else: raise Boto3Error("No Credential in STS response found")
def test_remote_missing_silent(get_bucket, load_to): config = Mock() get_bucket().download_fileobj.side_effect = Boto3Error('test') res = load_from_s3(config, filename='s3://somebucket/mycfg.py', silent=True) assert res is False load_to.assert_not_called()
def test_send_notification_to_queue_throws_exception_deletes_notification( sample_notification, mocker): mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async', side_effect=Boto3Error("EXPECTED")) with pytest.raises(Boto3Error): send_notification_to_queue(sample_notification, False) mocked.assert_called_once_with([(str(sample_notification.id))], queue='send-sms') assert Notification.query.count() == 0 assert NotificationHistory.query.count() == 0
def test_remote_missing(get_bucket, load_to): config = Mock() get_bucket().download_fileobj.side_effect = Boto3Error('test') with pytest.raises(Boto3Error) as e: load_from_s3(config, filename='s3://somebucket/mycfg.py') assert str(e.value) == 'test' load_to.assert_not_called()
def __init__(self): self._stream_name = config['kinesis_stream'] self._pending_records = [] if not self._stream_name: raise Boto3Error('kinesis_stream should not be empty') self._kinesis_kwargs = dict( service_name='kinesis', aws_access_key_id=config['aws_access_key_id'], aws_secret_access_key=config['aws_secret_access_key'], region_name=config['aws_region']) get_io_loop().spawn_callback(self.run)
def test_download_retry_exceeded_error(caplog): """Tests whether a retry exceeded error is handled as expected when downloading.""" mock_resource = MagicMock() mock_resource.download_file.side_effect = RetriesExceededError(Boto3Error()) meta = {'client': mock_resource, 'sha256_digest': 'asd', 'stage_info': {'location': 'loc'}, 'src_file_name': 'f', 'src_file_size': 99, 'get_callback_output_stream': None, 'show_progress_bar': False, 'get_callback': None} with mock.patch('snowflake.connector.s3_util.SnowflakeS3Util._get_s3_object', return_value=mock_resource): SnowflakeS3Util._native_download_file(meta, 'f', 4) assert meta['last_error'] is mock_resource.download_file.side_effect assert meta['result_status'] == ResultStatus.NEED_RETRY
def test_download_retry_exceeded_error(caplog): """Tests whether a retry exceeded error is handled as expected when downloading.""" caplog.set_level(logging.DEBUG, 'snowflake.connector') mock_resource = MagicMock() mock_resource.download_file.side_effect = RetriesExceededError(Boto3Error()) client_meta = { 'cloud_client': mock_resource, 'stage_info': {'location': 'loc'}, } meta = {'name': 'f', 'src_file_name': 'f', 'stage_location_type': 'S3', 'client_meta': SFResourceMeta(**client_meta), 'sha256_digest': 'asd', 'src_file_size': 99, 'get_callback_output_stream': None, 'show_progress_bar': False, 'get_callback': None} meta = SnowflakeFileMeta(**meta) with mock.patch('snowflake.connector.s3_util.SnowflakeS3Util._get_s3_object', return_value=mock_resource): SnowflakeS3Util._native_download_file(meta, 'f', 4) assert meta.last_error is mock_resource.download_file.side_effect assert meta.result_status == ResultStatus.NEED_RETRY
def execute_mock(job, process_number): if job["job_id"] == 2: raise Boto3Error("Something is gone wrong")
def test_should_raises_runtime_error_on_request(): with patch('awsenviron.boto3.client', return_value=SSMStub(response=Boto3Error())): with pytest.raises(EnvironmentError): awsenviron.load_from_parameter_store(path='/FOO/')