示例#1
0
    def testupdate(self):
        a = stupid_dict(self.sampleA)
        c = stupid_dict(self.sampleC)

        a.update(c)

        self.assert_( a["A"] == 1)
        self.assert_( a["B"] == "b")
示例#2
0
    def testupdate(self):
        a = stupid_dict(self.sampleA)
        c = stupid_dict(self.sampleC)

        a.update(c)

        self.assert_(a["A"] == 1)
        self.assert_(a["B"] == "b")
示例#3
0
    def test__eq__(self):
        d1 = stupid_dict(self.sampleC)
        d2 = stupid_dict((
            (
                "B",
                "b",
            ),
            (
                "D",
                4,
            ),
        ))

        self.assertEqual(d1, d2)
示例#4
0
 def testvalues(self):
     d = stupid_dict(self.sampleB)
     self.assertEqual(d.values(), [
         "A",
         "B",
         "C",
     ])
示例#5
0
 def testkeys(self):
     d = stupid_dict(self.sampleB)
     self.assert_(d.keys() == [
         1,
         2,
         3,
     ])
示例#6
0
    def select_for_update(self, dbclass, key):
        """
        This method works like L{select_by_primary_key} above, except that it
        doesn't select anything but returns a dummy object (an empty dbobj)
        that will allow setting attributes, yielding proper UPDATE statements.
        Note that supplying a primary key that does not exist will go
        unnoticed: The UPDATE statements won't create an error, they just
        won't affect any rows.

        This method is primarily ment for transaction based (i.e. www)
        applications.
        """
        if type(key) != TupleType: key = (key, )
        primary_key = keys.primary_key(dbclass)

        if len(key) != len(primary_key.key_attributes):
            msg = "The primary key for %s must have %i elements." % \
                     ( repr(dbclass), len(primary_key.key_attributes), )
            raise IllegalPrimaryKey(msg)

        info = stupid_dict()
        for property, value in zip(primary_key.attributes(), key):
            info[property.column] = value

        return dbclass.__from_result__(self, info)
示例#7
0
    def select_for_update(self, dbclass, key):
        """
        This method works like L{select_by_primary_key} above, except that it
        doesn't select anything but returns a dummy object (an empty dbobj)
        that will allow setting attributes, yielding proper UPDATE statements.
        Note that supplying a primary key that does not exist will go
        unnoticed: The UPDATE statements won't create an error, they just
        won't affect any rows.

        This method is primarily ment for transaction based (i.e. www)
        applications.
        """
        if type(key) != TupleType: key = ( key, )
        primary_key = keys.primary_key(dbclass)

        if len(key) != len(primary_key.key_attributes):
            msg = "The primary key for %s must have %i elements." % \
                     ( repr(dbclass), len(primary_key.key_attributes), )
            raise IllegalPrimaryKey(msg)

        info = stupid_dict()
        for property, value in zip(primary_key.attributes(), key):        
            info[property.column] = value

        return dbclass.__from_result__(self, info)
示例#8
0
 def update(
     self,
     relation,
     column,
     sql_literal,
     where,
 ):
     """
     Updates are stored in a list and executed on calls to commit() or to
     flush_updates() to join updates to the same row into a single SQL
     command.
     
     @param relation: The relation to be updated
     @param column: sql.column Name of the column to be updated
     @param sql_literal: sql literal of the value to be stored.
     @param where: where clause that would select (or update in this case)
       the desired row from relation
     """
     key = (
         relation,
         where,
     )
     data = self._updates.get(key, stupid_dict())
     data[column] = sql_literal
     self._updates[key] = data
示例#9
0
 def rollback(self):
     """
     Undo the changes you made to the database since the last commit()
     """
     self._updates = stupid_dict()
     db = getattr(self._conn, "db", None)
     if db is not None:
         db.rollback()
示例#10
0
    def test__iter__(self):
        d = stupid_dict(self.sampleC)

        l = []
        for key in d:
            l.append(key)

        self.assertEqual(l, ["B", "D"])
示例#11
0
    def test__iter__(self):
        d = stupid_dict(self.sampleC)

        l = []
        for key in d:
            l.append(key)

        self.assertEqual(l, ["B", "D"])
