OmniSciDB  ba1bac9284
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tests.test_integration.TestIntegration Class Reference

Public Member Functions

def test_connect_binary
 
def test_connect_http
 
def test_connect_uri
 
def test_connect_uri_and_others_raises
 
def test_invalid_sql
 
def test_nonexistant_table
 
def test_connection_execute
 
def test_select_sets_description
 
def test_select_parametrized
 
def test_executemany_parametrized
 
def test_executemany_parametrized_insert
 
def test_fetchone
 
def test_fetchmany
 
def test_select_dates
 

Detailed Description

Definition at line 23 of file test_integration.py.

Member Function Documentation

def tests.test_integration.TestIntegration.test_connect_binary (   self)

Definition at line 24 of file test_integration.py.

References omnisci.connection.connect().

24 
25  def test_connect_binary(self):
26  con = connect(
27  user="admin",
28  password='HyperInteractive',
29  host=omniscihost,
30  port=6274,
31  protocol='binary',
32  dbname='omnisci',
33  )
34  assert con is not None

+ Here is the call graph for this function:

def tests.test_integration.TestIntegration.test_connect_http (   self)

Definition at line 35 of file test_integration.py.

References omnisci.connection.connect().

35 
36  def test_connect_http(self):
37  con = connect(
38  user="admin",
39  password='HyperInteractive',
40  host=omniscihost,
41  port=6278,
42  protocol='http',
43  dbname='omnisci',
44  )
45  assert con is not None

+ Here is the call graph for this function:

def tests.test_integration.TestIntegration.test_connect_uri (   self)

Definition at line 46 of file test_integration.py.

References omnisci.connection.connect().

46 
47  def test_connect_uri(self):
48  uri = (
49  'omnisci://admin:HyperInteractive@{0}:6274/omnisci?'
50  'protocol=binary'.format(omniscihost)
51  )
52  con = connect(uri=uri)
53  assert con._user == 'admin'
54  assert con._password == 'HyperInteractive'
55  assert con._host == omniscihost
56  assert con._port == 6274
57  assert con._dbname == 'omnisci'
58  assert con._protocol == 'binary'

+ Here is the call graph for this function:

def tests.test_integration.TestIntegration.test_connect_uri_and_others_raises (   self)

Definition at line 59 of file test_integration.py.

References omnisci.connection.connect().

59 
61  uri = (
62  'omnisci://admin:HyperInteractive@{0}:6274/omnisci?'
63  'protocol=binary'.format(omniscihost)
64  )
65  with pytest.raises(TypeError):
66  connect(username='omnisci', uri=uri)

+ Here is the call graph for this function:

def tests.test_integration.TestIntegration.test_connection_execute (   self,
  con 
)

Definition at line 77 of file test_integration.py.

77 
78  def test_connection_execute(self, con):
79  result = con.execute("drop table if exists FOO;")
80  result = con.execute("create table FOO (a int);")
81  assert isinstance(result, Cursor)
82  con.execute("drop table if exists FOO;")
def tests.test_integration.TestIntegration.test_executemany_parametrized (   self,
  con 
)

Definition at line 136 of file test_integration.py.

137  def test_executemany_parametrized(self, con):
138 
139  c = con.cursor()
140  c.execute('drop table if exists stocks;')
141  create = (
142  'create table stocks (date_ text, trans text, symbol text, '
143  'qty int, price float, vol float);'
144  )
145  c.execute(create)
146  i1 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);" # noqa
147  i2 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);" # noqa
148 
149  c.execute(i1)
150  c.execute(i2)
151 
152  parameters = [{'symbol': 'GOOG'}, {'symbol': "RHAT"}]
153  expected = [[('GOOG', 100)], [('RHAT', 100)]]
154  query = 'select symbol, qty from stocks where symbol = :symbol'
155  c = con.cursor()
156  result = c.executemany(query, parameters)
157  assert result == expected
158  c.execute('drop table if exists stocks;')
def tests.test_integration.TestIntegration.test_executemany_parametrized_insert (   self,
  con 
)

Definition at line 159 of file test_integration.py.

161 
162  c = con.cursor()
163  c.execute('drop table if exists stocks;')
164  create = (
165  'create table stocks (date_ text, trans text, symbol text, '
166  'qty int, price float, vol float);'
167  )
168  c.execute(create)
169  i1 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);" # noqa
170  i2 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);" # noqa
171 
172  c.execute(i1)
173  c.execute(i2)
174 
175  c = con.cursor()
176  c.execute("drop table if exists stocks2;")
177  # Create table
178  c.execute('CREATE TABLE stocks2 (symbol text, qty int);')
179  params = [{"symbol": "GOOG", "qty": 10}, {"symbol": "AAPL", "qty": 20}]
180  query = "INSERT INTO stocks2 VALUES (:symbol, :qty);"
181  result = c.executemany(query, params)
182  assert result == [[], []] # TODO: not sure if this is standard
183  c.execute("drop table stocks2;")
184  c.execute('drop table if exists stocks;')
def tests.test_integration.TestIntegration.test_fetchmany (   self,
  con 
)

Definition at line 206 of file test_integration.py.

