def test_empty(self): from Products.GenericSetup.tests.common import DummyExportContext from Products.PluggableAuthService.exportimport import exportPAS _setUpDefaultTraversable() self._setUpAdapters() app, pas = self._initPAS() context = DummyExportContext(pas) exportPAS(context) self.assertEqual(len(context._wrote), 3) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'PAS/.objects') self.assertEqual(content_type, 'text/comma-separated-values') self.assertEqual(text.splitlines(), _EMPTY_PAS_OBJECTS.splitlines()) filename, text, content_type = context._wrote[1] self.assertEqual(filename, 'PAS/.properties') self.assertEqual(content_type, 'text/plain') lines = [_f for _f in [x.strip() for x in text.splitlines()] if _f] lines = sorted(lines) self.assertEqual(len(lines), 3) self.assertEqual(lines[0], '[DEFAULT]') self.assertEqual(lines[1], 'login_transform =') self.assertEqual(lines[2], 'title =') filename, text, content_type = context._wrote[2] self.assertEqual(filename, 'PAS/pluginregistry.xml') self.assertEqual(content_type, 'text/xml')
def test_empty(self): from Products.GenericSetup.utils import _getDottedName from Products.GenericSetup.tests.common import DummyExportContext from Products.PluginRegistry.PluginRegistry import PluginRegistry from Products.PluggableAuthService.exportimport import exportPAS _setUpDefaultTraversable() self._setUpAdapters() app, pas = self._initPAS() context = DummyExportContext(pas) exportPAS(context) self.assertEqual(len(context._wrote), 3) filename, text, content_type = context._wrote[0] self.assertEqual(filename, "PAS/.objects") self.assertEqual(content_type, "text/comma-separated-values") self.assertEqual(text.splitlines(), _EMPTY_PAS_OBJECTS.splitlines()) filename, text, content_type = context._wrote[1] self.assertEqual(filename, "PAS/.properties") self.assertEqual(content_type, "text/plain") lines = filter(None, [x.strip() for x in text.splitlines()]) self.assertEqual(len(lines), 2) self.assertEqual(lines[0], "[DEFAULT]") self.assertEqual(lines[1], "title =") filename, text, content_type = context._wrote[2] self.assertEqual(filename, "PAS/pluginregistry.xml") self.assertEqual(content_type, "text/xml")
def test_empty(self): from Products.GenericSetup.tests.common import DummyExportContext from Products.PluggableAuthService.exportimport import exportPAS _setUpDefaultTraversable() self._setUpAdapters() app, pas = self._initPAS() context = DummyExportContext(pas) exportPAS(context) self.assertEqual(len(context._wrote), 3) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'PAS/.objects') self.assertEqual(content_type, 'text/comma-separated-values') self.assertEqual(text.splitlines(), _EMPTY_PAS_OBJECTS.splitlines()) filename, text, content_type = context._wrote[1] self.assertEqual(filename, 'PAS/.properties') self.assertEqual(content_type, 'text/plain') lines = filter(None, [x.strip() for x in text.splitlines()]) lines = sorted(lines) self.assertEqual(len(lines), 3) self.assertEqual(lines[0], '[DEFAULT]') self.assertEqual(lines[1], 'login_transform =') self.assertEqual(lines[2], 'title =') filename, text, content_type = context._wrote[2] self.assertEqual(filename, 'PAS/pluginregistry.xml') self.assertEqual(content_type, 'text/xml')
def test_with_contents(self): from Products.GenericSetup.tests.common import DummyExportContext from Products.GenericSetup.tests.faux_objects \ import TestCSVAware from Products.GenericSetup.utils import _getDottedName from Products.PluggableAuthService.exportimport import exportPAS _setUpDefaultTraversable() self._setUpAdapters() app, pas = self._initPAS() csv_aware = TestCSVAware() csv_aware._setId('csv_plugin') pas._setObject('csv_plugin', csv_aware) context = DummyExportContext(pas) exportPAS(context) self.assertEqual(len(context._wrote), 4) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'PAS/.objects') self.assertEqual(content_type, 'text/comma-separated-values') objects = [x for x in reader(StringIO(text))] self.assertEqual(len(objects), 2) object_id, type_name = objects[0] self.assertEqual(object_id, 'plugins') self.assertEqual(type_name, 'plugins') # adapter-driven object_id, type_name = objects[1] self.assertEqual(object_id, 'csv_plugin') self.assertEqual(type_name, _getDottedName(csv_aware.__class__)) filename, text, content_type = context._wrote[1] self.assertEqual(filename, 'PAS/.properties') self.assertEqual(content_type, 'text/plain') lines = [_f for _f in [x.strip() for x in text.splitlines()] if _f] lines = sorted(lines) self.assertEqual(len(lines), 3) self.assertEqual(lines[0], '[DEFAULT]') self.assertEqual(lines[1], 'login_transform =') self.assertEqual(lines[2], 'title =') filename, text, content_type = context._wrote[2] self.assertEqual(filename, 'PAS/pluginregistry.xml') self.assertEqual(content_type, 'text/xml') filename, text, content_type = context._wrote[3] self.assertEqual(filename, 'PAS/csv_plugin.csv') self.assertEqual(content_type, 'text/comma-separated-values')
def test_with_contents(self): from Products.GenericSetup.tests.common import DummyExportContext from Products.GenericSetup.tests.faux_objects \ import TestCSVAware from Products.GenericSetup.utils import _getDottedName from Products.PluggableAuthService.exportimport import exportPAS _setUpDefaultTraversable() self._setUpAdapters() app, pas = self._initPAS() csv_aware = TestCSVAware() csv_aware._setId('csv_plugin') pas._setObject('csv_plugin', csv_aware) context = DummyExportContext(pas) exportPAS(context) self.assertEqual(len(context._wrote), 4) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'PAS/.objects') self.assertEqual(content_type, 'text/comma-separated-values') objects = [x for x in reader(StringIO(text))] self.assertEqual(len(objects), 2) object_id, type_name = objects[0] self.assertEqual(object_id, 'plugins') self.assertEqual(type_name, 'plugins') # adapter-driven object_id, type_name = objects[1] self.assertEqual(object_id, 'csv_plugin') self.assertEqual(type_name, _getDottedName(csv_aware.__class__)) filename, text, content_type = context._wrote[1] self.assertEqual(filename, 'PAS/.properties') self.assertEqual(content_type, 'text/plain') lines = filter(None, [x.strip() for x in text.splitlines()]) lines = sorted(lines) self.assertEqual(len(lines), 3) self.assertEqual(lines[0], '[DEFAULT]') self.assertEqual(lines[1], 'login_transform =') self.assertEqual(lines[2], 'title =') filename, text, content_type = context._wrote[2] self.assertEqual(filename, 'PAS/pluginregistry.xml') self.assertEqual(content_type, 'text/xml') filename, text, content_type = context._wrote[3] self.assertEqual(filename, 'PAS/csv_plugin.csv') self.assertEqual(content_type, 'text/comma-separated-values')
def test_getGroupsForPrincipal_group( self ): _setUpDefaultTraversable() dpg = self._makeOne( 'ggp_group' ) principal = FauxPrincipal( 'faux' ) dpg.addGroup( 'willing', 'group/willing' ) dpg.willing._setProperty( 'willing', type='boolean', value=0 ) groups = dpg.getGroupsForPrincipal( principal, {} ) self.assertEqual( len( groups ), 0 ) dpg.willing._updateProperty( 'willing', 1 ) groups = dpg.getGroupsForPrincipal( principal, {} ) self.assertEqual( len( groups ), 1 ) self.failUnless( 'willing' in groups )
def test_getGroupsForPrincipal_group(self): _setUpDefaultTraversable() dpg = self._makeOne('ggp_group') principal = FauxPrincipal('faux') dpg.addGroup('willing', 'group/willing') dpg.willing._setProperty('willing', type='boolean', value=0) groups = dpg.getGroupsForPrincipal(principal, {}) self.assertEqual(len(groups), 0) dpg.willing._updateProperty('willing', 1) groups = dpg.getGroupsForPrincipal(principal, {}) self.assertEqual(len(groups), 1) self.assertTrue('willing' in groups)
def test_getGroupsForPrincipal_request( self ): _setUpDefaultTraversable() dpg = self._makeOne( 'ggp_request' ) principal = FauxPrincipal( 'faux' ) dpg.addGroup( 'local', 'request/is_local | nothing' ) groups = dpg.getGroupsForPrincipal( principal, {} ) self.assertEqual( len( groups ), 0 ) groups = dpg.getGroupsForPrincipal( principal, { 'is_local' : 0 } ) self.assertEqual( len( groups ), 0 ) groups = dpg.getGroupsForPrincipal( principal, { 'is_local' : 1 } ) self.assertEqual( len( groups ), 1 ) self.failUnless( 'local' in groups )
def test_getGroupsForPrincipal_request(self): _setUpDefaultTraversable() dpg = self._makeOne('ggp_request') principal = FauxPrincipal('faux') dpg.addGroup('local', 'request/is_local | nothing') groups = dpg.getGroupsForPrincipal(principal, {}) self.assertEqual(len(groups), 0) groups = dpg.getGroupsForPrincipal(principal, {'is_local': 0}) self.assertEqual(len(groups), 0) groups = dpg.getGroupsForPrincipal(principal, {'is_local': 1}) self.assertEqual(len(groups), 1) self.assertTrue('local' in groups)