OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test_cursor.py
Go to the documentation of this file.
1 import pytest
2 from heavydb.cursor import Cursor, _bind_parameters
3 from heavydb import connect
4 
5 
6 @pytest.fixture
7 def mock_connection(mock_client):
8  """Connection with mocked transport layer, and
9 
10  - username='user'
11  - password='password'
12  - host='localhost'
13  - dbname='dbname'
14  """
15  return connect(
16  user='user', password='password', host='localhost', dbname='dbname'
17  )
18 
19 
20 class TestCursor:
22  c = Cursor(None)
23  result = list(c)
24  assert result == []
25 
26  def test_escape_basic(self):
27  query = "select * from foo where bar > :baz"
28  result = str(_bind_parameters(query, {"baz": 10}))
29  expected = 'select * from foo where bar > 10'
30  assert result == expected
31 
33  query = "select * from foo where bar > :baz"
34  result = str(_bind_parameters(query, {"baz": '1; drop table foo'}))
35  # note the inner quotes
36  expected = "select * from foo where bar > '1; drop table foo'"
37  assert result == expected
38 
39  def test_arraysize(self):
40  c = Cursor(None)
41  assert c.arraysize == 1
42  c.arraysize = 10
43  assert c.arraysize == 10
44 
45  with pytest.raises(TypeError):
46  c.arraysize = 'a'
def _bind_parameters
Definition: _parsers.py:162