Example #1
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)        
Example #2
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.")
Example #3
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)
Example #4
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