Ñò ÏyIc @ sÎ d Z d d k l Z l Z l Z l Z l Z d d d d g Z d e f d „ ƒ YZ d e f d „ ƒ YZ d e f d „ ƒ YZ d e e f d „ ƒ YZ d e f d „ ƒ YZ d e e f d „ ƒ YZ d S( s" Utilities to test source adapters.iÿÿÿÿ( t SourceErrort ExistingSectionErrort NonExistingSectionErrort ItemPresentErrort ItemNotPresentErrort GroupsAdapterTestert PermissionsAdapterTestert ReadOnlyGroupsAdapterTestert ReadOnlyPermissionsAdapterTestert _ReadOnlyBaseAdapterTesterc B sq e Z d Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z RS( s% Base test case for read-only adaptersc C s1 t ƒ } x! | i i ƒ D] } | | O} q W| S( N( t sett all_sectionst values( t selft all_itemst items( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt _get_all_items s c C sE t g } | i i ƒ D]$ \ } } | | j o | | q q ~ ƒ S( N( R R R ( R t itemt _[1]t nt s( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt _get_item_sections% s c C s | i | i i ƒ | i ƒ d S( N( t assertEqualt adaptert _get_all_sectionsR ( R ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt test_retrieving_all_sections( s c C s@ x9 | i i ƒ D]( \ } } | i | i i | ƒ | ƒ q Wd S( N( R R R R t _get_section_items( R t section_nameR ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt test_getting_section_items+ s c C s? x8 | i i ƒ D]' } | i i | ƒ p t d | ‚ q Wd S( Ns Section "%s" does NOT exist( R t keysR t _section_existst AssertionError( R R ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt test_checking_existing_section0 s c C s, d } | i i | ƒ p t d | ‚ d S( Nu i_dont_exists Section "%s" DOES exist( R R R ( R R ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt" test_checking_non_existing_section5 s c C sk xd | i i ƒ D]S \ } } xD | i i | ƒ D]0 } | i i | | ƒ p t d | | f ‚ q/ Wq Wd S( Ns* Item "%s" must be included in section "%s"( R R R R t _item_is_includedR ( R R R R ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt test_checking_item_inclusion: s c C s^ | i i ƒ } xH | i i ƒ D]7 \ } } | i i | | ƒ p t d t | f ‚ q Wd S( Ns+ Item "%s" must not included in section "%s"( t new_itemst popR R R R" R R ( R t excluded_itemR R ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt% test_checking_excluded_item_inclusionA s c C s? x8 | i i ƒ D]' } | i i | ƒ p t d | ‚ q Wd S( Ns Section "%s" must exist( R R R R R ( R R ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt test_checking_section_existenceI s c C s, d } | i i | ƒ p t d | ‚ d S( Nu designerss Section "%s" must not exist( R R R ( R t invalid_section( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt, test_checking_non_existing_section_existenceN s c C s! t | i d ƒ p t d ‚ d S( Nt is_writables^ The adapter doesn't have the 'is_writable' attribute; please call its parent's constructor too( t hasattrR R ( R ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt test_sets_if_it_is_writableS s ( t __name__t __module__t __doc__R R R R R R! R# R' R( R* R- ( ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyR s t _BaseAdapterTesterc B s2 e Z d Z d „ Z d „ Z d „ Z d „ Z RS( s( Base test case for read & write adaptersc C sw xp | i i ƒ D]_ \ } } | i i | | i ƒ | | i B} | i i | ƒ | j p t d | | i f ‚ q Wd S( Ns "%s" does not include %s( R R R t _include_itemsR$ R R ( R R R t final_items( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt! test_adding_many_items_to_section\ s c C sD d } | i i | ƒ | | i i ƒ i ƒ j p t d | ‚ d S( Nu cool-sections Section "%s" could not be added( R t _create_sectionR R R ( R t section( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt test_creating_sectionc s c C s| | i i ƒ d } d } | i i | | ƒ | | i i ƒ i ƒ j o | | i i ƒ i ƒ j p t d | | f ‚ d S( Ni u cool-sections$ Section "%s" was not renamed to "%s"( R R R t _edit_sectionR R ( R t old_sectiont new_section( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt test_editing_sectioni s c C sQ | i i ƒ d } | i i | ƒ | | i i ƒ i ƒ j p t d | ‚ d S( Ni s Section "%s" was not deleted( R R R t _delete_sectionR R ( R R6 ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt test_deleting_sectionr s ( R. R/ R0 R4 R7 R; R= ( ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyR1 Y s c B s> e Z d Z e d ƒ Z d „ Z d „ Z d „ Z d „ Z RS( s> Test case for read-only groups source adapters. The groups source used for the tests must only contain the following groups (aka "sections") and their relevant users (aka "items"; if any): * admins * rms * developers * rms * linus * trolls * sballmer * python * php .. attribute:: adapter An instance of the :term:`group adapter` to be tested. For example, a test case for the mock group adapter ``FakeReadOnlyGroupSourceAdapter`` may look like this:: from repoze.what.adapters.testutil import ReadOnlyGroupsAdapterTester class TestReadOnlyGroupsAdapterTester(ReadOnlyGroupsAdapterTester, unittest.TestCase): def setUp(self): super(TestReadOnlyGroupsAdapterTester, self).setUp() self.adapter = FakeReadOnlyGroupSourceAdapter() .. note:: :class:`GroupsAdapterTester` extends this test case to check write operations. u guidou rasmusc C sH h t d ƒ d 6t d ƒ d 6t d ƒ d 6t ƒ d 6t ƒ d 6| _ d S( Nu rmsu adminsu linusu developersu sballmeru trollsu pythonu php( u rms( u rmsu linus( u sballmer( R R ( R ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt setUp¢ s c C s h | d 6S( sù Return a fake :mod:`repoze.what` ``credentials`` dictionary based on the ``userid``. Overwrite this method if its generated ``credentials`` dictionaries are not suitable for your adapter. s repoze.what.userid( ( R t userid( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt _make_credentials« s c C sO xH | i ƒ D]: } | i | ƒ } | i | i i | ƒ | i | ƒ ƒ q Wd S( N( R R@ R R t _find_sectionsR ( R R? t credentials( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt) test_finding_groups_of_authenticated_user¶ s c C s2 | i d ƒ } | i | i i | ƒ t ƒ ƒ d S( Nu gustavo( R@ R R RA R ( R RB ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt( test_finding_groups_of_non_existing_user¼ s ( u guidou rasmus( R. R/ R0 R R$ R> R@ RC RD ( ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyR y s % c B s e Z d Z d „ Z RS( s„ Test case for groups source adapters. This test case extends :class:`ReadOnlyGroupsAdapterTester` to test write operations in read & write adapters and it should be set up the same way as its parent. For example, a test case for the mock group adapter ``FakeGroupSourceAdapter`` may look like this:: from repoze.what.adapters.testutil import GroupsAdapterTester class TestGroupsAdapterTester(GroupsAdapterTester, unittest.TestCase): def setUp(self): super(TestGroupsAdapterTester, self).setUp() self.adapter = FakeGroupSourceAdapter() c C sS d } d } | i i | | ƒ | i i | ƒ t ƒ j p t d | | f ‚ d S( Nu developersu rmsu linuss "%s" still includes %s( u rmsu linus( R t _exclude_itemsR R R ( R t groupt users( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt# test_removing_many_users_from_groupÓ s ( R. R/ R0 RH ( ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyR Á s c B s5 e Z d Z e d ƒ Z d „ Z d „ Z d „ Z RS( sŠ Test case for read-only permissions source adapters. The permissions source used for the tests must only contain the following permissions (aka "sections") and their relevant groups (aka "items"; if any): * see-site * trolls * edit-site * admins * developers * commit * developers .. attribute:: adapter An instance of the :term:`permission adapter` to be tested. For example, a test case for the mock permission adapter defined above (``FakeReadOnlyPermissionSourceAdapter``) may look like this:: from repoze.what.adapters.testutil import ReadOnlyPermissionsAdapterTester class TestReadOnlyPermissionsAdapterTester(ReadOnlyPermissionsAdapterTester, unittest.TestCase): def setUp(self): super(TestReadOnlyPermissionsAdapterTester, self).setUp() self.adapter = FakeReadOnlyPermissionSourceAdapter() .. note:: :class:`PermissionsAdapterTester` extends this test case to check write operations. u pythonu phpc C s4 h t d ƒ d 6t d ƒ d 6t d ƒ d 6| _ d S( Nu trollsu see-siteu adminsu developersu edit-siteu commit( u trolls( u adminsu developers( u developers( R R ( R ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyR> s c C s@ x9 | i ƒ D]+ } | i | i i | ƒ | i | ƒ ƒ q Wd S( N( R R R RA R ( R RF ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt test_finding_permissions s c C s# | i | i i d ƒ t ƒ ƒ d S( Nu designers( R R RA R ( R ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt. test_finding_permissions_of_non_existing_group s ( u pythonu php( R. R/ R0 R R$ R> RI RJ ( ( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyR Û s $ c B s e Z d Z d „ Z RS( sa Test case for permissions source adapters. This test case extends :class:`ReadOnlyPermissionsAdapterTester` to test write operations in read & write adapters and it should be set up the same way as its parent. For example, a test case for the mock group adapter ``FakePermissionSourceAdapter`` may look like this: For example, a test case for the mock permission adapter defined above (``FakePermissionSourceAdapter``) may look like this:: from repoze.what.adapters.testutil import PermissionsAdapterTester class TestPermissionsAdapterTester(PermissionsAdapterTester, unittest.TestCase): def setUp(self): super(TestPermissionsAdapterTester, self).setUp() self.adapter = FakePermissionSourceAdapter() c C sS d } d } | i i | | ƒ | i i | ƒ t ƒ j p t d | | f ‚ d S( Nu edit-siteu adminsu developerss "%s" still includes %s( u adminsu developers( R RE R R R ( R t permissiont groups( ( sA /usr/lib/python2.6/site-packages/repoze/what/adapters/testutil.pyt&