def setUp(self): self.cleanUp() h = DumpTruck(dbname=u"/tmp/test.db") h.save_var(u"birthday", u"November 30, 1888") h.close() connection = sqlite3.connect(u"/tmp/test.db") self.cursor = connection.cursor()
def save_and_check(self, dataIn, tableIn, dataOut, tableOut = None, twice = True): if tableOut == None: tableOut = quote(tableIn) # Insert h = DumpTruck(dbname = '/tmp/test.db') h.insert(dataIn, tableIn) h.close() # Observe with pysqlite connection=sqlite3.connect('/tmp/test.db') cursor=connection.cursor() cursor.execute(u'SELECT * FROM %s' % tableOut) observed1 = cursor.fetchall() connection.close() if twice: # Observe with DumpTruck h = DumpTruck(dbname = '/tmp/test.db') observed2 = h.execute(u'SELECT * FROM %s' % tableOut) h.close() #Check expected1 = dataOut expected2 = [dataIn] if type(dataIn) in (dict, OrderedDict) else dataIn self.assertListEqual(observed1, expected1) self.assertListEqual(observed2, expected2)
def setUp(self): self.cleanUp() h = DumpTruck(dbname = u'/tmp/test.db') h.save_var(u'birthday', u'November 30, 1888') h.close() connection=sqlite3.connect(u'/tmp/test.db') self.cursor=connection.cursor()
def test_no_rows_second_insert(self): "Nothing happens if no rows are inserted to a table that is there." dt = DumpTruck(dbname="/tmp/test.db") dt.create_table({"foo": "uhtnh", "bar": "aoue"}, "ninety") dt.insert([], "ninety") c = dt.execute("select count(*) as c from ninety")[0]["c"] dt.close() self.assertEqual(c, 0)
def test_empty_row_second_insert(self): "An empty row acts like any other row." dt = DumpTruck(dbname="/tmp/test.db") dt.create_table({"foo": "uhtnh", "bar": "aoue"}, "nine") dt.insert({}, "nine") c = dt.execute("select count(*) as c from nine")[0]["c"] dt.close() self.assertEqual(c, 1)
def test_second_insert(self): "Inserting a second row that is all null adds an empty row." dt = DumpTruck(dbname="/tmp/test.db") dt.create_table({"foo": "uhtnh", "bar": "aoue"}, "three") dt.insert({"foo": None, "bar": None}, "three") c = dt.execute("select count(*) as c from three")[0]["c"] dt.close() self.assertEqual(c, 1)
def test_second_insert(self): "Inserting a second row that is all null adds an empty row." dt = DumpTruck(dbname = '/tmp/test.db') dt.create_table({'foo': 'uhtnh', 'bar': 'aoue'}, 'three') dt.insert({'foo': None, 'bar': None}, 'three') c = dt.execute('select count(*) as c from three')[0]['c'] dt.close() self.assertEqual(c, 1)
def test_empty_row_second_insert(self): "An empty row acts like any other row." dt = DumpTruck(dbname = '/tmp/test.db') dt.create_table({'foo': 'uhtnh', 'bar': 'aoue'}, 'nine') dt.insert({}, 'nine') c = dt.execute('select count(*) as c from nine')[0]['c'] dt.close() self.assertEqual(c, 1)
def test_no_rows_second_insert(self): "Nothing happens if no rows are inserted to a table that is there." dt = DumpTruck(dbname = '/tmp/test.db') dt.create_table({'foo': 'uhtnh', 'bar': 'aoue'}, 'ninety') dt.insert([], 'ninety') c = dt.execute('select count(*) as c from ninety')[0]['c'] dt.close() self.assertEqual(c, 0)
def savegetvar(self, var): h = DumpTruck(dbname="/tmp/test.db") h.save_var(u"weird", var) h.close() h = DumpTruck(dbname="/tmp/test.db") t = os.stat("/tmp/test.db").st_mtime self.assertEqual(h.get_var(u"weird"), var) h.close() assert os.stat("/tmp/test.db").st_mtime == t
def savegetvar(self, var): h = DumpTruck(dbname = '/tmp/test.db') h.save_var(u'weird', var) h.close() h = DumpTruck(dbname = '/tmp/test.db') t=os.stat('/tmp/test.db').st_mtime self.assertEqual(h.get_var(u'weird'), var) h.close() assert os.stat('/tmp/test.db').st_mtime==t
def test_create_table(self): h = DumpTruck(dbname="/tmp/test.db") h.create_table({"foo": 0, "bar": 1, "baz": 2}, "zombies") h.close() connection = sqlite3.connect("/tmp/test.db") cursor = connection.cursor() cursor.execute("SELECT foo, bar, baz FROM zombies") observed = cursor.fetchall() connection.close() expected = [] self.assertListEqual(observed, expected)
def test_create_table(self): h = DumpTruck(dbname = '/tmp/test.db') h.create_table({'foo': 0, 'bar': 1, 'baz': 2}, 'zombies') h.close() connection=sqlite3.connect('/tmp/test.db') cursor=connection.cursor() cursor.execute('SELECT foo, bar, baz FROM zombies') observed = cursor.fetchall() connection.close() expected = [] self.assertListEqual(observed, expected)
def test_no_rows_first_insert(self): "Nothing happens if no rows are inserted to a table that isn't there." dt = DumpTruck(dbname = '/tmp/test.db') dt.insert([], 'ninety') self.assertSetEqual(dt.tables(), set()) dt.close()
def test_no_rows_create_table(self): "The insert must have a row so the schema can be defined." dt = DumpTruck(dbname = '/tmp/test.db') with self.assertRaises(ValueError): dt.create_table([], 'two') dt.close()
def test_save(self): h = DumpTruck(dbname="/tmp/test.db") h.insert({"firstname": "Robert", "lastname": "LeTourneau"}, "foo") h.drop("foo") self.assertEqual(h.tables(), set([])) h.close()
def test_empty_row_first_insert(self): "The first row must have a non-null value so the schema can be defined." dt = DumpTruck(dbname = '/tmp/test.db') with self.assertRaises(ValueError): dt.insert({}, 'two') dt.close()
def test_empty_row_create_table(self): "The schema row must have a non-null value." dt = DumpTruck(dbname = '/tmp/test.db') with self.assertRaises(ValueError): dt.create_table({}, 'two') dt.close()
def test_create_table(self): "The first row must have a non-null value so the schema can be defined." dt = DumpTruck(dbname = '/tmp/test.db') with self.assertRaises(ValueError): dt.create_table({'foo': None, 'bar': None}, 'one') dt.close()
def test_first_insert(self): "The first row must have a non-null value so the schema can be defined." dt = DumpTruck(dbname="/tmp/test.db") with self.assertRaises(ValueError): dt.insert({"foo": None, "bar": None}, "two") dt.close()
def get(self, key, value): h = DumpTruck(dbname = u'/tmp/test.db') self.assertEqual(h.get_var(key), value) h.close()
def test_save(self): h = DumpTruck(dbname="/tmp/test.db") data = [{"firstname": "Robert", "lastname": "LeTourneau"}] h.insert(data, "foo") self.assertEqual(data, h.dump("foo")) h.close()
def test_save(self): h = DumpTruck(dbname = '/tmp/test.db') h.insert({'firstname': 'Robert', 'lastname': 'LeTourneau'}, 'foo') h.drop('foo') self.assertEqual(h.tables(), set([])) h.close()
def savegetvar(self, var): h = DumpTruck(dbname = '/tmp/test.db') h.save_var(u'weird', var) self.assertEqual(h.get_var(u'weird'), var) h.close()
def test_save(self): h = DumpTruck(dbname = '/tmp/test.db') data = [{'firstname': 'Robert', 'lastname': 'LeTourneau'}] h.insert(data, 'foo') self.assertEqual(data, h.dump('foo')) h.close()
def save(self, key, value): h = DumpTruck(dbname = u'/tmp/test.db') h.save_var(key, value) h.close()