<s> import os <EOL> import unittest <EOL> import logging <EOL> import tempfile <EOL> from imgfac . Template import Template <EOL> from imgfac . ImageWarehouse import ImageWarehouse <EOL> from imgfac . ApplicationConfiguration import ApplicationConfiguration <EOL> from imgfac . builders . Mock_Builder import Mock_Builder <EOL> class testTemplate ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> logging . basicConfig ( level = logging . NOTSET , format = '<STR_LIT>' , filename = '<STR_LIT>' ) <EOL> self . warehouse = ImageWarehouse ( ApplicationConfiguration ( ) . configuration [ "<STR_LIT>" ] ) <EOL> self . template_xml = "<STR_LIT>" <EOL> def tearDown ( self ) : <EOL> del self . warehouse <EOL> del self . template_xml <EOL> def testTemplateFromUUID ( self ) : <EOL> template_id = self . warehouse . store_template ( self . template_xml ) <EOL> template = Template ( template_id ) <EOL> self . assertEqual ( template_id , template . identifier ) <EOL> self . assertEqual ( self . template_xml , template . xml ) <EOL> self . assertFalse ( template . url ) <EOL> def testTemplateFromImageID ( self ) : <EOL> template_id = self . warehouse . store_template ( self . template_xml ) <EOL> template = Template ( template_id ) <EOL> target = "<STR_LIT>" <EOL> builder = Mock_Builder ( self . template_xml , target ) <EOL> builder . build_image ( ) <EOL> metadata = dict ( template = template_id , target = target , icicle = "<STR_LIT:None>" , target_parameters = "<STR_LIT:None>" ) <EOL> self . warehouse . store_target_image ( builder . new_image_id , builder . image , metadata = metadata ) <EOL> image_template = Template ( builder . new_image_id ) <EOL> self . assertEqual ( template_id , image_template . identifier ) <EOL> self . assertEqual ( self . template_xml , image_template . xml ) <EOL> self . assertFalse ( template . url ) <EOL> def testTemplateFromXML ( self ) : <EOL> template = Template ( self . template_xml ) <EOL> self . assertEqual ( self . template_xml , template . xml ) <EOL> self . assertFalse ( template . identifier ) <EOL> self . assertFalse ( template . url ) <EOL> def testTemplateFromURL ( self ) : <EOL> template_id = self . warehouse . store_template ( self . template_xml ) <EOL> template_url = "<STR_LIT>" % ( self . warehouse . url , self . warehouse . template_bucket , template_id ) <EOL> template = Template ( template_url ) <EOL> self . assertEqual ( template_url , template . url ) <EOL> self . assertEqual ( template_id , template . identifier ) <EOL> self . assertEqual ( self . template_xml , template . xml ) <EOL> def testTemplateFromPath ( self ) : <EOL> ( fd , template_path ) = tempfile . mkstemp ( prefix = "<STR_LIT>" ) <EOL> os . write ( fd , self . template_xml ) <EOL> os . close ( fd ) <EOL> template = Template ( template_path ) <EOL> self . assertFalse ( template . url ) <EOL> self . assertFalse ( template . identifier ) <EOL> self . assertEqual ( self . template_xml , template . xml ) <EOL> os . remove ( template_path ) <EOL> def testTemplateStringRepresentation ( self ) : <EOL> template = Template ( self . template_xml ) <EOL> self . assertEqual ( self . template_xml , repr ( template ) ) <EOL> self . assertEqual ( self . template_xml , str ( template ) ) <EOL> self . assertEqual ( self . template_xml , "<STR_LIT>" % ( template , ) ) <EOL> self . assertEqual ( self . template_xml , "<STR_LIT:%s>" % ( template , ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
