def without_response():
     return WebhookResult.from_dict({
         "webhook_result_id": "a026531a-8512-4599-9491-81909ea8e31b",
         "webhook_id": "a026531a-8512-4599-9491-81909ea8e31b",
         "sent_on": "2020-11-18 11:38:37.156162",
         "response": None,
         "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"}',
             "body": '{"payload": "ok"}',
         },
         "is_success": True,
     })
 def without_request():
     return WebhookResult.from_dict({
         "webhook_result_id": "a026531a-8512-4599-9491-81909ea8e31b",
         "webhook_id": "a026531a-8512-4599-9491-81909ea8e31b",
         "sent_on": "2020-11-18 11:38:37.156162",
         "response": {
             "headers": None,
             "body": "",
             "status_code": 200,
             "completed_in_ms": 10,
         },
         "request": None,
         "is_success": True,
     })
 def failure():
     return WebhookResult.from_dict({
         "webhook_result_id": "a026531a-8512-4599-9491-81909ea8e31b",
         "webhook_id": "a026531a-8512-4599-9491-81909ea8e31b",
         "sent_on": "2020-11-18 11:41:18.140811",
         "response": {
             "headers": None,
             "body": None,
             "status_code": 503
         },
         "request": {
             "headers":
             '{"X-Petisco-Event": "user_created", "X-Petisco-Event-Version": "1", "X-Petisco-Delivery": "14ac35e8-0483-40b2-b308-104309b7407b", "X-Petisco-WebhookId": "8d5dc972-a6c8-4c87-8f81-a4cb61dcb6a3", "X-Petisco-Request-Timestamp": "2020-11-18 11:41:18.140811", "User-Agent": "Petisco-Hookshoot/", "apikey": "\'b0b905d6-228f-44bf-a130-c85d7aecd765"}',
             "body": '{"payload": "ok"}',
         },
         "is_success": False,
     })
Beispiel #4
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()),
     )
def test_should_serialize_and_deserialize_a_webhook_result(webhook_result):
    serialized = webhook_result.to_dict()

    deserialized_webhook_result = WebhookResult.from_dict(serialized)

    assert webhook_result == deserialized_webhook_result