def test__variable__variable_does_not_exist__fail(self): self.suite.keywords.append(Keyword(name='Set service context to node_1', type='setup')) tests = [ Keyword(name=u'Variable PTH: contains /usr/bin'), ] with patch('VnfValidator.orchestrator.DockerController.get_env', return_value=["PATH=/usr/bin"]): run_keyword_tests(test_instance=self, tests=tests, expected_result=Result.FAIL)
def test__port__invalid_value__fail(self): self.suite.keywords.append(Keyword(name='Set network context to node_1', type='setup')) tests = [ Keyword(name=u'Port 80: state is openedd'), ] with patch('ValidationTargets.port.exc.SetupError.ROBOT_EXIT_ON_FAILURE', False): run_keyword_tests(test_instance=self, setup=None, tests=tests, expected_result=Result.FAIL, expected_message=u'ValidationError: Value')
def test__variable__invalid_value__fail(self): self.suite.keywords.append(Keyword(name='Set service context to node_1', type='setup')) tests = [ Keyword(name=u'Variable ABC: is ""'), ] with patch('ValidationTargets.variable.exc.SetupError.ROBOT_EXIT_ON_FAILURE', False): run_keyword_tests(test_instance=self, setup=None, tests=tests, expected_result=Result.FAIL, expected_message=u'ValidationError: Value')
def test__port__pass(self): self.suite.keywords.append(Keyword(name='Set network context to node_1', type='setup')) tests = [ Keyword(name=u'Port 80: state is open'), Keyword(name=u'Port 80/TCP: state is open'), Keyword(name=u'Port 80/UDP: state is open'), Keyword(name=u'Port 80/UDP: state is closed'), ] run_keyword_tests(test_instance=self, tests=tests, expected_result=Result.PASS)
def run_keyword(self,name,*args): """ because the name of the keyword to execute is given as an argument is can be a vairbale and thus set dynamically,e.g.form a return value of another keyword or the command line """ if not isinstance(name,basestring): raise RuntimeError('Keyword name must be a string') kw = Keyword(name,list(args)) return kw.run(self._context)
def test__set_context__pass(self): tests = [ Keyword(name=u'Set application context to node_1'), Keyword(name=u'Set network context to node_1'), Keyword(name=u'Set node context to node_1'), Keyword(name=u'Set service context to node_1'), ] with patch('DockerController.DockerController') as mock_controller: mock_controller = MagicMock(DockerController) run_keyword_tests(test_instance=self, tests=tests, expected_result=Result.PASS)
def call_p4p(self, p1, p2): kw = Keyword(p1, args=[]) words = kw.run(EXECUTION_CONTEXTS.current) pw = "%s check" % p2 kw = Keyword(pw, args=[words]) result = kw.run(EXECUTION_CONTEXTS.current) kw = Keyword("Should be equal", args=["OK", result]) return kw.run(EXECUTION_CONTEXTS.current)
def run_keyword(self, name, *args): """, """ import robot.output as output from robot.running import Keyword, NAMESPACES kw = Keyword(name, args) def get_name(handler_name, variables): return "RDB.%s" % handler_name kw._get_name = get_name if self._exit_code > 0: sys.exit(self._exit_code) return kw.run(output.OUTPUT, NAMESPACES.current)
def test__set_context__wrong_context_type__fail(self): test = self.suite.tests.create(name=u'Test context') test.keywords.append(Keyword(name=u'Set app context to bla')) result = self.suite.run() self.assertIn("Invalid context given", result.suite.tests[0].message)
def wrapped_f(q, *args, **kwargs): ''' Calls the decorated function and puts the result in a queue ''' try: context = EXECUTION_CONTEXTS.current runner = context.get_runner(keyword) ret = runner.run(Keyword(name=keyword, args=args), context) q.put(ret) except Exception as ex: print(ex)
def test__variable__pass(self): self.suite.keywords.append(Keyword(name='Set service context to node_1', type='setup')) tests = [ Keyword(name=u'Variable PATH: contains /usr/bin'), Keyword(name=u'Variable PATH: is /usr/bin'), Keyword(name=u'Variable PATH: is "/usr/bin"'), Keyword(name=u'Variable PATH: is \'/usr/bin\''), Keyword(name=u'Variable NGINX_VERSION: contains 2.0.0beta1'), Keyword(name=u'Variable NGINX_VERSION: is 2.0.0beta1'), ] with patch('VnfValidator.orchestrator._get_controller') as mock: mock.return_value = MagicMock(DockerController) mock.return_value.get_env.return_value = ["PATH=/usr/bin", "NGINX_VERSION=2.0.0beta1"] run_keyword_tests(test_instance=self, tests=tests, expected_result=Result.PASS)
def call_p3p(self, p1, p2): kw = Keyword(p1, args=[]) user, passwd = kw.run(EXECUTION_CONTEXTS.current) pw = "Enter Credentials" kw = Keyword(pw, args=[user, passwd]) return kw.run(EXECUTION_CONTEXTS.current)
def call_p6(self, p1): pw = "%s teardown" % p1 kw = Keyword(pw, args=[]) return kw.run(EXECUTION_CONTEXTS.current)
def call_p2(self, p1): pw = "%s setup" % p1 kw = Keyword(pw, args=[]) return kw.run(EXECUTION_CONTEXTS.current)
def call_p1(self, p1): kw = Keyword(p1, args=[]) return kw.run(EXECUTION_CONTEXTS.current)