Skip to content

Commit

Permalink
modernize catalog.delColumn and tests a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed Apr 7, 2012
1 parent 3fda51c commit 47c13dc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
4 changes: 1 addition & 3 deletions src/Products/ZCatalog/Catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,9 @@ def delColumn(self, name):
del names[_index]

# rebuild the schema
i = 0
schema = {}
for name in names:
for i, name in enumerate(names):
schema[name] = i
i = i + 1

self.schema = schema
self.names = tuple(names)
Expand Down
39 changes: 26 additions & 13 deletions src/Products/ZCatalog/tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,35 @@ def tearDown(self):
self._catalog = None


class TestAddDelColumn(CatalogBase, unittest.TestCase):
class TestAddDelColumn(unittest.TestCase):

def testAdd(self):
self._catalog.addColumn('id')
self.assertEqual('id' in self._catalog.schema, True,
'add column failed')
def _makeOne(self):
from Products.ZCatalog.Catalog import Catalog
return Catalog()

def testAddBad(self):
from Products.ZCatalog.Catalog import CatalogError
self.assertRaises(CatalogError, self._catalog.addColumn, '_id')
def test_add(self):
catalog = self._makeOne()
catalog.addColumn('id')
self.assertEqual('id' in catalog.schema, True, 'add column failed')

def testDel(self):
self._catalog.addColumn('id')
self._catalog.delColumn('id')
self.assert_('id' not in self._catalog.schema,
'del column failed')
def test_add_bad(self):
from Products.ZCatalog.Catalog import CatalogError
catalog = self._makeOne()
self.assertRaises(CatalogError, catalog.addColumn, '_id')

def test_del(self):
catalog = self._makeOne()
catalog.addColumn('id')
catalog.delColumn('id')
self.assert_('id' not in catalog.schema, 'del column failed')

def test_del_remaining(self):
catalog = self._makeOne()
catalog.addColumn('id')
catalog.addColumn('id2')
catalog.addColumn('id3')
catalog.delColumn('id2')
self.assert_('id2' not in catalog.schema, 'del column failed')


class TestAddDelIndexes(CatalogBase, unittest.TestCase):
Expand Down

0 comments on commit 47c13dc

Please sign in to comment.