Esempio n. 1
0
    def test_EnvironmentNameIsNotSpecifiedRaisesError(self):
        """
        Verifies requirement GEN000003. Checks that the environment name must 
        be specified in the command line parameters.
        """
        # Setup Mock Object
        self.common.SetupMox(self)

        testharness.getOptDebugFlag().AndReturn(True)
        testharness.getOptParam().AndReturn(None)
        testharness.getOptExternal().AndReturn(self.external)
        testharness.getOptImplantable().AndReturn(self.implantable)
        testharness.getOptEnv().AndReturn(None)

        self.mocker.ReplayAll()

        self.trace('GEN000003')
        try:
            tc = komodo.getTestContext()
            self.verifyFailed(msg="Did not catch the MissingCommandLineParamError exception.")
            
        except komodo.MissingCommandLineParamError:
            self.verified(msg="MissingCommandLineParamError was raised")            	

        except:
            self.verifyFailed(msg="Did not catch the MissingCommandLineParamError exception.")	
        self.mocker.VerifyAll()

        # Reset Mock Object
        self.common.UnsetMox(self)
Esempio n. 2
0
    def test_MalformedPGSimParameter(self):
        """
        Verifies requirement GEN000003. Check that bad inputs are handled 
        correctly.
        """
        # Setup Mock Object
        self.common.SetupMox(self)

        testharness.getOptDebugFlag().AndReturn(True)
        testharness.getOptParam().AndReturn({'pgsim': self.badBooleanName})
        testharness.getOptExternal().AndReturn(self.external)
        testharness.getOptImplantable().AndReturn(self.implantable)
        testharness.getOptEnv().AndReturn(self.env)
        self.mocker.ReplayAll()

        self.trace('GEN000003')
        try:
            tc = komodo.getTestContext()
            self.verifyFailed(msg="Did not catch the UnrecognizedCommandLineParamError exception.")

        except komodo.UnrecognizedCommandLineParamError:
            self.verified(msg="UnrecognizedCommandLineParamError was raised")	    

        except:
            self.verifyFailed(msg="Did not catch the UnrecognizedCommandLineParamError exception.")	
        self.mocker.VerifyAll()
        
        # Reset Mock Object
        self.common.UnsetMox(self)    
Esempio n. 3
0
    def test_PGModelIsNotSpecifiedRaisesError(self):
        """
        Verifies requirement GEN000003. Checks that the missing config exception
        is thrown when the PG model is not specified.
        """
        # Setup Mock Object
        self.common.SetupMox(self)

        testharness.getOptDebugFlag().AndReturn(True)
        testharness.getOptParam().AndReturn(None)
        testharness.getOptExternal().AndReturn(self.external)
        testharness.getOptImplantable().AndReturn(None)
        testharness.getOptEnv().AndReturn(self.env)
        self.mocker.ReplayAll()

        self.trace('GEN000003')
        try:
            tc = komodo.getTestContext()
            self.verifyFailed(msg="Did not catch the MissingCommandLineParamError exception.")

        except komodo.MissingCommandLineParamError:
            self.verified(msg="MissingCommandLineParamError was raised")	    

        except:
            self.verifyFailed(msg="Did not catch the MissingCommandLineParamError exception.")	

        self.mocker.VerifyAll() 

        # Reset Mock Object
        self.common.UnsetMox(self)        
Esempio n. 4
0
    def test_EnvironmentObjectIsRetrieved(self):
        """
        Verifies requirement GEN000003. Checks that the environment object was 
        retrieved.
        """
        # Setup Mock Object
        self.common.SetupMox(self)

        # Stub out the testharness functions that are called
        testharness.getOptDebugFlag().AndReturn(True)
        testharness.getOptParam().AndReturn(None)
        testharness.getOptExternal().AndReturn(self.external)
        testharness.getOptImplantable().AndReturn(self.implantable)
        testharness.getOptEnv().AndReturn(self.env)

        # In order for the testContext to return successfully, the environment 
        # geography and the external availability should match. Force this to 
        # occur with a mock environment object
        MockEnv = mox.MockObject(Environment)
        MockEnv.geography = 'us'
        availability.evaluate('US').AndReturn(True)
        environment.getInstance(self.env).AndReturn(MockEnv)
        self.mocker.ReplayAll()

        testContext = komodo.getTestContext()	
        # Verification
        self.trace('GEN000003')
        self.verify(testContext['env'] is not None)
        self.mocker.VerifyAll()
        
        # Reset Mock Object
        self.common.UnsetMox(self)        
