27 lines
900 B
Python
27 lines
900 B
Python
import pytest
|
|
|
|
from infrasynth.webhooks.inbound.handlers import BaseInboundHandler
|
|
|
|
|
|
class _ConcreteHandler(BaseInboundHandler):
|
|
def verify(self, payload, headers, secret):
|
|
return payload.get("token") == secret
|
|
|
|
def process(self, event_type, payload):
|
|
return {"handled": event_type, "items": len(payload)}
|
|
|
|
|
|
class TestBaseInboundHandler:
|
|
def test_is_abstract(self):
|
|
with pytest.raises(TypeError):
|
|
BaseInboundHandler()
|
|
|
|
def test_concrete_handler_verify(self):
|
|
handler = _ConcreteHandler()
|
|
assert handler.verify({"token": "abc"}, {}, "abc") is True
|
|
assert handler.verify({"token": "wrong"}, {}, "abc") is False
|
|
|
|
def test_concrete_handler_process(self):
|
|
handler = _ConcreteHandler()
|
|
result = handler.process("issue.opened", {"a": 1, "b": 2})
|
|
assert result == {"handled": "issue.opened", "items": 2}
|