[Zope-CVS] CVS: Products/Ape/lib/apelib/config/tests - __init__.py:1.2 test_minitables.py:1.2

Shane Hathaway shane@zope.com
Tue, 15 Jul 2003 14:13:43 -0400


Update of /cvs-repository/Products/Ape/lib/apelib/config/tests
In directory cvs.zope.org:/tmp/cvs-serv1888

Added Files:
	__init__.py test_minitables.py 
Log Message:
Merged missing tests

=== Products/Ape/lib/apelib/config/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null	Tue Jul 15 14:13:42 2003
+++ Products/Ape/lib/apelib/config/tests/__init__.py	Tue Jul 15 14:13:35 2003
@@ -0,0 +1,17 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Ape configuration test package.
+
+$Id$
+"""


=== Products/Ape/lib/apelib/config/tests/test_minitables.py 1.1 => 1.2 ===
--- /dev/null	Tue Jul 15 14:13:42 2003
+++ Products/Ape/lib/apelib/config/tests/test_minitables.py	Tue Jul 15 14:13:36 2003
@@ -0,0 +1,171 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Minitable tests.
+
+$Id$
+"""
+
+import unittest
+
+from apelib.config import minitables
+
+
+TEST_DATA = [
+    {'name':    'Jose',
+     'sex':     'm',
+     'address': '101 Example St.',
+     'phone':   '123-4567',
+     },
+    {'name':    'Maria',
+     'sex':     'f',
+     'address': '102 Example St.',
+     },
+    {'name':    'Carlos',
+     'sex':     'm',
+     'phone':   '987-6543',
+     },
+    {'name':    'Tiago',
+     'sex':     'm',
+     'phone':   '123-4567',
+     },
+    {'name':    'Ana',
+     'sex':     'f',
+     'phone':   '123-4567',
+     },
+    ]
+
+
+class MiniTableTests(unittest.TestCase):
+
+    def setUp(self):
+        schema = minitables.TableSchema()
+        schema.addColumn('name', primary=1, indexed=1)
+        schema.addColumn('sex', indexed=1)
+        schema.addColumn('address')
+        schema.addColumn('phone', indexed=1)
+        self.table = table = minitables.Table(schema)
+        for data in TEST_DATA:
+            table.insert(data)
+
+    def testSelectByName(self):
+        # Searches by primary key
+        records = self.table.select({'name': 'Jose'})
+        self.assertEqual(len(records), 1)
+        self.assertEqual(records[0]['address'], '101 Example St.')
+
+    def testSelectByUnknownName(self):
+        # Searches by primary key
+        records = self.table.select({'name': 'Joao'})
+        self.assertEqual(len(records), 0)
+
+    def testSelectByPhone(self):
+        # Searches by index
+        records = self.table.select({'phone': '987-6543'})
+        self.assertEqual(len(records), 1)
+        self.assertEqual(records[0]['name'], 'Carlos')
+
+    def testSelectByAddress(self):
+        # Searches one-by-one
+        records = self.table.select({'address': '102 Example St.'})
+        self.assertEqual(len(records), 1)
+        self.assertEqual(records[0]['name'], 'Maria')
+
+    def testSelectMales(self):
+        records = self.table.select({'sex': 'm'})
+        self.assertEqual(len(records), 3)
+
+    def testSelectFemales(self):
+        records = self.table.select({'sex': 'f'})
+        self.assertEqual(len(records), 2)
+
+    def testSelectByNameAndSex(self):
+        records = self.table.select({'name': 'Jose', 'sex': 'm'})
+        self.assertEqual(len(records), 1)
+
+    def testSelectByNameAndIncorrectSex(self):
+        records = self.table.select({'name': 'Jose', 'sex': 'f'})
+        self.assertEqual(len(records), 0)
+
+    def testSelectBySexAndPhone(self):
+        # Intersects two indexes
+        records = self.table.select({'phone': '123-4567', 'sex': 'm'})
+        self.assertEqual(len(records), 2)
+
+    def testSelectAll(self):
+        records = self.table.select({})
+        self.assertEqual(len(records), 5)
+
+    def testInsertMinimal(self):
+        self.table.insert({'name': 'Edson'})
+
+    def testInsertDuplicate(self):
+        self.assertRaises(minitables.DuplicateError,
+                          self.table.insert, {'name':'Carlos'})
+
+    def testInsertWithoutPrimaryKey(self):
+        self.assertRaises(ValueError, self.table.insert, {})
+
+    def testUpdateNewAddress(self):
+        # Test adding a value in a non-indexed column
+        self.table.update({'name': 'Carlos'}, {'address': '99 Sohcahtoa Ct.'})
+        records = self.table.select({'address': '99 Sohcahtoa Ct.'})
+        self.assertEqual(len(records), 1)
+        self.assertEqual(records[0]['name'], 'Carlos')
+
+    def testUpdateChangeAddress(self):
+        # Test changing a value in a non-indexed column
+        self.table.update({'name': 'Jose'}, {'address': '99 Sohcahtoa Ct.'})
+        records = self.table.select({'address': '99 Sohcahtoa Ct.'})
+        self.assertEqual(len(records), 1)
+        self.assertEqual(records[0]['name'], 'Jose')
+
+    def testUpdateFemaleAddresses(self):
+        # Test changing and adding simultaneously in a non-indexed column
+        self.table.update({'sex': 'f'}, {'address': '99 Sohcahtoa Ct.'})
+        records = self.table.select({'address': '99 Sohcahtoa Ct.'})
+        self.assertEqual(len(records), 2)
+
+
+    def testUpdateChangePhone(self):
+        # Test changing a value in an indexed column
+        records = self.table.select({'phone': '123-4567'})
+        self.assertEqual(len(records), 3)  # Precondition
+
+        self.table.update({'name': 'Jose'}, {'phone': '111-5555'})
+        records = self.table.select({'phone': '123-4567'})
+        self.assertEqual(len(records), 2)
+        records = self.table.select({'phone': '111-5555'})
+        self.assertEqual(len(records), 1)
+        self.assertEqual(records[0]['name'], 'Jose')
+
+
+    def testUpdateChangeName(self):
+        # Test changing a value in a primary key column
+        records = self.table.select({'name': 'Jose'})
+        self.assertEqual(len(records), 1)  # Precondition
+
+        self.table.update({'name': 'Jose'}, {'name': 'Marco'})
+        records = self.table.select({'name': 'Jose'})
+        self.assertEqual(len(records), 0)
+        records = self.table.select({'name': 'Marco'})
+        self.assertEqual(len(records), 1)
+
+
+    def testUpdateNameConflict(self):
+        self.assertRaises(minitables.DuplicateError, self.table.update,
+                          {'name':'Jose'}, {'name': 'Carlos'})
+
+if __name__ == '__main__':
+    unittest.main()
+