コード例 #1
0
    def test_trigger_dag(self):
        with self.app.test_client() as c:
            url_template = '/api/experimental/dags/{}/dag_runs'
            response = c.post(url_template.format('example_bash_operator'),
                              data=json.dumps(
                                  dict(run_id='my_run' +
                                       datetime.now().isoformat())),
                              content_type="application/json")
            self.assertEqual(401, response.status_code)
            try:
                callable_path = conf.get('core', 'hostname_callable')
            except (AirflowConfigException, XToolConfigException):
                callable_path = None
            response.url = 'http://{}'.format(get_hostname(callable_path))

            class Request():
                headers = {}

            response.request = Request()
            response.content = ''
            response.raw = mock.MagicMock()
            response.connection = mock.MagicMock()
            response.connection.send = mock.MagicMock()

            # disable mutual authentication for testing
            client_auth.mutual_authentication = 3

            # case can influence the results
            try:
                callable_path = conf.get('core', 'hostname_callable')
            except (AirflowConfigException, XToolConfigException):
                callable_path = None
            client_auth.hostname_override = get_hostname(callable_path)

            client_auth.handle_response(response)
            self.assertIn('Authorization', response.request.headers)

            response2 = c.post(url_template.format('example_bash_operator'),
                               data=json.dumps(
                                   dict(run_id='my_run' +
                                        datetime.now().isoformat())),
                               content_type="application/json",
                               headers=response.request.headers)
            self.assertEqual(200, response2.status_code)
コード例 #2
0
    def test_trigger_dag(self):
        with self.app.test_client() as c:
            url_template = '/api/experimental/dags/{}/dag_runs'
            response = c.post(
                url_template.format('example_bash_operator'),
                data=json.dumps(dict(run_id='my_run' + datetime.now().isoformat())),
                content_type="application/json"
            )
            self.assertEqual(401, response.status_code)

            response.url = 'http://{}'.format(get_hostname())

            class Request():
                headers = {}

            response.request = Request()
            response.content = ''
            response.raw = mock.MagicMock()
            response.connection = mock.MagicMock()
            response.connection.send = mock.MagicMock()

            # disable mutual authentication for testing
            client_auth.mutual_authentication = 3

            # case can influence the results
            client_auth.hostname_override = get_hostname()

            client_auth.handle_response(response)
            self.assertIn('Authorization', response.request.headers)

            response2 = c.post(
                url_template.format('example_bash_operator'),
                data=json.dumps(dict(run_id='my_run' + datetime.now().isoformat())),
                content_type="application/json",
                headers=response.request.headers
            )
            self.assertEqual(200, response2.status_code)