Commits

angri  committed 9eee035

[tests] more tests for custom columns and column options

  • Participants
  • Parent commits fea7ba6

Comments (0)

Files changed (2)

File sqlamp/__init__.py

         if needed, create the column object if needed and check the
         existing `Column` object for sanity.
         """
-        assert field
+        assert field is not None
         if not isinstance(field, basestring):
             assert isinstance(field, sqlalchemy.Column)
             assert not attach or field.table is table

File tests/functional-tests.py

             parent = sqlalchemy.orm.relation("Node", remote_side=[id])
             name = sqlalchemy.Column(sqlalchemy.String(100))
 
+        self.assertEqual(Node.MP._mp_opts.pathlen, 120)
+        self.assertEqual(Node.MP._mp_opts.steplen, 5)
+        self.assertEqual(Node.MP._mp_opts.path_field, Node.__table__.c.path)
+        self.assertEqual(Node.MP._mp_opts.depth_field.name, 'MP_depth')
+
         if Node.__table__.exists():
             Node.__table__.drop()
         Node.__table__.create()
         mpm = sqlamp.MPManager(tbl, steplen=1, pathlen=512)
         self.assertEqual(tbl.c.mp_path.type.impl.length, 512)
 
+    def test_custom_column_and_same_column_options(self):
+        tbl = sqlalchemy.Table('tbl5', metadata,
+            sqlalchemy.Column('id', sqlalchemy.Integer, primary_key=True),
+            sqlalchemy.Column('pid', sqlalchemy.ForeignKey('tbl5.id')),
+            sqlalchemy.Column('path', sqlamp.PathField(length=40),
+                              nullable=False)
+        )
+        mpm = sqlamp.MPManager(tbl, pathlen=40)
+        self.assertEqual(tbl.c.mp_path.type.impl.length, 40)
+
+    def test_custom_column_and_different_column_options(self):
+        tbl = sqlalchemy.Table('tbl6', metadata,
+            sqlalchemy.Column('id', sqlalchemy.Integer, primary_key=True),
+            sqlalchemy.Column('pid', sqlalchemy.ForeignKey('tbl6.id')),
+        )
+        path_field = sqlalchemy.Column('path', sqlamp.PathField(length=50),
+                                       nullable=False)
+        self.assertRaises(AssertionError, sqlamp.MPManager, tbl,
+                          pathlen=60, path_field=path_field)
+
     def test_table_inheritance(self):
         tbl_abstract = sqlalchemy.Table('tbl_abstract', metadata,
             sqlalchemy.Column('id', sqlalchemy.Integer, primary_key=True),
 class MoveNodesLimitsTestCase(_BaseFunctionalTestCase):
     def setUp(self):
         super(MoveNodesLimitsTestCase, self).setUp()
-        self.tbl = sqlalchemy.Table('tbl3', metadata,
+        self.tbl = sqlalchemy.Table('tbl7', metadata,
             sqlalchemy.Column('id', sqlalchemy.Integer, primary_key=True),
-            sqlalchemy.Column('pid', sqlalchemy.ForeignKey('tbl3.id'))
+            sqlalchemy.Column('pid', sqlalchemy.ForeignKey('tbl7.id'))
         )
         class Node(Cls):
             mp = sqlamp.MPManager(self.tbl, steplen=1)