示例#12
0
    def test__delitem__(self):
        d = stupid_dict(self.sampleC)
        
        del d["B"]

        self.assertEqual(d.data, [("D", 4,)])

        self.assertRaises(KeyError, d.__delitem__, "X")
示例#13
0
    def test__setitem__(self):
        d = stupid_dict(self.sampleA)
        d["D"] = 4

        self.assert_((
            "D",
            4,
        ) in d.data)
示例#14
0
 def rollback(self):
     """
     Undo the changes you made to the database since the last commit()
     """
     self._updates = stupid_dict()
     db = getattr(self._conn, "db", None)
     if db is not None:
         db.rollback()
示例#15
0
    def test__getitem__(self):
        for sample in self.samples:
            a = stupid_dict(sample)

            if type(sample) == DictType:
                items = sample.items()
            else:
                items = sample

            for key, value in items:
                self.assertEqual(a[key], value)
示例#16
0
    def test__getitem__(self):
        for sample in self.samples:
            a = stupid_dict(sample)

            if type(sample) == DictType:
                items = sample.items()
            else:
                items = sample

            for key, value in items:
                self.assertEqual(a[key], value)
示例#17
0
    def test__delitem__(self):
        d = stupid_dict(self.sampleC)

        del d["B"]

        self.assertEqual(d.data, [(
            "D",
            4,
        )])

        self.assertRaises(KeyError, d.__delitem__, "X")
示例#18
0
    def test__init__(self):
        self.assertRaises(ValueError, stupid_dict, (
            (
                1,
                2,
            ),
            1,
            2,
        ))
        self.assertRaises(ValueError, stupid_dict, "kacke")

        d = stupid_dict({"a": 1, "b": 2})
示例#19
0
    def next(self):
        if hasattr(self, "rows"):
            if len(self.rows) == 0:
                tpl = None
            else:
                tpl = self.rows.pop()
        else:
            tpl = self.cursor.fetchone()

        if tpl is None:
            raise StopIteration
        else:
            info = stupid_dict(zip(self.columns, tpl))
            return self.dbclass.__from_result__(self.ds, info)
示例#20
0
    def next(self):
        if hasattr(self, "rows"):
            if len(self.rows) == 0:
                tpl = None
            else:
                tpl = self.rows.pop()
        else:
            tpl = self.cursor.fetchone()

        if tpl is None:
            raise StopIteration
        else:
            info = stupid_dict(zip(self.columns, tpl))
            return self.dbclass.__from_result__(self.ds, info)
示例#21
0
    def __select_columns__(cls):
        """
        A list of columns to select from the elation to construct one
        of these. 
        """
        # The use of the stupid_dict class has become neccessary, because
        # sql._part instances are not hashable.
        columns = stupid_dict()
        for property in cls.__dbproperties__():
            if property.__select_this_column__():
                columns[property.column] = 0
                
        columns = list(columns.keys())

        return columns
示例#22
0
    def __select_columns__(cls):
        """
        A list of columns to select from the elation to construct one
        of these. 
        """
        # The use of the stupid_dict class has become neccessary, because
        # sql._part instances are not hashable.
        columns = stupid_dict()
        for property in cls.__dbproperties__():
            if property.__select_this_column__():
                columns[property.column] = 0

        columns = list(columns.keys())

        return columns
示例#23
0
 def update(self, relation, column, sql_literal, where, ):
     """
     Updates are stored in a list and executed on calls to commit() or to
     flush_updates() to join updates to the same row into a single SQL
     command.
     
     @param relation: The relation to be updated
     @param column: sql.column Name of the column to be updated
     @param sql_literal: sql literal of the value to be stored.
     @param where: where clause that would select (or update in this case)
       the desired row from relation
     """
     key = ( relation, where, )
     data = self._updates.get(key, stupid_dict())
     data[column] = sql_literal
     self._updates[key] = data
示例#24
0
 def testitems(self):
     d = stupid_dict(self.sampleB)
     self.assertEqual(d.items(), list(self.sampleB))
示例#25
0
    def testhas_key(self):
        d = stupid_dict(self.sampleB)

        self.assert_(d.has_key(1))
        self.assert_(not d.has_key(0))