Esempio n. 5
0
    def test_ParameterDefaultsAreSetCorrectly(self):
        """
        Verifies requirements GEN000003 and GEN000004. Check that the default 
        optional parameters are set when none are specified. 
        
        GEN000003: Komodo shall provide a context to capture command line 
        options for the following attributes: External, Implantable, Environment,
        Browser Type, Enroll type, PG Simulator, Debug.

        
        GEN000004: Komodo shall provide the ability to load the product line 
        model for the external and implantable in the context.
        """
        # Setup Mock Object
        self.common.SetupMox(self)

        testharness.getOptDebugFlag().AndReturn(True)
        testharness.getOptParam().AndReturn(None)
        testharness.getOptExternal().AndReturn(self.external)
        testharness.getOptImplantable().AndReturn(self.implantable)
        testharness.getOptEnv().AndReturn(self.env)

        # In order for the testContext to return successfully, the environment 
        # geography and the external availability should match. Force this to 
        # occur with a mock environment object
        MockEnv = mox.MockObject(Environment)
        MockEnv.geography = 'us'
        availability.evaluate('US').AndReturn(True)
        environment.getInstance(self.env).AndReturn(MockEnv)
        self.mocker.ReplayAll()

        testContext = komodo.getTestContext()

        self.trace('GEN000003')
        self.verifyEqual(testContext['brwsr'], komodo.BROWSER_DEFAULT)
        self.verifyEqual(testContext['pgsim'], False)
        self.verifyEqual(testContext['enroll'], True)
        self.mocker.VerifyAll()
        
        # Reset Mock Object
        self.common.UnsetMox(self)	 
        
        self.trace('GEN000004')
        self.verifyTrue(availability.getExternal() is not None, msg="External PLM was loaded.")
        self.verifyTrue(availability.getImplantable() is not None, msg="Implantable PLM was loaded.")
Esempio n. 6
0
    def test_EnvironmentExternalGeographyMismatchRaisesError(self):
        """
        Verifies requirement GEN000005. Check that the external param and the 
        env geography mismatch throw an error.
        """
        # Setup Mock Object
        self.common.SetupMox(self)

        testharness.getOptDebugFlag().AndReturn(True)
        testharness.getOptParam().AndReturn(None)
        testharness.getOptExternal().AndReturn(self.external)
        testharness.getOptImplantable().AndReturn(self.implantable)
        testharness.getOptEnv().AndReturn(self.env)

        # In order for the testContext to return successfully, the environment 
        # geography and the external availability should match. Force this to 
        # occur with a mock environment object
        MockEnv = mox.MockObject(Environment)
        MockEnv.geography = 'us'
        availability.evaluate('US').AndReturn(False)
        environment.getInstance(self.env).AndReturn(MockEnv)
        self.mocker.ReplayAll()

        self.trace('GEN000005')
        try:
            tc = komodo.getTestContext()
            self.verifyFailed(msg="Did not catch the ExternalPLMEnvironmentMismatchError exception.")

        except ExternalPLMEnvironmentMismatchError:
            self.verified(msg="ExternalPLMEnvironmentMismatchError was raised")	    

        except:
            self.verifyFailed(msg="Did not catch the ExternalPLMEnvironmentMismatchError exception.")

        self.mocker.VerifyAll() 
        
        # Reset Mock Object
        self.common.UnsetMox(self)
