From fc7332e639da982b277482dce21d8729e2adbf26 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Jun 09 2016 13:18:35 +0000 Subject: [PATCH 1/2] Add tests for the UpdateProcessor. --- diff --git a/tests/test_hub/test_update_processor.py b/tests/test_hub/test_update_processor.py new file mode 100644 index 0000000..283283e --- /dev/null +++ b/tests/test_hub/test_update_processor.py @@ -0,0 +1,35 @@ +import unittest +import mock + +import kojihub + + +class TestUpdateProcessor(unittest.TestCase): + + def test_basic_instantiation(self): + # TODO -- this doesn't make sense. A query with no arguments should + # probably raise an exception saying "this doesn't make sense." + kojihub.UpdateProcessor('sometable') # No exception! + + def test_to_string_with_data(self): + proc = kojihub.UpdateProcessor('sometable', data={'foo': 'bar'}) + actual = str(proc) + expected = 'UPDATE sometable SET foo = %(data.foo)s' + self.assertEquals(actual, expected) + + def test_to_values_from_data(self): + proc = kojihub.UpdateProcessor('sometable', data={'foo': 'bar'}) + actual = proc.get_values() + expected = {'data.foo': 'bar'} + self.assertEquals(actual, expected) + + @mock.patch('kojihub.context') + def test_simple_execution_with_iterate(self, context): + cursor = mock.MagicMock() + context.cnx.cursor.return_value = cursor + proc = kojihub.UpdateProcessor('sometable', data={'foo': 'bar'}) + proc.execute() + cursor.execute.assert_called_once_with( + 'UPDATE sometable SET foo = %(data.foo)s', + {'data.foo': 'bar'}, + ) From 6a20a55b304626b889242ffda969852589cc9048 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Jun 09 2016 13:19:02 +0000 Subject: [PATCH 2/2] Scrub comments based on feedback from @mikem in #93. --- diff --git a/tests/test_hub/test_update_processor.py b/tests/test_hub/test_update_processor.py index 283283e..e765b3b 100644 --- a/tests/test_hub/test_update_processor.py +++ b/tests/test_hub/test_update_processor.py @@ -7,8 +7,6 @@ import kojihub class TestUpdateProcessor(unittest.TestCase): def test_basic_instantiation(self): - # TODO -- this doesn't make sense. A query with no arguments should - # probably raise an exception saying "this doesn't make sense." kojihub.UpdateProcessor('sometable') # No exception! def test_to_string_with_data(self):