Beispiel #1
0
class SuperTestCase(unittest.TestCase):
    """
    Provides a base for higher level test cases.
    """
    def setUp(self):
        """
        Creates an application and 
        almost launches it.
        """
        logFileName = Path('tmp/app data/test.conf')
        Config._getConfigPathOptions = lambda s: [logFileName]
        if not logFileName.dirname().exists():
            logFileName.dirname().makedirs()
        confParser = ConfigParser()
        self._setupConfigFile(confParser)
        confParser.write(logFileName)
        self.app = Application()
        self.app.loadConfiguration()
        self.app.preLaunch()
        self.client = FakeClient()
        self.package = Package('temp')
        self.app.webServer.root.bindNewPackage(self.package)
        self.mainpage = self.app.webServer.root.children['temp']
    def tearDown(self):
        """
        Remove the global app instance
        """
        from exe import globals
        globals.application = None
    def _setupConfigFile(self, configParser):
        """
        Override this to setup any customised config
        settings
        """
        system = configParser.addSection('system')
        system.exePath = '../exe/exe'
        system.exeDir = '../exe'
        system.webDir = '../exe/webui'
        system.localeDir = '../exe/locale'
        system.port = 8081
        tmpDir = Path('tmp')
        if not tmpDir.exists(): tmpDir.mkdir()
        dataDir = tmpDir/'data'
        if not dataDir.exists():
            dataDir.mkdir()
        system.dataDir = dataDir
        system.browserPath = 'not really used in tests so far'
        logging = configParser.addSection('logging')
        logging.root = 'DEBUG'
    def _request(self, **kwargs):
        """
        Pass me args and I return you a fake request object.
        eg. self._request(action='addIdevice').args['action'][0] == 'addIdevice'
        """
        return FakeRequest(**kwargs)
Beispiel #2
0
 def setUp(self):
     class MyConfig:
         def __init__(self):
             self.port       = 8081
             self.dataDir    = Path(".")
             self.webDir     = Path(".")
             self.exeDir     = Path(".")
             self.configDir  = Path(".")
             self.styles     = ["default"]
     app = Application()
     app.config = MyConfig()
     app.preLaunch()
     self.client = FakeClient()
     self.package = Package('temp')
     app.webServer.root.bindNewPackage(self.package)
     self.outline = app.webServer.root.children['temp'].outlinePane
Beispiel #3
0
    def setUp(self):
        class MyConfig:
            def __init__(self):
                self.port = 8081
                self.dataDir = Path(".")
                self.webDir = Path(".")
                self.exeDir = Path(".")
                self.configDir = Path(".")
                self.styles = ["default"]

        app = Application()
        app.config = MyConfig()
        app.preLaunch()
        self.client = FakeClient()
        self.package = Package('temp')
        app.webServer.root.bindNewPackage(self.package)
        self.outline = app.webServer.root.children['temp'].outlinePane
                     dest="website",
                     help=_(u"Include Web Site export files").encode(sys.stdout.encoding),
                     default=False)
    parser.add_option_group(group)

    return parser

if __name__ == "__main__":
    application = Application()
    
    if '--standalone' in sys.argv:
        application.standalone = True
        sys.argv.remove("--standalone")
        
    application.loadConfiguration()
    application.preLaunch()
    optparse._ = application.config.locales[application.config.locale].gettext

    parser = prepareParser()
    options, args = parser.parse_args()
    

    if options.x and options.i:
        parser.error(_(u'Options --export and --import are mutually \
exclusive.').encode(sys.stdout.encoding))
    if not options.x and not options.i and not options.set_options and not options.report:
        parser.error(_(u'No --export, --import, --set or --report option supplied.')\
.encode(sys.stdout.encoding))

    if not args:
        parser.error(_(u'No file input supplied.').encode(sys.stdout.encoding))
class SuperTestCase(unittest.TestCase):
    """
    Provides a base for higher level test cases.
    """
    def setUp(self):
        """
        Creates an application and 
        almost launches it.
        """
        # Make whatever config class that application uses only look for our
        # Set up our customised config file
        logFileName = Path('tmp/app data/test.conf')
        Config._getConfigPathOptions = lambda s: [logFileName]
        if not logFileName.dirname().exists():
            logFileName.dirname().makedirs()
        confParser = ConfigParser()
        self._setupConfigFile(confParser)
        confParser.write(logFileName)
        # Start up the app and friends
        self.app = Application()
        self.app.loadConfiguration()
        self.app.preLaunch()
        self.client = FakeClient()
        self.package = Package('temp')
        self.app.webServer.root.bindNewPackage(self.package)
        self.mainpage = self.app.webServer.root.children['temp']

    def tearDown(self):
        """
        Remove the global app instance
        """
        from exe import globals
        globals.application = None

    def _setupConfigFile(self, configParser):
        """
        Override this to setup any customised config
        settings
        """
        # Set up the system section
        system = configParser.addSection('system')
        system.exePath = '../exe/exe'
        system.exeDir = '../exe'
        system.webDir = '../exe/webui'
        system.localeDir = '../exe/locale'
        system.port = 8081
        # Make a temporary dir where we can save packages and exports etc
        tmpDir = Path('tmp')
        if not tmpDir.exists(): tmpDir.mkdir()
        dataDir = tmpDir / 'data'
        if not dataDir.exists():
            dataDir.mkdir()
        system.dataDir = dataDir
        system.browserPath = 'not really used in tests so far'
        # Setup the logging section
        logging = configParser.addSection('logging')
        logging.root = 'DEBUG'

    def _request(self, **kwargs):
        """
        Pass me args and I return you a fake request object.
        eg. self._request(action='addIdevice').args['action'][0] == 'addIdevice'
        """
        return FakeRequest(**kwargs)