Esempio n. 7
0
def getTestContext():
    """
    Defines the context parameters of the test from command-line parameters for
    use with any library component that requires this information. Parameters 
    are specified with key/value pairs using the perseus -p option. 
    
    Example::

        python Test_Script.py -t test1 -c case1 -e isosys5a -x EU_1.0_JAGRF -i J063-200-1 -p brwsr=InternetExplorer,enroll=True,pgsim=False
        
    I{Available parameters used by Komodo}::
        -brwsr    = InternetExplorer, Firefox (default), HtmlUnit -- see SyRS010131
        -pgsim    = True, False (default)
        -enroll   = True (default), False (direct to database)
    
    I{REQUIRED parameters available through Perseus command-line options}::
        -e = [name of environment, no underscores],  REQUIRED
        -x = [external from PLE], REQUIRED, must be specified before "-i"
        -i = [implantable from PLE], REQUIRED
        
    B{NOTE}:
    
    The Perseus command-line option "-r" for PLM release is ignored by Komodo.
    You cannot specify versions of browsers in Komodo, that is a test station-specific setup.
        
    @return: TestContext dictionary
    @rtype: C{dict}
    
    @raises UnrecognizedCommandLineParamError: 
    @raises MissingCommandLineParamError:
    """
    logger.info('** Komodo System Evaluation Automation Test Library Version %s **' % __VERSIONSTR)
    testContext = dict()
    _rawCommandLineArgs = dict()
    
    # Parse the specified command-line parameters from "-p"
    _rawCommandLineParams = testharness.getOptParam()

    # Check to make sure some command-line arguments were specified, malformed -p args may appear as strings
    if _rawCommandLineParams is not None and type(_rawCommandLineParams) is dict:
        logger.info('Command line Parameters: %s' % _rawCommandLineParams)
        _rawCommandLineArgs.update(_rawCommandLineParams)    

    # No parameters specified or parameters are strings, do nothing and let them
    # go unnoticed by Komodo
    else:
        pass

    _rawCommandLineArgs['debug'] = testharness.getOptDebugFlag()
    _rawCommandLineArgs['external'] = testharness.getOptExternal()
    _rawCommandLineArgs['implantable'] = testharness.getOptImplantable()
    _rawCommandLineArgs['env'] = testharness.getOptEnv()
        
    # Set the logger level if the debug flag is on
    if _rawCommandLineArgs['debug']:
        logger.setLevel(_plog.DEBUG)    
    
    # Browsers for web navigation (no longer supported), leave here for brevity
    testContext['brwsr'] = BROWSER_DEFAULT
            
    # PG Simulator vs Real PG
    if 'pgsim' in _rawCommandLineArgs:
        if _rawCommandLineArgs['pgsim'].lower() == 'true':
            testContext['pgsim'] = True
        elif _rawCommandLineArgs['pgsim'].lower() == 'false':
            testContext['pgsim'] = False
        else:
            logger.error('Unrecognized value for Command line Parameter - pgsim [%s]' % _rawCommandLineArgs['pgsim'])
            raise UnrecognizedCommandLineParamError("Parameter 'pgsim' values are 'True' or 'False'.")
    
    else:
        testContext['pgsim'] = False
        
    # Test Data: Enrollment vs Direct to Database push
    if 'enroll' in _rawCommandLineArgs:
        if _rawCommandLineArgs['enroll'].lower() == 'true':
            testContext['enroll'] = True
        elif _rawCommandLineArgs['enroll'].lower() == 'false':
            testContext['enroll'] = False
        else:
            logger.error('Unrecognized value for Command line Parameter - enroll [%s]' % _rawCommandLineArgs['enroll'])
            raise UnrecognizedCommandLineParamError("Parameter 'enroll' values are 'True' or 'False'.")
            
    else:
        testContext['enroll'] = True
        
    # Country: If the test wants to specify a country different than a random
    if 'country' in _rawCommandLineArgs:
            testContext['country'] = _rawCommandLineArgs['country']            
    else:
        testContext['country'] = None    
        
    # External (i.e. Communicator, required)
    if 'external' in _rawCommandLineArgs and _rawCommandLineArgs['external'] is not None:
        testContext['external'] = _rawCommandLineArgs['external']
        perseus.availability.loadExternal(testContext['external'])
        
    else:
        logger.error('Missing Command line Parameter - external')
        raise MissingCommandLineParamError("Parameter 'external' is required.")
    
    # PG Model (required)
    if 'implantable' in _rawCommandLineArgs and _rawCommandLineArgs['implantable'] is not None:
        testContext['implantable'] = _rawCommandLineArgs['implantable']
        perseus.availability.loadImplantable(testContext['implantable'])

    else:
        logger.error('Missing Command line Parameter - implantable')
        raise MissingCommandLineParamError("Parameter 'implantable' is required.")
        
    # Environment Name (required)
    if 'env' in _rawCommandLineArgs and _rawCommandLineArgs['env'] is not None:
        testContext['env'] = environment.getInstance(_rawCommandLineArgs['env'])
            
        # The external should be in the format [2-char server deployment]_[release #]_[comm model #]
        if testContext['external'][1:3].lower() == testContext['env'].geography.lower():
            logger.info('testContext PLM "external" %s matches environment geography %s' % (testContext['external'], testContext['env'].geography.upper()))
        else:
            logger.error('testContext PLM "external" %s does NOT match environment geography %s' % (testContext['external'], testContext['env'].geography.upper()))
            raise ExternalPLMEnvironmentMismatchError("Availability (%s) and Geography (%s) do not match" % (testContext['external'], testContext['env'].geography.upper()))

        # If a country has been specified, check it as well
        if testContext['country']:
            for ctry in testContext['env'].countries:
                if testContext['country'] == ctry.iso3code:
                    logger.info('testContext country "%s" matches an environment-supported geography' % testContext['country'])
                    testContext['country'] = ctry
                    testContext['country'].default = True
                    break
            else:
                logger.error('testContext country "%s" does not match environment support geographies: "%s"' % (testContext['country'], ", ".join( [x.iso3code for x in testContext['env'].countries] )))
                raise UnrecognizedCommandLineParamError('testContext country "%s" not found' % testContext['country'])
        else:
            testContext['country'] = None
        
    else:
        logger.error('Missing Command line Paramater - env')
        raise MissingCommandLineParamError("Parameter 'env' is required")
    
    # Log commandline parameters set in testContext
    logger.debug('testContext values: %s' % testContext)
    logger.info('Successfully created Komodo testContext dictionary.')

    return testContext