示例#26
0
 def test__contains__(self):
     d = stupid_dict(self.sampleC)
     
     self.assert_("B" in d)
     self.assert_(not "X" in d)
示例#27
0
    def test__setitem__(self):
        d = stupid_dict(self.sampleA)
        d["D"] = 4

        self.assert_( ("D", 4,) in d.data )
示例#28
0
 def testclear(self):
     d = stupid_dict(self.sampleB)
     d.clear()
     self.assertEqual(len(d), 0)
示例#29
0
    def test__eq__(self):
        d1 = stupid_dict(self.sampleC)
        d2 = stupid_dict((("B", "b",), ("D", 4,),))

        self.assertEqual(d1, d2)
示例#30
0
 def testitems(self):
     d = stupid_dict(self.sampleB)
     self.assertEqual(d.items(), list(self.sampleB))
示例#31
0
    def testcopy(self):
        d = stupid_dict(self.sampleB)
        e = d.copy()

        self.assert_(id(d) != id(e) and d == e)
示例#32
0
 def testvalues(self):
     d = stupid_dict(self.sampleB)
     self.assertEqual(d.values(), [ "A", "B", "C", ])
示例#33
0
    def test__contains__(self):
        d = stupid_dict(self.sampleC)

        self.assert_("B" in d)
        self.assert_(not "X" in d)
示例#34
0
    def testsetdefault(self):
        d = stupid_dict(self.sampleB)
        d.setdefault("X")

        self.assert_(d[0] == "X")
        self.assert_(d[1] == "A")
示例#35
0
    def test__init__(self):
        self.assertRaises(ValueError, stupid_dict, ( (1, 2,), 1, 2, ))
        self.assertRaises(ValueError, stupid_dict, "kacke")

        d = stupid_dict({"a": 1, "b": 2})
示例#36
0
 def test__len__(self):
     for a in self.samples:
         d = stupid_dict(a)
         self.assertEqual(len(d), len(a))
示例#37
0
    def testsetdefault(self):
        d = stupid_dict(self.sampleB)
        d.setdefault("X")

        self.assert_(d[0] == "X")
        self.assert_(d[1] == "A")
示例#38
0
 def test__repr__(self):
     d = stupid_dict(self.sampleB)
     self.assertEqual(repr(d), "stupid_dict(%s)" % repr(list(self.sampleB)))
示例#39
0
    def testget(self):
        d = stupid_dict(self.sampleB)

        self.assertEqual(d.get(1), "A")
        self.assertEqual(d.get(0, "X"), "X")
        self.assertEqual(d.get(0), None)
示例#40
0
 def testclear(self):
     d = stupid_dict(self.sampleB)
     d.clear()
     self.assertEqual(len(d), 0)
示例#41
0
 def test__len__(self):
     for a in self.samples:
         d = stupid_dict(a)
         self.assertEqual(len(d), len(a))
示例#42
0
    def testcopy(self):
        d = stupid_dict(self.sampleB)
        e = d.copy()

        self.assert_(id(d) != id(e) and d == e)
示例#43
0
 def test__repr__(self):
     d = stupid_dict(self.sampleB)
     self.assertEqual(repr(d), "stupid_dict(%s)" % repr(list(self.sampleB)))
示例#44
0
    def testget(self):
        d = stupid_dict(self.sampleB)

        self.assertEqual(d.get(1), "A")
        self.assertEqual(d.get(0, "X"), "X")
        self.assertEqual(d.get(0), None)
示例#45
0
 def __init__(self):
     self._conn = None
     self._updates = stupid_dict()
     self._update_cursor = None
     self._debug = 0    
示例#46
0
    def testhas_key(self):
        d = stupid_dict(self.sampleB)

        self.assert_(d.has_key(1))
        self.assert_(not d.has_key(0))
示例#47
0
 def __init__(self):
     self._conn = None
     self._updates = stupid_dict()
     self._update_cursor = None
     self._debug = 0
示例#48
0
 def testkeys(self):
     d = stupid_dict(self.sampleB)
     self.assert_(d.keys() == [ 1, 2, 3, ])