207  def test_fetchmany(self, con):
208 
209  c = con.cursor()
210  c.execute('drop table if exists stocks;')
211  create = (
212  'create table stocks (date_ text, trans text, symbol text, '
213  'qty int, price float, vol float);'
214  )
215  c.execute(create)
216  i1 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);" # noqa
217  i2 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);" # noqa
218 
219  c.execute(i1)
220  c.execute(i2)
221 
222  c.execute("select symbol, qty from stocks")
223  result = c.fetchmany()
224  expected = [('RHAT', 100)]
225  assert result == expected
226 
227  c.execute("select symbol, qty from stocks")
228  result = c.fetchmany(size=10)
229  expected = [('RHAT', 100), ('GOOG', 100)]
230  assert result == expected
231  c.execute('drop table if exists stocks;')
def tests.test_integration.TestIntegration.test_fetchone (   self,
  con 
)

Definition at line 185 of file test_integration.py.

186  def test_fetchone(self, con):
187 
188  c = con.cursor()
189  c.execute('drop table if exists stocks;')
190  create = (
191  'create table stocks (date_ text, trans text, symbol text, '
192  'qty int, price float, vol float);'
193  )
194  c.execute(create)
195  i1 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);" # noqa
196  i2 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);" # noqa
197 
198  c.execute(i1)
199  c.execute(i2)
200 
201  c.execute("select symbol, qty from stocks")
202  result = c.fetchone()
203  expected = ('RHAT', 100)
204  assert result == expected
205  c.execute('drop table if exists stocks;')
def tests.test_integration.TestIntegration.test_invalid_sql (   self,
  con 
)

Definition at line 67 of file test_integration.py.

67 
68  def test_invalid_sql(self, con):
69  with pytest.raises(ProgrammingError) as r:
70  con.cursor().execute("this is invalid;")
71  r.match("Exception: SQL Error:")
def tests.test_integration.TestIntegration.test_nonexistant_table (   self,
  con 
)

Definition at line 72 of file test_integration.py.

72 
73  def test_nonexistant_table(self, con):
74  with pytest.raises(DatabaseError) as r:
75  con.cursor().execute("select it from fake_table;")
76  r.match("Table 'FAKE_TABLE' does not exist|Object 'fake_table' not")
def tests.test_integration.TestIntegration.test_select_dates (   self,
  con 
)

Definition at line 232 of file test_integration.py.

233  def test_select_dates(self, con):
234 
235  c = con.cursor()
236  c.execute('drop table if exists dates;')
237  c.execute(
238  'create table dates (date_ DATE, datetime_ TIMESTAMP, '
239  'time_ TIME);'
240  )
241  i1 = (
242  "INSERT INTO dates VALUES ('2006-01-05','2006-01-01T12:00:00',"
243  "'12:00:00');"
244  )
245  i2 = (
246  "INSERT INTO dates VALUES ('1901-12-14','1901-12-13T20:45:53',"
247  "'23:59:00');"
248  )
249  c.execute(i1)
250  c.execute(i2)
251 
252  result = list(c.execute("select * from dates"))
253  expected = [
254  (
255  datetime.date(2006, 1, 5),
256  datetime.datetime(2006, 1, 1, 12),
257  datetime.time(12),
258  ),
259  (
260  datetime.date(1901, 12, 14),
261  datetime.datetime(1901, 12, 13, 20, 45, 53),
262  datetime.time(23, 59),
263  ),
264  ]
265  assert result == expected
266  c.execute('drop table if exists dates;')
267 
def tests.test_integration.TestIntegration.test_select_parametrized (   self,
  con 
)

Definition at line 110 of file test_integration.py.

111  def test_select_parametrized(self, con):
112 
113  c = con.cursor()
114  c.execute('drop table if exists stocks;')
115  create = (
116  'create table stocks (date_ text, trans text, symbol text, '
117  'qty int, price float, vol float);'
118  )
119  c.execute(create)
120  i1 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);" # noqa
121  i2 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);" # noqa
122 
123  c.execute(i1)
124  c.execute(i2)
125 
126  c.execute(
127  'select symbol, qty from stocks where symbol = :symbol',
128  {'symbol': 'GOOG'},
129  )
130  result = list(c)
131  expected = [
132  ('GOOG', 100),
133  ] # noqa
134  assert result == expected
135  c.execute('drop table if exists stocks;')
def tests.test_integration.TestIntegration.test_select_sets_description (   self,
  con 
)

Definition at line 83 of file test_integration.py.

References omnisci._parsers.Description.

83 
84  def test_select_sets_description(self, con):
85 
86  c = con.cursor()
87  c.execute('drop table if exists stocks;')
88  create = (
89  'create table stocks (date_ text, trans text, symbol text, '
90  'qty int, price float, vol float);'
91  )
92  c.execute(create)
93  i1 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);" # noqa
94  i2 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);" # noqa
95 
96  c.execute(i1)
97  c.execute(i2)
98 
99  c.execute("select * from stocks")
100  expected = [
101  Description('date_', 6, None, None, None, None, True),
102  Description('trans', 6, None, None, None, None, True),
103  Description('symbol', 6, None, None, None, None, True),
104  Description('qty', 1, None, None, None, None, True),
105  Description('price', 3, None, None, None, None, True),
106  Description('vol', 3, None, None, None, None, True),
107  ]
108  assert c.description == expected
109  c.execute('drop table if exists stocks;')
tuple Description
Definition: _parsers.py:11

The documentation for this class was generated from the following file: