[CalendarServer-changes] [9643] CalendarServer/branches/users/glyph/q

source_changes at macosforge.org source_changes at macosforge.org
Sat Aug 11 01:55:16 PDT 2012


Revision: 9643
          http://trac.macosforge.org/projects/calendarserver/changeset/9643
Author:   glyph at apple.com
Date:     2012-08-11 01:55:16 -0700 (Sat, 11 Aug 2012)
Log Message:
-----------
simple query test, stub, and fix to give records some column attributes

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py
    CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_record.py

Property Changed:
----------------
    CalendarServer/branches/users/glyph/q/

Modified: CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py
===================================================================
--- CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py	2012-08-11 08:55:15 UTC (rev 9642)
+++ CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py	2012-08-11 08:55:16 UTC (rev 9643)
@@ -157,7 +157,14 @@
         self.__dict__.update(kw)
 
 
+    @classmethod
+    @inlineCallbacks
+    def query(cls, expr, order=None):
+        yield None
+        returnValue([])
 
+
+
 def fromTable(table):
     """
     Create a L{type} that maps the columns from a particular table.
@@ -175,8 +182,9 @@
         attrname = column.model.name.lower()
         attrmap[attrname] = column
         colmap[column] = attrname
-    return type(table.model.name, tuple([_RecordBase]),
-                dict(__tbl__=table, __attrmap__=attrmap, __colmap__=colmap))
+    ns = dict(__tbl__=table, __attrmap__=attrmap, __colmap__=colmap)
+    ns.update(attrmap)
+    return type(table.model.name, tuple([_RecordBase]), ns)
 
 
 

Modified: CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_record.py
===================================================================
--- CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_record.py	2012-08-11 08:55:15 UTC (rev 9642)
+++ CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_record.py	2012-08-11 08:55:16 UTC (rev 9643)
@@ -157,4 +157,23 @@
         self.assertEqual(rec.gamma, u'otherwise')
 
 
+    @inlineCallbacks
+    def test_simpleQuery(self):
+        """
+        L{Record.query} will allow you to query for a record by its class
+        attributes as columns.
+        """
+        txn = self.pool.connection()
+        for beta, gamma in [(123, u"one"), (234, u"two"), (345, u"three"),
+                            (356, u"three"), (456, u"four")]:
+            yield txn.execSQL("insert into ALPHA values (:1, :2)",
+                              [beta, gamma])
+        records = yield TestRecord.query(TestRecord.gamma == u"three",
+                                         TestRecord.beta)
+        self.assertEqual(len(records), 2)
+        self.assertEqual(records[0].beta, 345)
+        self.assertEqual(records[1].beta, 356)
 
+
+
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120811/08655e5a/attachment.html>


More information about the calendarserver-changes mailing list