Esempio n. 8
0
def getTestContext():
    """
    Defines the context parameters of the test from command-line parameters for
    use with any library component that requires this information. Parameters 
    are specified with key/value pairs using the perseus -p option. 
    
    I{Available parameters used by KomodoRS}::
        -pgsim    = True, False (default)
        -brwsr    = InternetExplorer (default), Firefox 
    
    I{REQUIRED parameters available through Perseus command-line options}::
        -e = [name of environment, no underscores],  REQUIRED
        -x = [external from PLE], REQUIRED, must be specified before "-i"
        -i = [implantable from PLE], REQUIRED
        
    B{NOTE}:
    
    The Perseus command-line option "-r" for PLM release is ignored by KomodoRS.
    You cannot specify versions of browsers in Komodo, that is a test station-specific setup.
        
    @return: TestContext dictionary
    @rtype: C{dict}
    
    @raises UnrecognizedCommandLineParamError: 
    @raises MissingCommandLineParamError:        
    """
    testContext = {}
    # Get required parameters
    testContext['env'] = testharness.getOptEnv() 
    testContext['external'] = testharness.getOptExternal()
    testContext['implantable'] = testharness.getOptImplantable()
    
    # Set optional parameters to default values
    testContext['pgsim'] = PGSIM_DEFAULT 
    testContext['brwsr'] = BROWSER_DEFAULT
    
    # Get optional parameters - overwrite defaults
    optionalParams = testharness.getOptParam()
    if isinstance(optionalParams, dict):
        customBoolArgs = CUSTOM_ARGS.split(',')
        for arg in optionalParams:
            if arg == 'pgsim':
                if not optionalParams[arg].lower() in ('true','false'):
                    raise UnrecognizedCommandLineParamError("Optional command line argument %s must be True or False" % arg)
                testContext[arg] = (optionalParams[arg].lower() == 'true')    
            elif arg == 'brwsr':
                if not optionalParams[arg].lower() in ('firefox','internetexplorer'):
                    raise UnrecognizedCommandLineParamError("Optional command line argument %s must be Firefox or InternetExplorer" % arg)
                testContext[arg] = optionalParams[arg].lower()
            else:
                raise UnrecognizedCommandLineParamError("Command line argument %s not recognized." % arg)

        
    # Validate required arguments are not None
    required = ['external', 'implantable', 'env']
    for arg in required:
        if not testContext[arg]:
            raise MissingCommandLineParamError("The required command line argument '%s' is not present" % arg)
            
    # Set environment
    testContext['env'] = environment.getInstance(testContext['env'])
    
    # Set the logger level if the debug flag is on
    if testharness.getOptDebugFlag():
        logger.setLevel(_plog.DEBUG)

    # Load availability
    perseus.availability.loadExternal(testContext['external'])
    perseus.availability.loadImplantable(testContext['implantable'])
    
    # Preset the containers for copies of hardware handles
    testContext['comm'] = None
    testContext['pg'] = None
    
    logger.info('testContext created successfully: %s' % testContext)
    return testContext