[Zope-CVS] CVS: Products/Ape/lib/apelib/config/tests - __init__.py:1.1.2.1 test_minitables.py:1.1.2.1
Shane Hathaway
shane@zope.com
Mon, 7 Jul 2003 18:59:24 -0400
Update of /cvs-repository/Products/Ape/lib/apelib/config/tests
In directory cvs.zope.org:/tmp/cvs-serv2793/config/tests
Added Files:
Tag: ape-newconf-branch
__init__.py test_minitables.py
Log Message:
Implemented XML-based configuration. The filesystem tests pass.
Used an experimental approach for mixing configuration from multiple sources.
Take a look at zope2/apeconf.xml.
=== Added File Products/Ape/lib/apelib/config/tests/__init__.py ===
##############################################################################
#
# 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: __init__.py,v 1.1.2.1 2003/07/07 22:59:18 shane Exp $
"""
=== Added File Products/Ape/lib/apelib/config/tests/test_minitables.py ===
##############################################################################
#
# 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: test_minitables.py,v 1.1.2.1 2003/07/07 22:59:18 shane Exp $
"""
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()