def test_AmpRegEx(self):
     pymms = pyMailMergeService( enablelogging=False )
     amp = pymms._getRegEx( 'amp'  )
     self.assertEquals( "blah & blah", re.sub( amp, "&", "blah & blah" ) )
     self.assertEquals( "blah & blah &", re.sub( amp, "&", "blah & blah &" ) )
     self.assertEquals( "blah & blah", re.sub( amp, "&", "blah & blah" ) )
     self.assertEquals( "blah < blah", re.sub( amp, "&", "blah < blah" ) )
     self.assertEquals( "blah • blah", re.sub( amp, "&", "blah • blah" ) )
 def test_if_section_simple_false(self):
     xml = getXML( "if_section_simple.odt" )
     key = "if|token::testif"
     value = 0
     #run method
     pymms = pyMailMergeService( enablelogging=False )
     xml = pymms._if( key, value, xml )
     xml = etree.XML( xml )
     #test values
     p = xml.xpath( "//text:p[contains(.,'%s')]" % "blah blah", namespaces={'text':'urn:oasis:names:tc:opendocument:xmlns:text:1.0'} )
     self.assertEqual( 0, len( p ) )
 def test_sortparams(self):
     params = [ ['test::token', 0], ['if|test::if', 1], ['repeatcolumn|test::repeatcol', 2], ['repeatrow|test::repeat_row', 3], ['repeatsection|test::repeatsect', 4] ]
     #params[ "test::token" ] = ['0']
     #run method
     pymms = pyMailMergeService( enablelogging=False )
     params = pymms._sortparams( params )
     #test the output
     self.assertEquals( 1, params[0]['if|test::if'] )
     self.assertEquals( 4, params[1]['repeatsection|test::repeatsect'] )
     self.assertEquals( 2, params[2]['repeatcolumn|test::repeatcol'] )
     self.assertEquals( 3, params[3]['repeatrow|test::repeat_row'] )
     self.assertEquals( 0, params[4]['test::token'] )
     self.assertEquals( 5, len( params ) )
 def testLogging(self):
     try:
         #remove the file in case it exists before the test.
         os.unlink( 'pymms.log' )
     except:
         pass
     pmms = pyMailMergeService( enablelogging=False )
     pmms.hello( 'world' )
     #I just want to make sure the log file does not get created, if the log 
     #does not exist then an exception will be thrown.
     file = None
     try:
         file = open( 'pymms.log' )
     except:
         pass
     self.assertEquals( None, file )
 def test_repeat_column_merged_columns_before( self ):
     xml = getXML( "repeat_column_merged_columns_before.odt" )
     key = "repeatcolumn|token::test"
     value = ( "replace1", "replace2" )
     #run methods
     pymms = pyMailMergeService( enablelogging=False )
     xml = pymms._repeatcolumn( xml, key, value )
     matrix = getTableText( xml )
     self.assertEqual( 'a1', matrix[0][0] )
     self.assertEqual( 'a2', matrix[0][1] )
     self.assertEqual( 'replace1', matrix[0][2] )
     self.assertEqual( 'replace2', matrix[0][3] )
     self.assertEqual( 'b1b2', matrix[1][0] )
     self.assertEqual( 'b3', matrix[1][1] )
     self.assertEqual( 'b3', matrix[1][2] )
     self.assertEqual( 'c1', matrix[2][0] )
     self.assertEqual( 'c2', matrix[2][1] )
     self.assertEqual( 'c3', matrix[2][2] )
     self.assertEqual( 'c3', matrix[2][3] )
 def test_simple_repeat_column( self ):
     #mock data
     xml = getXML( "simple_repeat_column.odt" )
     key = "repeatcolumn|token::test"
     value = ( "replace1", "replace2" )
     #run methods
     pymms = pyMailMergeService( enablelogging=False )
     xml = pymms._repeatcolumn( xml, key, value )
     #test results
     matrix = getTableText( xml )
     self.assertEquals( 2, len( matrix ) )
     self.assertEquals( 3, len( matrix[0] ) )
     self.assertEquals( 3, len( matrix[1] ) )
     self.assertEquals( "replace1", matrix[0][0] )
     self.assertEquals( "replace2", matrix[0][1] )
     self.assertEquals( "a2", matrix[0][2] )
     self.assertEquals( "b1", matrix[1][0] )
     self.assertEquals( "b1", matrix[1][1] )
     self.assertEquals( "b2", matrix[1][2] )
 def testParseXMLParams(self):
     xml = """<?xml version="1.0" encoding="UTF-8"?>
     <tokens>
         <token>
             <name>whatever::whatever</name>
             <value>somevalue</value>
         </token>
         <token>
             <name>token::multivalue</name>
             <value>a</value>
             <value>b</value>
             <value>c</value>
         </token>
     </tokens>"""
     pymms = pyMailMergeService( enablelogging=False )
     params = pymms._parseXMLParams( xml )
     params = pymms._sortparams( params )
     self.assertEquals( "somevalue", params[0]['whatever::whatever'] )
     self.assertEquals( "a", params[1]['token::multivalue'][0] )
     self.assertEquals( "b", params[1]['token::multivalue'][1] )
     self.assertEquals( "c", params[1]['token::multivalue'][2] )
 def test_TokenRegEX(self):
     pymms = pyMailMergeService( enablelogging=False )
     token = pymms._getRegEx( 'tokens' )
     sampleStringOfPossibleTokens = """
     ~blah::blah~     #should be found
     ~blah::blah|1~   #should be found
     ~object::method|param~    #should be found
     ~modifier|object::method|param~    #should be found
     ~modifier|object::method|param|param2~    #should be found
     ~object::method2~    #should be found
     ~object::method|param|paramwith)~    #shold be found -- this is a specific use case for my company... I know it's a little weird.
     ~object::rightnext1~~object::rightnext2~ #should both be found
     ~object::noclosingtilde    #should NOT work because it has no closing tilde
     object::noopeningtilde~    #should NOT work because it has no opening tilde
     ~::blah|12~      #should NOT be found because the object part is missing
     ~object::method_test~    #should NOT be found
     ~modifier|object::method|para#~    #should NOT be found
     blahblah~object::mixedinwithothertext~blahblah  I'm just proving that this should be there because it'sm mixed in with other text
     ~object1::method1~    #should NOT be found because it has a number in the object, which really isn't a problem unless it's first but whatever.
     ~~    #should NOT be found
     """
     matches = token.findall( sampleStringOfPossibleTokens )
     self.assertTrue( "::blah|12" not in matches )
     self.assertTrue( "blah::blah" in matches )
     self.assertTrue( "blah::blah|1" in matches )
     self.assertTrue( "object::method|param" in matches )
     self.assertTrue( "modifier|object::method|param" in matches )
     self.assertTrue( "modifier|object::method|param|param2" in matches )
     self.assertTrue( "modifier|object::method|para#" not in matches )
     self.assertTrue( "object::method2" in matches )
     self.assertTrue( 'object::mixedinwithothertext' in matches )
     self.assertTrue( 'object::rightnext1' in matches )
     self.assertTrue( 'object::rightnext2' in matches )
     self.assertTrue( 'object::modifier_test' not in matches )
     self.assertTrue( 'object::method|param|paramwith)' in matches )
     self.assertTrue( 'object::noclosingtilde' not in matches )
     self.assertTrue( 'object::noopeningtilde' not in matches )
     self.assertTrue( 'object1::method1' not in matches )
     self.assertTrue( "" not in matches )
 def test_hello(self):
     pymms = pyMailMergeService( enablelogging=False )
     self.assertEquals( 'hello test', pymms.hello( 'test' ) )
     self.assertEquals( 'hello world', pymms.hello() )
 def test_get_file_extension(self):
     pymms = pyMailMergeService( enablelogging=False )
     self.assertEqual( 'odt', pymms._getFileExtension( "simple_repeat_column.odt" ) )
     self.assertEqual( 'odt', pymms._getFileExtension( "invoice.odt" ) )