Plomino importer : test formulas and script import
==================================================

Check a database
-----------------

    >>> from Products.Five.testbrowser import Browser
    >>> browser = Browser()
    
Import os to generate file from path

    >>> import os.path
    >>> dir, _f = os.path.split(os.path.abspath(__file__))
    
    >>> self.setRoles(['Manager'])
    >>> id=self.folder.invokeFactory('PlominoDatabase', id='mydb')
    >>> db=self.folder.mydb
    >>> db.at_post_create_script()
    
    >>> from plomino.dominoimport.interfaces import IDominoImporter
    >>> i=IDominoImporter(db)
    >>> i.__class__.__name__
    'DominoImporter'
    
    >>> i.context.id
    'mydb'
        
    
Import a DXL File
-----------------

DXL file imported is the database design one: the file is parsed in a xml object

    >>> dxlFile = os.path.join(dir, "DXLFiles", "test_formulas.xml")
    >>> dxlDoc = i.processImportDXL(dxlFile)
    {'forms': [2, 0], 'docs': [4, 0], 'agents': [1, 0], 'resources': [0, 0], 'views': [3, 0]}

Forms
-----

    >>> allForms = db.getForms()
    >>> if allForms[0].getFormName() != 'web':
    ...     allForms.reverse()
    >>> form = db.getForm('infos')

Fields

    >>> for form in allForms:
    ...     form.getFormName()
    'web'
    'infos'

    >>> allFields = form.getFields()
    >>> allFields.reverse()
    >>> allFields
    [<PlominoField at /plone/Members/test_user_1_/mydb/infos/biography>, <PlominoField at /plone/Members/test_user_1_/mydb/infos/age>, <PlominoField at /plone/Members/test_user_1_/mydb/infos/birthdate>, <PlominoField at /plone/Members/test_user_1_/mydb/infos/name>]
    
    >>> for field in allFields:
    ...     field.getId()
    ...     field.getFormula()
    ...     field.getValidationFormula()
    'biography'
    ''
    ''
    'age'
    '# @Year(12/12/2006)'
    ''
    'birthdate'
    ''
    ''
    'name'
    ''
    ''
    
form.getFormLayout()
'<p>nom: <span class="plominoFieldClass">name</span></p><p>date de naissance: <span class="plominoFieldClass">birthdate</span></p><p>\xc3\xa2ge: <span class="plominoFieldClass">age</span></p><p>biographie: <span class="plominoFieldClass">biography</span></p><p></p>'

Views
    
    >>> allViews = db.getViews()
    >>> allViews.sort()
    >>> allViews
    [<PlominoView at /plone/Members/test_user_1_/mydb/All>, <PlominoView at /plone/Members/test_user_1_/mydb/biographie>, <PlominoView at /plone/Members/test_user_1_/mydb/Infos_Mail>]

Check Columns
-------------

    >>> for view in allViews:
    ...     view.getViewName()
    ...     view.getSelectionFormula()
    ...     view.getFormFormula()
    ...     allColumns = view.getColumns()
    ...     print "Columns: "
    ...     for column in allColumns:
    ...         column.getId()
    ...         column.getFormula()
    ...     print '----'
    'All'
    'True'
    ''
    Columns: 
    'name'
    'plominoDocument.name'
    ----
    'biographie'
    '# (age > 5)'
    ''
    Columns: 
    'name'
    'plominoDocument.name'
    'biography'
    'plominoDocument.biography'
    'age'
    'plominoDocument.age'
    ----
    'Infos_Mail'
    'True'
    '# web'
    Columns: 
    'name'
    'plominoDocument.name'
    'site'
    'plominoDocument.site'
    'email'
    'plominoDocument.email'
    ----
    
Docs

    >>> allDocs = db.getAllDocuments()
    >>> len(allDocs)
    4
    
    Delete database
    >>> self.folder.manage_delObjects(["mydb"])
    
Import agents
==============

    >>> id=self.folder.invokeFactory('PlominoDatabase', id='mydb')
    >>> db=self.folder.mydb
    >>> db.at_post_create_script()
    >>> i=IDominoImporter(db)
    
    
DXL file imported is the database design one: the file is parsed in a xml object

    >>> dxlFile = os.path.join(dir, "DXLFiles", "test_agents.xml")
    >>> dxlDoc = i.processImportDXL(dxlFile)
    {'forms': [1, 0], 'docs': [1, 0], 'agents': [3, 0], 'resources': [0, 0], 'views': [1, 0]}
    
Check agent
-----------

    >>> allAgents = db.getAgents()
    >>> for agent in allAgents:
    ...     agent.getId()
    ...     agent.getContent()
    ...     agent.getScheduled()
    ...     agent.getAgentUser()
    ...     agent.getCron()
    'exporter'
    '\n#------------ \n# code from lotus domino\n# Event: options\n# code type: lotusscript\n#------------ \n# Option Public\n# \n#------------ \n# code from lotus domino\n# Event: initialize\n# code type: lotusscript\n#------------ \n# Sub Initialize \n# \tDim session As New NotesSession \n# \tDim db As NotesDatabase \n# \tSet db = session.CurrentDatabase \n# \t\n# REM Open xml file named after current database \n# \tDim stream As NotesStream \n# \tSet stream = session.CreateStream \n# \tfilename$ = "e:\\tmp\\" & Left(db.FileName, Len(db.FileName) - 3) & "xml" \n# \tIf Not stream.Open(filename$) Then \n# \t\tMessagebox "Cannot open " & filename$,, "Error" \n# \t\tExit Sub \n# \tEnd If \n# \tCall stream.Truncate \n# \t\n# REM Export current database as DXL \n# \tDim exporter As NotesDXLExporter \n# \tSet exporter = session.CreateDXLExporter \n# \t\n#    REM Create note collection of actions \n# \tDim nc As NotesNoteCollection \n# \tSet nc = db.CreateNoteCollection(False) \n# \t\'Call nc.SelectAllFormatElements(True)\n# \tCall nc.SelectAllNotes(True)\n# \tnc.SelectActions = False \n# \tCall nc.BuildCollection \n# \t\n# REM Set up importer to receive DXL piped from exporter \n# REM and to re-import the documents back into the \n# REM current database as copies. \n# \tSet exporter = session.CreateDXLExporter(nc) \n# \t\n# \tCall exporter.SetInput(nc) \n# \tCall exporter.SetOutput(stream) \n#    \'There are two kinds of XML-valid and well-formed. \n# \'Valid XML has a DTD. \n# \'Well-formed XML has no DTD, but is properly constructed-all entities are declared, properly closed, and correctly nested. \n# \'The XML specification makes a DTD optional. \n# \'Well-formed XML is self-documenting and can be processed without a DTD. \n# \'Valid XML cannot. \n# \texporter.OutputDOCTYPE = False \' Stops the <!DOCTYPE database SYSTEM \'xmlschemas/domino_7_0.dtd\'> from being added to output. \n# \tCall exporter.Process \n# End Sub'
    False
    ''
    '* 1 * * *'
    'capitalize'
    '\n#------------ \n# code from lotus domino\n# Event: action\n# code type: simpleaction\n#------------ \n# action: modifyfieldfield: namevalue: capitalize(name)'
    True
    ''
    '* 1 * * *'
    'purgeDb'
    '\n#------------ \n# code from lotus domino\n# Event: action\n# code type: formula\n#------------ \n# @GetField(name);\n#  @All'
    True
    ''
    '* 1 * * *'
