<s> import glob <EOL> import mock <EOL> import os <EOL> import shutil <EOL> import unittest <EOL> import zipfile <EOL> from cStringIO import StringIO <EOL> from simple_idml . indesign import indesign <EOL> from suds . client import ServiceSelector <EOL> from urllib2 import OpenerDirector <EOL> CURRENT_DIR = os . path . dirname ( __file__ ) <EOL> IDMLFILES_DIR = os . path . join ( CURRENT_DIR , "<STR_LIT>" ) <EOL> SOAP_DIR = os . path . join ( CURRENT_DIR , "<STR_LIT>" ) <EOL> CLIENT_WORKDIR = os . path . join ( CURRENT_DIR , "<STR_LIT>" ) <EOL> SERVER_WORKDIR = os . path . join ( CURRENT_DIR , "<STR_LIT>" ) <EOL> class InDesignTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( InDesignTestCase , self ) . setUp ( ) <EOL> self . u2open_patcher = mock . patch ( '<STR_LIT>' ) <EOL> self . u2open_mock = self . u2open_patcher . start ( ) <EOL> self . u2open_mock . side_effect = OpenerDirectorMock <EOL> self . runscript_patcher = mock . patch ( '<STR_LIT>' ) <EOL> self . runscript_mock = self . runscript_patcher . start ( ) <EOL> self . runscript_mock . side_effect = ServiceSelectorMock <EOL> for f in glob . glob ( os . path . join ( CLIENT_WORKDIR , "<STR_LIT:*>" ) ) : <EOL> if os . path . isdir ( f ) : <EOL> shutil . rmtree ( f ) <EOL> else : <EOL> os . unlink ( f ) <EOL> if not ( os . path . exists ( CLIENT_WORKDIR ) ) : <EOL> os . makedirs ( CLIENT_WORKDIR ) <EOL> def tearDown ( self ) : <EOL> self . u2open_patcher . stop ( ) <EOL> self . runscript_patcher . stop ( ) <EOL> def test_save_as ( self ) : <EOL> responses = indesign . save_as ( os . path . join ( IDMLFILES_DIR , "<STR_LIT>" ) , <EOL> [ { "<STR_LIT>" : "<STR_LIT>" } ] , <EOL> "<STR_LIT>" , <EOL> CLIENT_WORKDIR , SERVER_WORKDIR , <EOL> indesign_server_path_style = "<STR_LIT>" ) <EOL> self . assertTrue ( self . runscript_mock . called ) <EOL> self . assertEqual ( responses , [ '<STR_LIT>' ] ) <EOL> responses = indesign . save_as ( os . path . join ( IDMLFILES_DIR , "<STR_LIT>" ) , <EOL> [ { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } } , <EOL> { "<STR_LIT>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : "<STR_LIT>" } ] , <EOL> "<STR_LIT>" , <EOL> CLIENT_WORKDIR , SERVER_WORKDIR , <EOL> indesign_server_path_style = "<STR_LIT>" ) <EOL> self . assertTrue ( self . runscript_mock . called ) <EOL> self . assertEqual ( responses [ : <NUM_LIT:2> ] , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] ) <EOL> zip_buf = StringIO ( ) <EOL> zip_buf . write ( responses [ <NUM_LIT:2> ] ) <EOL> self . assertTrue ( zipfile . is_zipfile ( zip_buf ) ) <EOL> def test_close_all_documents ( self ) : <EOL> indesign . close_all_documents ( "<STR_LIT>" , <EOL> CLIENT_WORKDIR , SERVER_WORKDIR , <EOL> indesign_server_path_style = "<STR_LIT>" ) <EOL> self . assertTrue ( self . runscript_mock . called ) <EOL> indesign . close_all_documents ( "<STR_LIT>" , <EOL> CLIENT_WORKDIR , SERVER_WORKDIR , <EOL> indesign_server_path_style = "<STR_LIT>" ) <EOL> self . assertTrue ( self . runscript_mock . called ) <EOL> class OpenerDirectorMock ( OpenerDirector ) : <EOL> def open ( self , fullurl = None , data = None , timeout = None ) : <EOL> url = fullurl . get_full_url ( ) <EOL> if os . path . basename ( url ) == '<STR_LIT>' : <EOL> return open ( os . path . join ( SOAP_DIR , '<STR_LIT>' ) , "<STR_LIT:r>" ) <EOL> class ServiceSelectorMock ( ServiceSelector ) : <EOL> def RunScript ( self , params ) : <EOL> script = os . path . basename ( params [ '<STR_LIT>' ] ) <EOL> script_args = dict ( [ ( p [ "<STR_LIT:name>" ] , p [ "<STR_LIT:value>" ] ) for p in params [ '<STR_LIT>' ] ] ) <EOL> if script in indesign . JS_SAVE_AS_SCRIPTS : <EOL> script_args . pop ( "<STR_LIT:source>" ) <EOL> dst_filename = script_args . pop ( "<STR_LIT>" ) <EOL> extra_params = script_args <EOL> if script == indesign . JS_PACKAGE_SCRIPT : <EOL> os . mkdir ( dst_filename ) <EOL> dst_filename = "<STR_LIT>" % dst_filename <EOL> fobj = open ( dst_filename , "<STR_LIT>" ) <EOL> fobj . write ( "<STR_LIT>" % ( script , <EOL> os . path . basename ( dst_filename ) , <EOL> extra_params ) ) <EOL> elif script in indesign . JS_CLOSE_ALL_SCRIPT : <EOL> pass <EOL> def suite ( ) : <EOL> suite = unittest . TestLoader ( ) . loadTestsFromTestCase ( InDesignTestCase ) <EOL> return suite </s>
