adding class for database response
This commit is contained in:
parent
0d40080f6c
commit
ded26dc46b
@ -2,6 +2,7 @@ import unittest
|
|||||||
|
|
||||||
from mock_plpy import MockPlPy
|
from mock_plpy import MockPlPy
|
||||||
plpy = MockPlPy()
|
plpy = MockPlPy()
|
||||||
|
from mock_plpy import MockDBResponse
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
sys.modules['plpy'] = plpy
|
sys.modules['plpy'] = plpy
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
class MockCursor:
|
class MockCursor:
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
self.cursor_pos = 0
|
self.cursor_pos = 0
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
def fetch(self, batch_size):
|
def fetch(self, batch_size):
|
||||||
batch = self.data[self.cursor_pos : self.cursor_pos + batch_size]
|
batch = self.data[self.cursor_pos:self.cursor_pos + batch_size]
|
||||||
self.cursor_pos += batch_size
|
self.cursor_pos += batch_size
|
||||||
return batch
|
return batch
|
||||||
|
|
||||||
@ -45,8 +46,22 @@ class MockPlPy:
|
|||||||
data = self.execute(query)
|
data = self.execute(query)
|
||||||
return MockCursor(data)
|
return MockCursor(data)
|
||||||
|
|
||||||
def execute(self, query): # TODO: additional arguments
|
# TODO: additional arguments
|
||||||
for result in self.results:
|
def execute(self, query):
|
||||||
if result[0].match(query):
|
for result in self.results:
|
||||||
return result[1]
|
if result[0].match(query):
|
||||||
return []
|
return result[1]
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
class MockDBResponse:
|
||||||
|
def __init__(self, data, colnames=None):
|
||||||
|
self.data = data
|
||||||
|
if colnames is None:
|
||||||
|
self.colnames = data[0].keys()
|
||||||
|
else:
|
||||||
|
self.colnames = colnames
|
||||||
|
|
||||||
|
|
||||||
|
def colnames(self):
|
||||||
|
return self.colnames
|
||||||
|
Loading…
Reference in New Issue
Block a user