5
5
from django .test import TestCase
6
6
from django .test .utils import override_settings
7
7
8
+ from django_dynamic_fixture import get
9
+
10
+ from readthedocs .builds .constants import EXTERNAL , BUILD_STATUS_SUCCESS
11
+ from readthedocs .builds .models import Version , Build
8
12
from readthedocs .oauth .models import RemoteOrganization , RemoteRepository
9
13
from readthedocs .oauth .services import (
10
14
BitbucketService ,
@@ -26,6 +30,10 @@ def setUp(self):
26
30
self .org = RemoteOrganization .objects .create (slug = 'rtfd' , json = '' )
27
31
self .privacy = self .project .version_privacy_level
28
32
self .service = GitHubService (user = self .user , account = None )
33
+ self .external_version = get (Version , project = self .project , type = EXTERNAL )
34
+ self .external_build = get (
35
+ Build , project = self .project , version = self .external_version
36
+ )
29
37
30
38
def test_make_project_pass (self ):
31
39
repo_json = {
@@ -142,6 +150,51 @@ def test_multiple_users_same_repo(self):
142
150
self .assertEqual (github_project , github_project_5 )
143
151
self .assertEqual (github_project_2 , github_project_6 )
144
152
153
+ @mock .patch ('readthedocs.oauth.services.github.log' )
154
+ @mock .patch ('readthedocs.oauth.services.github.GitHubService.get_session' )
155
+ def test_send_build_status_successful (self , session , mock_logger ):
156
+ session ().post .return_value .status_code = 201
157
+ success = self .service .send_build_status (
158
+ self .external_build ,
159
+ BUILD_STATUS_SUCCESS
160
+ )
161
+
162
+ self .assertTrue (success )
163
+ mock_logger .info .assert_called_with (
164
+ 'GitHub commit status for project: %s' ,
165
+ self .project
166
+ )
167
+
168
+ @mock .patch ('readthedocs.oauth.services.github.log' )
169
+ @mock .patch ('readthedocs.oauth.services.github.GitHubService.get_session' )
170
+ def test_send_build_status_404_error (self , session , mock_logger ):
171
+ session ().post .return_value .status_code = 404
172
+ success = self .service .send_build_status (
173
+ self .external_build ,
174
+ BUILD_STATUS_SUCCESS
175
+ )
176
+
177
+ self .assertFalse (success )
178
+ mock_logger .info .assert_called_with (
179
+ 'GitHub project does not exist or user does not have '
180
+ 'permissions: project=%s' ,
181
+ self .project
182
+ )
183
+
184
+ @mock .patch ('readthedocs.oauth.services.github.log' )
185
+ @mock .patch ('readthedocs.oauth.services.github.GitHubService.get_session' )
186
+ def test_send_build_status_value_error (self , session , mock_logger ):
187
+ session ().post .side_effect = ValueError
188
+ success = self .service .send_build_status (
189
+ self .external_build , BUILD_STATUS_SUCCESS
190
+ )
191
+
192
+ self .assertFalse (success )
193
+ mock_logger .exception .assert_called_with (
194
+ 'GitHub commit status creation failed for project: %s' ,
195
+ self .project ,
196
+ )
197
+
145
198
@override_settings (DEFAULT_PRIVACY_LEVEL = 'private' )
146
199
def test_make_private_project (self ):
147
200
"""
0 commit comments