def test_cursor_can_fetchall(self): query = 'foo' rows = [('bar', 'baz'), ('spam', 'eggs'), ('foo', 'fad')] mock_cursor = get_mock_cursor({query: rows}) mock_cursor.execute('foo') result = mock_cursor.fetchall() self.assertEqual(result, rows)
def test_cursor_query_can_take_args(self): query = ('foo', ('spam', )) row = ('bar', ) mock_cursor = get_mock_cursor({query: [row]}) mock_cursor.execute('foo', ('spam', )) result = mock_cursor.fetchone() self.assertEqual(result, row)
def test_cursor_raises_when_no_results(self): query = 'foo' # Query without results rows = None mock_cursor = get_mock_cursor({query: rows}) mock_cursor.execute('foo') self.assertRaises(mockProgrammingError, mock_cursor.fetchone)
def test_cursor_returns_when_no_results(self): query = 'foo' rows = [('bar', 'baz'), ('spam', 'eggs'), ('foo', 'fad')] mock_cursor = get_mock_cursor({query: rows}) mock_cursor.execute('foo') # empty results mock_cursor.fetchall() result = mock_cursor.fetchone() self.assertEqual(result, None)
def test_cursor_has_option_to_accept_any_query(self): mock_cursor = get_mock_cursor({}, strict=False) try: mock_cursor.execute('foo') except NotImplementedError: self.fail('Should not raise NotImplementedError when strict=False')
def test_cursor_raises_when_no_query(self): mock_cursor = get_mock_cursor({}) self.assertRaises(mockProgrammingError, mock_cursor.fetchone)
def test_cursor_can_fetchone(self): row = ('bar', ) mock_cursor = get_mock_cursor({'foo': [row]}) mock_cursor.execute('foo') result = mock_cursor.fetchone() self.assertEqual(result, row)
def test_cursor_can_execute_query(self): mock_cursor = get_mock_cursor({'foo': 'bar'}) mock_cursor.execute('foo')