2013-04-01 19:38:02 +02:00
|
|
|
import unittest
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
from dataset import connect
|
2013-04-01 19:46:17 +02:00
|
|
|
from sample_data import TEST_DATA
|
2013-04-01 19:38:02 +02:00
|
|
|
|
|
|
|
|
class DatabaseTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
self.db = connect('sqlite:///:memory:')
|
2013-04-01 19:46:17 +02:00
|
|
|
self.tbl = self.db['weather']
|
|
|
|
|
for row in TEST_DATA:
|
|
|
|
|
self.tbl.insert(row)
|
2013-04-01 19:38:02 +02:00
|
|
|
|
|
|
|
|
def test_create_table(self):
|
|
|
|
|
table = self.db['foo']
|
|
|
|
|
assert table.table.exists()
|
|
|
|
|
assert len(table.table.columns) == 1, table.table.columns
|
2013-04-01 19:46:17 +02:00
|
|
|
assert 'id' in table.table.c, table.table.c
|
|
|
|
|
|
|
|
|
|
def test_load_table(self):
|
|
|
|
|
tbl = self.db.load_table('weather')
|
|
|
|
|
assert tbl.table==self.tbl.table
|
|
|
|
|
|
|
|
|
|
def test_query(self):
|
|
|
|
|
r = self.db.query('SELECT COUNT(*) AS num FROM weather').next()
|
|
|
|
|
assert r['num']==len(TEST_DATA), r
|
|
|
|
|
|
2013-04-01 19:38:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|
|
|
|
|
|