================================
Principal Sample Data Generation
================================

This generator creates principals from a data source.

  >>> from z3c.sampledata.generator.principals import SamplePrincipals
  >>> generator = SamplePrincipals()

For the creation of principals we need a site configured with a principal
authentican. To create our site we use the site generator.

  >>> from pprint import pprint
  >>> from zope import component
  >>> from z3c.sampledata.interfaces import ISampleDataPlugin
  >>> from z3c.sampledata import Manager
  >>> from z3c.sampledata.generator.site import SampleSite
  >>> component.provideUtility(SampleSite(),
  ...                          ISampleDataPlugin,
  ...                          'z3c.sampledata.site')
  >>> from z3c.sampledata.generator.pau import SamplePau
  >>> component.provideUtility(SamplePau(),
  ...                          ISampleDataPlugin,
  ...                          'z3c.sampledata.pau')
  >>> manager = Manager('manager', '')
  >>> manager.add('z3c.sampledata.site')
  >>> manager.add('z3c.sampledata.pau', contextFrom='z3c.sampledata.site')
  >>> from zope.app.folder.folder import Folder
  >>> infos = manager.generate(context=root,
  ...                          param={'z3c.sampledata.site':
  ...                                      {'sitename':'test'}},
  ...                          seed=None)
  >>> root['test']
  <zope.app.folder.folder.Folder object at ...>

  >>> principalDataSource = [['batlogg','Jodok Batlogg','bJB'],
  ...                        ['jukart','Juergen Kartnaller','jJK'],
  ...                        ['dobee','Bernd Dorn','dBD'],
  ...                        ['srichter','Stephan Richter','sSR'],
  ...                        ['byzo','Michael Breidenbruecker','bMB'],
  ...                        ['oli','Oliver Ruhm','oOR']]

Now that everything is set up we can generate the principals for the root
object.

  >>> testsite = root['test']
  >>> pau = testsite.getSiteManager()['default']['pau']

We can define a maximum number of users.

  >>> p = generator.generate(testsite,
  ...                    param={'minPrincipals':-1,
  ...                           'maxPrincipals': 2,
  ...                           'pauLocation':'default/pau',
  ...                           'passwordManager':'SHA1'},
  ...                    dataSource=principalDataSource
  ...                   )
  >>> p == pau
  True
  >>> len(pau['members'])
  2

With both parameter set to -1 all members from the datasource are generated.

  >>> p = generator.generate(testsite,
  ...                    param={'minPrincipals':-1,
  ...                           'maxPrincipals':-1,
  ...                           'pauLocation':'default/pau',
  ...                           'passwordManager':'SHA1'},
  ...                    dataSource=principalDataSource
  ...                   )
  >>> p == pau
  True
  >>> pprint(sorted([pau['members'][user[0]].title for user in
  ...                                                  principalDataSource]))
  [u'Bernd Dorn',
   u'Jodok Batlogg',
   u'Juergen Kartnaller',
   u'Michael Breidenbruecker',
   u'Oliver Ruhm',
   u'Stephan Richter']

We can define a minimum number of users to create.

  >>> numMembers = len(pau['members'])
  >>> p = generator.generate(testsite,
  ...                    param={'minPrincipals': 10,
  ...                           'maxPrincipals':-1,
  ...                           'pauLocation':'default/pau',
  ...                           'passwordManager':'SHA1'},
  ...                   )
  >>> p == pau
  True
  >>> len(pau['members']) == numMembers+10
  True
  >>> pprint(sorted([user.title for user in pau['members'].values()]))
  [u'Bernd Dorn',
   u'Jodok Batlogg',
   u'Juergen Kartnaller',
   u'Michael Breidenbruecker',
   u'Oliver Ruhm',
   u'Stephan Richter',
   u'name0',
   u'name1',
   u'name2',
   u'name3',
   u'name4',
   u'name5',
   u'name6',
   u'name7',
   u'name8',
   u'name9']

