Back to index

plone3  3.1.7
testKeyring.py
Go to the documentation of this file.
00001 import types
00002 from unittest import makeSuite
00003 from unittest import TestCase
00004 from unittest import TestSuite
00005 from zope.interface.verify import verifyClass
00006 from plone.keyring.interfaces import IKeyring
00007 from plone.keyring.keyring import Keyring
00008 
00009 class KeyringTests(TestCase):
00010     def testInterface(self):
00011         verifyClass(IKeyring, Keyring)
00012 
00013     def testConstructionDefaultSize(self):
00014         ring=Keyring()
00015         self.assertEqual(len(ring), 5)
00016 
00017     def testConstructionSize(self):
00018         ring=Keyring(3)
00019         self.assertEqual(len(ring), 3)
00020 
00021     def testKeyringStartsEmpty(self):
00022         ring=Keyring()
00023         self.assertEqual(set(list(ring)), set([None]))
00024 
00025     def testIterate(self):
00026         ring=Keyring()
00027         ring.data=[0, 1, 2, 3, 4]
00028         iterator=ring.__iter__()
00029         self.failUnless(isinstance(iterator, types.GeneratorType))
00030         self.assertEqual(list(iterator), [0, 1, 2, 3, 4])
00031 
00032     def testClear(self):
00033         ring=Keyring()
00034         ring.data=[0, 1, 2]
00035         ring.clear()
00036         self.assertEqual(ring.data, [ None, None, None ])
00037 
00038     def testRotate(self):
00039         ring=Keyring()
00040         ring.rotate()
00041         self.failIf(ring.current is None)
00042         self.assertEqual(ring.data[1:], [ None, None, None, None])
00043 
00044     def testRotateTwice(self):
00045         ring=Keyring()
00046         ring.rotate()
00047         ring.rotate()
00048         self.failUnless(ring.data[0] is not None)
00049         self.failUnless(ring.data[1] is not None)
00050         self.assertEqual(ring.data[2:], [ None, None, None])
00051 
00052     def testCurrent(self):
00053         ring=Keyring()
00054         marker=[]
00055         ring.data=[marker, 1, 2, 3]
00056         self.failUnless(ring.current is marker)
00057 
00058 
00059 def test_suite():
00060     suite=TestSuite()
00061     suite.addTest(makeSuite(KeyringTests))
00062     return suite
00063