Example #1
0
    def test_Step_run_post(self, post):
        class ResponseX():
            status_code = 200
            content = b'ok'

        resp = ResponseX()
        post.return_value = resp
        step = Step(url='http://test.com', method='post')
        with self.assertLogs('actions', level='INFO'):
            step.run()
Example #2
0
 def test_Step_data(self):
     data = {
         'token': '%action1.step1.token%',
         'action': '%action2.step1.action%',
         'control': True,
     }
     expect = {
         'token': '1234',
         'action': 'add',
         'control': True,
     }
     step1 = Step(url='http://test.com', data=data, name='step1')
     step1.results = {'token': '1234'}
     action1 = Action([step1], 'action1')
     step2 = Step(url='/', name='step1')
     step2.results = {'action': 'add'}
     action2 = Action([step2], 'action2')
     Actions([action1, action2])
     self.assertEqual(step1.data, expect)
Example #3
0
 def test_Step_get_variable(self):
     # add step1
     step1 = Step(url='http://test.com', name='step1')
     step1.results = {'rc': '_rc1'}
     # should not be found withoud connection with action
     self.assertEqual(step1.get_variable('action1.step1.rc'), 'None')
     action1 = Action([step1], 'action1')
     # should be found after connection
     self.assertEqual(step1.get_variable('action1.step1.rc'), '_rc1')
     # add step2
     step2 = Step(url='http://test.com/auth', name='step1')
     step2.results = {'rc': '_rc2'}
     action2 = Action([step2], 'action2')
     # should not be found for step1 and found for step2
     self.assertEqual(step1.get_variable('action2.step1.rc'), 'None')
     self.assertEqual(step2.get_variable('action2.step1.rc'), '_rc2')
     Actions([action1, action2])
     # should be found for step1 after connect action with parent
     self.assertEqual(step1.get_variable('action2.step1.rc'), '_rc2')
Example #4
0
 def test_Step_get_value(self):
     step = Step(url='http://test.com')
     step.results = {
         'key1': 'value1',
         'key2': {
             'key3': 'value3',
             'key4': {
                 'key5': 'value5'
             }
         }
     }
     self.assertEqual(step.get_value('key1'.split('.')), 'value1')
     self.assertEqual(step.get_value('key2.key3'.split('.')), 'value3')
     self.assertEqual(step.get_value('key2.key4'.split('.')), {'key5': 'value5'})
     self.assertEqual(step.get_value('key2.key4.key5'.split('.')), 'value5')
     self.assertIsNone(step.get_value('key6'.split('.')))
Example #5
0
    def test_Step_run_get(self, get):
        class ResponseX():
            status_code = 200
            content = b'ok'

        resp = ResponseX()
        get.return_value = resp
        step = Step(url='http://test.com', method='get')
        # check only status code
        with self.assertLogs('actions', level='INFO'):
            step.run()
        # set expected_data and test
        resp.content = b'{"test": true}'
        step.expected_data = {'test': True}
        with self.assertLogs('actions', level='INFO'):
            step.run()
        # empty content
        resp.content = b''
        with self.assertLogs('actions') as cm:
            step.run()
            self.assertEqual(cm.output, [
                'ERROR:actions:response data "None" is not equal "{\'test\': True}"',
                'WARNING:actions:None GET http://test.com'
            ])
        # set wrong params and test
        resp.status_code = 404
        resp.content = b'{"test": false}'
        with self.assertLogs('actions') as cm:
            step.run()
            self.assertEqual(cm.output, [
                'ERROR:actions:status code 404 not equal 200',
                'ERROR:actions:response data "{\'test\': False}" is not equal "{\'test\': True}"',
                'WARNING:actions:None GET http://test.com'
            ])
        # skip errors
        step.skip_erros = True
        with self.assertLogs('actions', level='WARNING'):
            step.run()
Example #6
0
 def test_Step_url(self):
     step = Step(url='http://test.com?token=%action1.step1.token%', name='step1')
     step.results = {'token': '1234'}
     Action([step], 'action1')
     self.assertEqual(step.url, 'http://test.com?token=1234')