Example #1
0
 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()
Example #2
0
  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)
Example #3
0
 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()
Example #4
0
 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)
Example #5
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)
Example #6
0
 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)
Example #7
0
 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)
Example #8
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)
Example #9
0
 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)
Example #10
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
Example #11
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
Example #12
0
    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)
Example #13
0
  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)
Example #14
0
 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()
Example #15
0
 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()
Example #16
0
 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()
Example #17
0
 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()
Example #18
0
 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()
Example #19
0
 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()
Example #20
0
 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()
Example #21
0
 def get(self, key, value):
   h = DumpTruck(dbname = u'/tmp/test.db')
   self.assertEqual(h.get_var(key), value)
   h.close()
Example #22
0
 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()
Example #23
0
 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()
Example #24
0
 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()
Example #25
0
 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()
Example #26
0
 def save(self, key, value):
   h = DumpTruck(dbname = u'/tmp/test.db')
   h.save_var(key, value)
   h.close()