Ejemplo n.º 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()
Ejemplo n.º 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)
Ejemplo n.º 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()
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 21
0
 def get(self, key, value):
   h = DumpTruck(dbname = u'/tmp/test.db')
   self.assertEqual(h.get_var(key), value)
   h.close()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 26
0
 def save(self, key, value):
   h = DumpTruck(dbname = u'/tmp/test.db')
   h.save_var(key, value)
   h.close()