Ejemplo n.º 1
0
    def execute(self, webhook: Webhook, payload: Dict) -> Result[WebhookResult, Error]:
        webhook_delivery_id = WebhookResultId.generate()
        sent_on = datetime.utcnow()
        headers = self._get_headers(webhook, webhook_delivery_id, sent_on)
        auth = self._get_auth(webhook)

        result = Request.post(
            url=webhook.post_url,
            string_info=json.dumps(payload),
            headers=headers,
            auth=auth,
        )
        return Success(
            WebhookResult.create(
                webhook, webhook_delivery_id, sent_on, headers, payload, result
            )
        )
 def failure_from_create():
     webhook_result = WebhookResultMother.success()
     return WebhookResult.create(
         webhook=WebhookMother.default(),
         webhook_result_id=WebhookResultId.generate(),
         sent_on=webhook_result.sent_on,
         request_headers={
             "X-Petisco-Event": "user_created",
             "X-Petisco-Event-Version": "1",
             "X-Petisco-Delivery": "a026531a-8512-4599-9491-81909ea8e31b",
             "X-Petisco-WebhookId": "1baa14dc-bda9-400f-b45b-428f26532f1d",
             "X-Petisco-Request-Timestamp": "2020-11-18 11:38:37.156162",
             "User-Agent": "Petisco-Hookshoot/",
             "apikey": "'b0b905d6-228f-44bf-a130-c85d7aecd765",
         },
         request_body={"payload": "ok"},
         result=Failure(TimeoutRequestError()),
     )