Exemplo n.º 1
0
    def test_process_existing_query_string(self, request_mock):
        resources = [{
            "name": "test1",
            "value": "test_value"
        }, {
            "name": "test2",
            "value": "test_value"
        }]

        data = {
            "url": "http://foo.com?existing=test",
            "query-params": {
                "foo": "resource.name"
            }
        }

        wh = Webhook(data=data, manager=self._get_manager())
        wh.process(resources)

        req1 = request_mock.call_args_list[0][1]
        req2 = request_mock.call_args_list[1][1]

        self.assertIn("existing=test", req1['url'])
        self.assertIn("foo=test1", req1['url'])
        self.assertIn("existing=test", req2['url'])
        self.assertIn("foo=test2", req2['url'])
Exemplo n.º 2
0
    def test_process_batch_body(self, request_mock):
        resources = [{"name": "test_name", "value": "test_value"}]

        data = {
            "url": "http://foo.com",
            "batch": True,
            "body": "resources[].name",
            "body-size": 10,
            "headers": {
                "test": "'header'"
            },
            "query-params": {
                "foo": "resources[0].name"
            }
        }

        wh = Webhook(data=data, manager=self._get_manager())
        wh.process(resources)
        req = request_mock.call_args[1]

        self.assertEqual("http://foo.com?foo=test_name", req['url'])
        self.assertEqual("POST", req['method'])
        self.assertEqual(b'[\n"test_name"\n]', req['body'])
        self.assertEqual({
            "test": "header",
            "Content-Type": "application/json"
        }, req['headers'])
Exemplo n.º 3
0
    def test_process_policy_metadata(self, request_mock):
        resources = [
            {
                "name": "test1",
                "value": "test_value"
            },
            {
                "name": "test2",
                "value": "test_value"
            }
        ]

        data = {
            "url": "http://foo.com",
            "query-params": {
                "policy": "policy.name"
            }
        }

        wh = Webhook(data=data, manager=self._get_manager())
        wh.process(resources)
        req1 = request_mock.call_args_list[0][1]
        req2 = request_mock.call_args_list[1][1]

        self.assertEqual("http://foo.com?policy=webhook_policy", req1['url'])
        self.assertEqual("http://foo.com?policy=webhook_policy", req2['url'])
Exemplo n.º 4
0
    def test_process_batch(self, request_mock):
        resources = [
            {
                "name": "test_name",
                "value": "test_value"
            },
            {
                "name": "test_name",
                "value": "test_value"
            },
            {
                "name": "test_name",
                "value": "test_value"
            },
            {
                "name": "test_name",
                "value": "test_value"
            },
            {
                "name": "test_name",
                "value": "test_value"
            }
        ]

        data = {
            "url": "http://foo.com",
            "batch": True,
            "batch-size": 2,
            "query-params": {
                "foo": "resources[0].name"
            }
        }

        wh = Webhook(data=data, manager=self._get_manager())
        wh.process(resources)
        req = request_mock.call_args[1]

        # 5 resources with max batch size 2 == 3 calls
        self.assertEqual(3, len(request_mock.call_args_list))

        # Check out one of the calls in detail
        self.assertEqual("http://foo.com?foo=test_name", req['url'])
        self.assertEqual("POST", req['method'])
        self.assertEqual({}, req['headers'])
Exemplo n.º 5
0
    def test_process_with_http_proxy(self, pool_request_mock,
                                     proxy_request_mock):
        with mock.patch.dict(
                os.environ,
            {'HTTP_PROXY': 'http://mock.http.proxy.server:8000'},
                clear=True):
            resources = [{"name": "test_name", "value": "test_value"}]

            data = {"url": "http://foo.com"}

            wh = Webhook(data=data, manager=self._get_manager())
            wh.process(resources)
            proxy_req = proxy_request_mock.call_args[1]

            self.assertEqual("http://foo.com", proxy_req['url'])
            self.assertEqual("POST", proxy_req['method'])

            self.assertEqual(1, proxy_request_mock.call_count)
            self.assertEqual(0, pool_request_mock.call_count)
Exemplo n.º 6
0
    def test_process_date_serializer(self, request_mock):
        current = datetime.datetime.utcnow()
        resources = [
            {
                "name": "test1",
                "value": current
            },
        ]

        data = {
            "url": "http://foo.com",
            "body": "resources[]",
            'batch': True,
        }

        wh = Webhook(data=data, manager=self._get_manager())
        wh.process(resources)
        req1 = request_mock.call_args_list[0][1]
        self.assertEqual(
            json.loads(req1['body'])[0]['value'], current.isoformat())