def test_process_check_do_bad_func(self): """ process should raise error on invalid doFunc parameter """ with self.assertRaises(ValueError) as context: s3.process(self.doBadFunc, '', '', bucket=self.bucket) self.assertTrue(self.err_doFunc in context.exception)
def test_process_check_bucket_false(self, mock_check): """ process should raise error on check_bucket exception """ mock_check.return_value = self.mock_check_false with self.assertRaises(ValueError) as context: s3.process(self.doFunc, '', '', bucket=self.bucket) self.assertTrue(self.err_bucket in context.exception)
def test_process_boto3_error(self, mock_check, mock_boto3): """ process should raise error on boto3.client exception """ mock_check.return_value = self.mock_check_true mock_boto3.Session.side_effect = self.mock_client_err with self.assertRaises(ClientError) as context: s3.process(self.doFunc, '', '', bucket=self.bucket) self.assertTrue(self.err_boto3_msg in context.exception.message)
def test_process_xml(self, mock_check, mock_boto3): """ process should be able to process 'test/*.xml' keys """ self.mock_iterator.search.return_value = self.mock_prefix_test_xmls mock_check.return_value = self.mock_check_true mock_boto3.Session.return_value = self.mock_session s3.process(self.doFunc, "test", ".xml", bucket=self.bucket) self.mock_client.get_paginator.assert_called_with('list_objects') self.mock_paginator.paginate.assert_called_with( **self.mock_params_test_xmls) self.mock_iterator.search.assert_called_with('CommonPrefixes') self.assertEqual(self.mock_doFunc.call_count, len(self.mock_prefix_test_xmls))
def test_process(self, mock_check, mock_boto3): """ process should be able to process with no suffix """ self.mock_iterator.search.return_value = self.mock_prefix_more_keys mock_check.return_value = self.mock_check_true mock_boto3.Session.return_value = self.mock_session s3.process(self.doFunc, "more", "", bucket=self.bucket) self.mock_client.get_paginator.assert_called_with('list_objects') self.mock_paginator.paginate.assert_called_with( **self.mock_params_more_keys) self.mock_iterator.search.assert_called_with('Contents') self.assertEqual(self.mock_doFunc.call_count, len(self.mock_prefix_more_keys))