1+ import logging
2+
13import pytest
24from core .models import DiscordMessage , Webhook
3- from core .tasks import process_internal_webhook , process_webhook
5+ from core .tasks import process_github_webhook , process_internal_webhook , process_webhook
46from django_tasks .task import ResultStatus
57
68
@@ -31,7 +33,7 @@ def test_process_internal_webhook_fails_if_incorrect_source():
3133
3234
3335@pytest .mark .django_db
34- def test_process_webhook_fails_if_unsupported_source (caplog ):
36+ def test_process_webhook_fails_if_unsupported_source ():
3537 wh = Webhook .objects .create (source = "asdf" , event = "test1" , content = {})
3638
3739 # If the task is enqueued the errors are not emited.
@@ -41,3 +43,23 @@ def test_process_webhook_fails_if_unsupported_source(caplog):
4143 assert result .status == ResultStatus .FAILED
4244 assert result ._exception_class == ValueError
4345 assert result .traceback .endswith ("ValueError: Unsupported source asdf\n " )
46+
47+
48+ @pytest .mark .django_db
49+ def test_process_github_webhook_logs_unsupported_event (caplog ):
50+ wh = Webhook .objects .create (
51+ source = "github" ,
52+ event = "" ,
53+ meta = {"X-Github-Event" : "testrandom" },
54+ content = {},
55+ )
56+
57+ with caplog .at_level (logging .INFO ):
58+ process_github_webhook (wh )
59+
60+ assert len (caplog .records ) == 1
61+ assert caplog .records [0 ].levelname == "INFO"
62+ assert (
63+ caplog .records [0 ].message
64+ == f"Not processing Github Webhook { wh .uuid } : Event `testrandom` not supported"
65+ )
0 commit comments