예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
 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')
예제 #6
0
 def test_cursor_raises_when_no_query(self):
     mock_cursor = get_mock_cursor({})
     self.assertRaises(mockProgrammingError, mock_cursor.fetchone)
예제 #7
0
 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)
예제 #8
0
 def test_cursor_can_execute_query(self):
     mock_cursor = get_mock_cursor({'foo': 'bar'})
     mock_cursor.execute('foo')