[CalendarServer-changes] [9562] CalendarServer/branches/users/glyph/q
source_changes at macosforge.org
source_changes at macosforge.org
Sat Aug 11 01:54:09 PDT 2012
Revision: 9562
http://trac.macosforge.org/projects/calendarserver/changeset/9562
Author: glyph at apple.com
Date: 2012-08-11 01:54:09 -0700 (Sat, 11 Aug 2012)
Log Message:
-----------
Most basic resource-loading test.
Modified Paths:
--------------
CalendarServer/branches/users/glyph/q/twext/enterprise/adbapi2.py
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/adbapi2.py
===================================================================
--- CalendarServer/branches/users/glyph/q/twext/enterprise/adbapi2.py 2012-08-11 08:54:08 UTC (rev 9561)
+++ CalendarServer/branches/users/glyph/q/twext/enterprise/adbapi2.py 2012-08-11 08:54:09 UTC (rev 9562)
@@ -1187,8 +1187,8 @@
Initialize a mapping of transaction IDs to transaction objects.
"""
super(ConnectionPoolConnection, self).__init__()
- self.pool = pool
- self._txns = {}
+ self.pool = pool
+ self._txns = {}
self._blocks = {}
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:54:08 UTC (rev 9561)
+++ CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py 2012-08-11 08:54:09 UTC (rev 9562)
@@ -22,3 +22,20 @@
L{twext.enterprise.dal.syntax}.
"""
+class _RecordBase(object):
+ @classmethod
+ def load(cls, txn, primaryKey):
+ return cls()
+
+
+
+def fromTable(table):
+ """
+ Create a L{type} that maps the columns from a particular table.
+
+ A L{type} created in this manner will have instances with attributes that are mapp.
+
+ @param table: The table.
+ """
+ return type(table.model.name, tuple([_RecordBase]), {})
+
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:54:08 UTC (rev 9561)
+++ CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_record.py 2012-08-11 08:54:09 UTC (rev 9562)
@@ -18,3 +18,68 @@
Test cases for L{twext.enterprise.dal.record}.
"""
+import sqlite3
+
+from twisted.internet.defer import inlineCallbacks
+
+from twisted.trial.unittest import TestCase
+
+from twext.enterprise.dal.record import fromTable
+
+from twext.enterprise.dal.test.test_parseschema import SchemaTestHelper
+from twext.enterprise.adbapi2 import ConnectionPool
+from twext.enterprise.dal.syntax import SchemaSyntax
+
+
+# from twext.enterprise.dal.syntax import
+
+
+sth = SchemaTestHelper()
+sth.id = lambda : __name__
+schemaString = """
+create table ALPHA (BETA integer primary key, GAMMA text);
+"""
+testSchema = SchemaSyntax(sth.schemaFromString(schemaString))
+
+
+
+class TestRecord(fromTable(testSchema.ALPHA)):
+ """
+ A sample test record.
+ """
+
+
+
+class TestCRUD(TestCase):
+ """
+ Tests for creation, mutation, and deletion operations.
+ """
+
+ def setUp(self):
+ sqlitename = self.mktemp()
+ def connectionFactory(label="test"):
+ return sqlite3.connect(sqlitename)
+ con = connectionFactory()
+ con.execute(schemaString)
+ con.commit()
+ self.pool = ConnectionPool(connectionFactory)
+ self.pool.startService()
+ self.addCleanup(self.pool.stopService)
+
+
+ @inlineCallbacks
+ def test_simpleCreate(self):
+ txn = self.pool.connection()
+ yield txn.execSQL("insert into ALPHA values (:1, :2)", [234, "one"])
+ yield txn.execSQL("insert into ALPHA values (:1, :2)", [456, "two"])
+ rec = yield TestRecord.load(txn, 456)
+ self.assertIsInstance(rec, TestRecord)
+ self.assertEquals(rec.beta, 456)
+ self.assertEquals(rec.gamma, "two")
+
+
+
+class TestQuery(object):
+ """
+ Tests for loading row objects from the database.
+ """
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120811/064c076e/attachment.html>
More information about the calendarserver-changes
mailing list