11import logging
22
3+ from unittest import mock
34from django .urls import reverse
45from django .test import TestCase , Client
56from django .utils import timezone
@@ -167,10 +168,15 @@ def test_project_detail_with_scored_project(self):
167168 # Check if the context has 'disabled' as True
168169 self .assertTrue (response .context ["disabled" ])
169170
170- def test_project_submission_post_no_submissions (self ):
171+ @mock .patch ("requests.get" )
172+ def test_project_submission_post_no_submissions (self , mock_get ):
171173 """
172174 Test posting a project submission when there are no existing submissions.
173175 """
176+ mock_response = mock .Mock ()
177+ mock_response .status_code = 200
178+ mock_get .return_value = mock_response
179+
174180 self .client .login (** credentials )
175181 url = reverse (
176182 "project" , args = [self .course .slug , self .project .slug ]
@@ -207,7 +213,12 @@ def test_project_submission_post_no_submissions(self):
207213 submission .faq_contribution , data ["faq_contribution" ]
208214 )
209215
210- def test_project_submission_post_creates_enrollment (self ):
216+ @mock .patch ("requests.get" )
217+ def test_project_submission_post_creates_enrollment (self , mock_get ):
218+ mock_response = mock .Mock ()
219+ mock_response .status_code = 200
220+ mock_get .return_value = mock_response
221+
211222 self .enrollment .delete ()
212223
213224 enrollments = Enrollment .objects .filter (
@@ -224,7 +235,7 @@ def test_project_submission_post_creates_enrollment(self):
224235 )
225236
226237 data = {
227- "github_link" : "https://httpbin.org/status/200 " ,
238+ "github_link" : "https://github.com/existing/repo " ,
228239 "commit_id" : "1234567" ,
229240 "time_spent" : "2" ,
230241 "problems_comments" : "Encountered an issue with..." ,
@@ -235,18 +246,23 @@ def test_project_submission_post_creates_enrollment(self):
235246
236247 self .assertEqual (enrollments .count (), 1 )
237248
238- def test_project_submission_post_with_submissions (self ):
249+ @mock .patch ("requests.get" )
250+ def test_project_submission_post_with_submissions (self , mock_get ):
239251 """
240252 Test posting a project submission when there are existing submissions.
241253 """
254+ mock_response = mock .Mock ()
255+ mock_response .status_code = 200
256+ mock_get .return_value = mock_response
257+
242258 self .client .login (** credentials )
243259
244260 # Create an initial submission
245261 submission = ProjectSubmission .objects .create (
246262 project = self .project ,
247263 student = self .user ,
248264 enrollment = self .enrollment ,
249- github_link = "https://httpbin.org/status/200 " ,
265+ github_link = "https://github.com/existing/repo " ,
250266 commit_id = "123456a" ,
251267 )
252268
@@ -255,7 +271,7 @@ def test_project_submission_post_with_submissions(self):
255271 )
256272
257273 data = {
258- "github_link" : "https://httpbin.org/status/200 " ,
274+ "github_link" : "https://github.com/existing/repo " ,
259275 "commit_id" : "123456e" ,
260276 "time_spent" : "3" ,
261277 "problems_comments" : "No issues encountered." ,
@@ -293,7 +309,7 @@ def test_remove_project_submission(self):
293309 project = self .project ,
294310 student = self .user ,
295311 enrollment = self .enrollment ,
296- github_link = "https://httpbin.org/status/200 " ,
312+ github_link = "https://github.com/existing/repo " ,
297313 commit_id = "123456a" ,
298314 )
299315
@@ -305,18 +321,17 @@ def test_remove_project_submission(self):
305321
306322 self .assertEqual (count_sumissions , 1 )
307323
308-
309324 url = reverse (
310325 "project" , args = [self .course .slug , self .project .slug ]
311326 )
312327
313328 data = {
314- "github_link" : "https://httpbin.org/status/200 " ,
329+ "github_link" : "https://github.com/existing/repo " ,
315330 "commit_id" : "123456e" ,
316331 "time_spent" : "3" ,
317332 "problems_comments" : "No issues encountered." ,
318333 "faq_contribution" : "Helped a peer with their problem." ,
319- "action" : "delete"
334+ "action" : "delete" ,
320335 }
321336
322337 response = self .client .post (url , data )
@@ -330,7 +345,6 @@ def test_remove_project_submission(self):
330345
331346 self .assertEqual (count_sumissions , 0 )
332347
333-
334348 # this test requires a redesing of the project view
335349 # skipping for now
336350 # def test_submission_exist_post_with_error(self):
@@ -399,7 +413,7 @@ def test_project_submission_not_accepting_responses(self):
399413 )
400414
401415 data = {
402- "github_link" : "https://httpbin.org/status/200 " ,
416+ "github_link" : "https://github.com/existing/repo " ,
403417 "commit_id" : "1234567" ,
404418 "time_spent" : "2" ,
405419 "problems_comments" : "Encountered an issue with..." ,
@@ -417,11 +431,18 @@ def test_project_submission_not_accepting_responses(self):
417431
418432 self .assertEqual (submissions .count (), 0 )
419433
420- def test_project_submission_post_invalid_link_no_submission (self ):
434+ @mock .patch ("requests.get" )
435+ def test_project_submission_post_invalid_link_no_submission (
436+ self , mock_get
437+ ):
421438 """
422439 When the link is invalid and there's no submission yet,
423440 no submission is created
424441 """
442+ mock_response = mock .Mock ()
443+ mock_response .status_code = 404
444+ mock_get .return_value = mock_response
445+
425446 self .client .login (** credentials )
426447 url = reverse (
427448 "project" , args = [self .course .slug , self .project .slug ]
0 commit comments