1
+ import logging
2
+
1
3
import pytest
2
4
from 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
4
6
from django_tasks .task import ResultStatus
5
7
6
8
@@ -31,7 +33,7 @@ def test_process_internal_webhook_fails_if_incorrect_source():
31
33
32
34
33
35
@pytest .mark .django_db
34
- def test_process_webhook_fails_if_unsupported_source (caplog ):
36
+ def test_process_webhook_fails_if_unsupported_source ():
35
37
wh = Webhook .objects .create (source = "asdf" , event = "test1" , content = {})
36
38
37
39
# If the task is enqueued the errors are not emited.
@@ -41,3 +43,23 @@ def test_process_webhook_fails_if_unsupported_source(caplog):
41
43
assert result .status == ResultStatus .FAILED
42
44
assert result ._exception_class == ValueError
43
45
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