1
- # -*- coding: utf-8 -*-
2
1
"""Notifications sent after build is completed."""
3
2
4
3
import json
8
7
from django .test import TestCase
9
8
from unittest .mock import patch
10
9
10
+ from readthedocs .builds .constants import EXTERNAL
11
11
from readthedocs .builds .models import Build , Version
12
12
from readthedocs .projects .forms import WebHookForm
13
13
from readthedocs .projects .models import EmailHook , Project , WebHook
@@ -19,7 +19,7 @@ def setUp(self):
19
19
self .project = fixture .get (Project )
20
20
self .version = fixture .get (Version , project = self .project )
21
21
self .build = fixture .get (Build , version = self .version )
22
-
22
+
23
23
@patch ('readthedocs.builds.managers.log' )
24
24
def test_send_notification_none_if_wrong_version_pk (self , mock_logger ):
25
25
self .assertFalse (Version .objects .filter (pk = 345343 ).exists ())
@@ -40,6 +40,18 @@ def test_send_webhook_notification(self):
40
40
41
41
self .assertEqual (len (mail .outbox ), 0 )
42
42
43
+ def test_dont_send_webhook_notifications_for_external_versions (self ):
44
+ fixture .get (WebHook , project = self .project )
45
+ self .version .type = EXTERNAL
46
+ self .version .save ()
47
+
48
+ with patch ('readthedocs.projects.tasks.requests.post' ) as mock :
49
+ mock .return_value = None
50
+ send_notifications (self .version .pk , self .build .pk )
51
+ mock .assert_not_called ()
52
+
53
+ self .assertEqual (len (mail .outbox ), 0 )
54
+
43
55
def test_send_webhook_notification_has_content_type_header (self ):
44
56
hook = fixture .get (WebHook , project = self .project )
45
57
data = json .dumps ({
@@ -67,6 +79,14 @@ def test_send_email_notification(self):
67
79
send_notifications (self .version .pk , self .build .pk , email = True )
68
80
self .assertEqual (len (mail .outbox ), 1 )
69
81
82
+ def test_dont_send_email_notifications_for_external_versions (self ):
83
+ fixture .get (EmailHook , project = self .project )
84
+ self .version .type = EXTERNAL
85
+ self .version .save ()
86
+
87
+ send_notifications (self .version .pk , self .build .pk , email = True )
88
+ self .assertEqual (len (mail .outbox ), 0 )
89
+
70
90
def test_send_email_and_webhook__notification (self ):
71
91
fixture .get (EmailHook , project = self .project )
72
92
fixture .get (WebHook , project = self .project )
0 commit comments