From 1344062bddf9ec22f1e870ecdd9bbee802d26faf Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Nov 19 2019 17:01:14 +0000 Subject: fix typo and extend unit test to cover where it occurred --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 549fee2..aae60c5 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -8429,7 +8429,7 @@ class BulkInsertProcessor(object): def execute(self): if not self.batch: - self.__one_insert(self.data) + self._one_insert(self.data) else: for i in range(0, len(self.data), self.batch): data = self.data[i:i+self.batch] diff --git a/tests/test_hub/test_insert_processor.py b/tests/test_hub/test_insert_processor.py index 17601ed..1feaccd 100644 --- a/tests/test_hub/test_insert_processor.py +++ b/tests/test_hub/test_insert_processor.py @@ -189,3 +189,20 @@ class TestBulkInsertProcessor(unittest.TestCase): calls[1][1], ('INSERT INTO sometable (foo) VALUES (%(foo0)s)', {'foo0': 'bar3'})) + + @mock.patch('kojihub.context') + def test_no_batch_execution(self, context): + cursor = mock.MagicMock() + context.cnx.cursor.return_value = cursor + + proc = kojihub.BulkInsertProcessor('sometable', data=[{'foo': 'bar1'}], batch=None) + proc.add_record(foo='bar2') + proc.add_record(foo='bar3') + proc.execute() + calls = cursor.execute.mock_calls + # list of (name, positional args, keyword args) + self.assertEquals(len(calls), 1) + self.assertEquals( + calls[0][1], + ('INSERT INTO sometable (foo) VALUES (%(foo0)s), (%(foo1)s), (%(foo2)s)', + {'foo0': 'bar1', 'foo1': 'bar2', 'foo2': 'bar3'}))