]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
unit tests to test column/pk/fk exports on relational objects
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 8 Jan 2006 01:30:03 +0000 (01:30 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 8 Jan 2006 01:30:03 +0000 (01:30 +0000)
test/selectable.py [new file with mode: 0755]

diff --git a/test/selectable.py b/test/selectable.py
new file mode 100755 (executable)
index 0000000..37b1f28
--- /dev/null
@@ -0,0 +1,91 @@
+"""tests that various From objects properly export their columns, as well as useable primary keys\r
+and foreign keys.  Full relational algebra depends on every selectable unit behaving\r
+nicely with others.."""\r
+\r
+import testbase\r
+import unittest, sys, datetime\r
+\r
+\r
+db = testbase.db\r
+\r
+from sqlalchemy import *\r
+\r
+\r
+table = Table('table1', db, \r
+    Column('col1', Integer, primary_key=True),\r
+    Column('col2', String(20)),\r
+    Column('col3', Integer),\r
+    redefine=True\r
+)\r
+\r
+table2 = Table('table2', db,\r
+    Column('col1', Integer, primary_key=True),\r
+    Column('col2', Integer, ForeignKey('table1.col1')),\r
+    Column('col3', String(20)),\r
+    redefine=True\r
+)\r
+\r
+class SelectableTest(testbase.AssertMixin):\r
+    def testtablealias(self):\r
+        a = table.alias('a')\r
+        \r
+        j = join(a, table2)\r
+        \r
+        criterion = a.c.col1 == table2.c.col2\r
+        print\r
+        print str(j)\r
+        self.assert_(criterion.compare(j.onclause))\r
+\r
+    def testjoin(self):\r
+        a = join(table, table2)\r
+        print str(a.select(use_labels=True))\r
+        # TODO - figure out what we're trying to do here\r
+        return\r
+        b = table2.alias('b')\r
+        j = join(a, b)\r
+        print str(j)\r
+        return\r
+        criterion = a.c.col1 == b.c.col2\r
+        print\r
+        print str(j)\r
+        self.assert_(criterion.compare(j.onclause))\r
+\r
+    def testselectalias(self):\r
+        a = table.select().alias('a')\r
+        print str(a.select())\r
+        j = join(a, table2)\r
+        \r
+        criterion = a.c.col1 == table2.c.col2\r
+        print\r
+        print str(j)\r
+        self.assert_(criterion.compare(j.onclause))\r
+\r
+    def testselectlabels(self):\r
+        a = table.select(use_labels=True)\r
+        print str(a.select())\r
+        j = join(a, table2)\r
+        \r
+        criterion = a.c.table1_col1 == table2.c.col2\r
+        print\r
+        print str(j)\r
+        self.assert_(criterion.compare(j.onclause))\r
+\r
+    def testcolumnlabels(self):\r
+        a = select([table.c.col1.label('acol1'), table.c.col2.label('acol2'), table.c.col3.label('acol3')])\r
+        print str(a)\r
+        print [c for c in a.columns]\r
+        j = join(a, table2)\r
+        \r
+    def testselectaliaslabels(self):\r
+        a = table2.select(use_labels=True).alias('a')\r
+        print str(a.select())\r
+        j = join(a, table)\r
+        \r
+        criterion =  table.c.col1 == a.c.table2_col2\r
+        print str(criterion)\r
+        print str(j.onclause)\r
+        self.assert_(criterion.compare(j.onclause))\r
+        \r
+if __name__ == "__main__":\r
+    testbase.main()\r
+    
\ No newline at end of file