Ejemplo n.º 1
0
 def test_index(self):
     x = _DBTable(parent_schema=None, name='x', pk='row_id')
     x.add_row({'row_id':1, 'val':'value1'})
     x.add_row({'row_id':2, 'val':'value2'})
     x.add_row({'row_id':3, 'val':'valueX'})
     x.add_row({'row_id':4, 'val':'valueX'})
     self.assertFalse(x._index_exists(('val',)))
     self.assertFalse(x._index_exists('something else'))
     x._index_create(('val',))
     self.assertTrue(x._index_exists(('val',)))
     self.assertFalse(x._index_exists('something else'))
     rows = x._index_find_rows(('val',), ('valueX',))
     self.assertEqual(rows, set([x[3], x[4]]))
     no_rows = x._index_find_rows(('val',), ('notvalue',))
     for row in no_rows:
         self.assertTrue(False) # no iterations expected
     x._index_clear_all()
     self.assertFalse(x._index_exists(('val',)))
Ejemplo n.º 2
0
    def test_find_rows(self):
        x = _DBTable(parent_schema=None, name='x', pk='row_id')
        x.add_row({'row_id':1, 'val':'value1'})
        x.add_row({'row_id':2, 'val':'value2'})
        x.add_row({'row_id':3, 'val':'valueX'})
        x.add_row({'row_id':4, 'val':'valueX'})

        # Find one row, based on one column
        rows = x.find_rows(['val'], ['value2'])
        self.assertEqual(len(rows), 1)
        self.assertEqual(list(rows)[0].row_id.value, 2)

        # Find more then one row, based on one column
        rows = x.find_rows(['val'], ['valueX'])
        self.assertEqual(len(rows), 2)
        self.assertItemsEqual([r.row_id.value for r in rows], [3,4])

        # Find one row, based on two columns
        rows = x.find_rows(['val', 'row_id'], ['valueX', 3])
        self.assertEqual(len(rows), 1)
        self.assertEqual(list(rows)[0].row_id.value, 3)
Ejemplo n.º 3
0
 def test_getitem_multivalued_pk(self):
     x = _DBTable(parent_schema=None, name='x', pk='row_id id_modif')
     x.add_row({'row_id':1, 'id_modif':100, 'val':'valueX'})
     self.assertEqual(x[1,100].val.value, 'valueX')
Ejemplo n.º 4
0
 def test_getitem_key_error(self):
     x = _DBTable(parent_schema=None, name='x', pk='row_id')
     x.add_row({'row_id':1, 'val':'valueX'})
     with self.assertRaises(RowKeyError) as cm:
         x[2]
     self.assertEqual(str(cm.exception), 'RowKeyError(x, row_id, (2,))')
Ejemplo n.º 5
0
 def test_getitem(self):
     x = _DBTable(parent_schema=None, name='x', pk='row_id')
     x.add_row({'row_id':1, 'val':'valueX'})
     self.assertEqual(x[1].val.value, 'valueX')
Ejemplo n.º 6
0
 def test_duplicate_check(self):
     x = _DBTable(parent_schema=None, name='x', pk='row_id')
     x.add_row({'row_id':1, 'val':'value1'})
     with self.assertRaises(DuplicateRowException) as cm:
         x.add_row({'row_id':1, 'val':'value1'})
     self.assertEqual(cm.exception.table_name, 'x')
Ejemplo n.º 7
0
 def test_values(self):
     x = _DBTable(parent_schema=None, name='x', pk='row_id')
     x.add_row({'row_id':1, 'val':'value1'})
     for v in x.values():
         self.assertEqual(v.val.value, 'value1')
Ejemplo n.º 8
0
 def test_iteritems_multikey(self):
     x = _DBTable(parent_schema=None, name='x', pk='row_id m')
     x.add_row({'row_id':1, 'm':100, 'val':'value1'})
     for k,v in x.iteritems():
         self.assertEqual(k, (1, 100))
         self.assertEqual(v.val.value, 'value1')
Ejemplo n.º 9
0
 def test_contains(self):
     x = _DBTable(parent_schema=None, name='x', pk='row_id')
     x.add_row({'row_id':1, 'val':'value1'})
     self.assertTrue(1 in x)
Ejemplo n.º 10
0
 def test_contains_multikey(self):
     x = _DBTable(parent_schema=None, name='x', pk='row_id m')
     x.add_row({'row_id':1, 'm':100, 'val':'value1'})
     self.assertTrue((1, 100) in x)