class TestDBConnectionWrapper(unittest.TestCase): """ Test that we are wrapping DB connections correctly """ def setUp(self): self.cw = DBConnectionWrapper() #create a fake connection that is a mock as well self.cw._wrapped = Mock() self.cw.execute = MagicMock() self.cw.execute.return_value = MagicMock() self.cw.execute.return_value.fetchall = MagicMock() self.cw.description = MagicMock() def test_select_dataframe(self): return_val = [(1, 2), (3, 4)] headers = [['Col1'], ['col2']] self.cw.execute.return_value.fetchall.return_value = return_val self.cw.execute.return_value.description = headers query = 'my select statement' results = self.cw.select_dataframe(query) #check to see that the headers match but all lower case self.assertEquals([d for d in results.columns], [c[0].lower() for c in headers]) def test_select(self): query = 'my select statement' results = self.cw.select(query) expected = ((1, 2), (3, 4)) results._data = expected self.assertEquals(query, results.query) self.assertEquals(results.data, expected) def check_chunk(self): self.cw.chunks = {'this_chunk': True} self.assertTrue(self.cw.chunk('this_chunk'))
class TestDBConnectionWrapper(unittest.TestCase): """ Test that we are wrapping DB connections correctly """ def setUp(self): self.cw = DBConnectionWrapper() #create a fake connection that is a mock as well self.cw._wrapped = Mock() self.cw.execute = MagicMock() self.cw.execute.return_value = MagicMock() self.cw.execute.return_value.fetchall = MagicMock() self.cw.description = MagicMock() def test_select_dataframe(self): return_val = [(1,2), (3,4)] headers = [['Col1'], ['col2']] self.cw.execute.return_value.fetchall.return_value = return_val self.cw.execute.return_value.description = headers query = 'my select statement' results = self.cw.select_dataframe(query) #check to see that the headers match but all lower case self.assertEquals([d for d in results.columns], [c[0].lower() for c in headers]) def test_select(self): query = 'my select statement' results = self.cw.select(query) expected = ((1,2), (3,4)) results._data = expected self.assertEquals(query, results.query) self.assertEquals(results.data, expected) def check_chunk(self): self.cw.chunks = {'this_chunk':True} self.assertTrue(self.cw.chunk('this_chunk'))
def setUp(self): self.cw = DBConnectionWrapper() #create a fake connection that is a mock as well self.cw._wrapped = Mock() self.cw.execute = MagicMock() self.cw.execute.return_value = MagicMock() self.cw.execute.return_value.fetchall = MagicMock() self.cw.description = MagicMock()