|
11 | 11 |
|
12 | 12 | from readthedocs.builds.models import Build, Version
|
13 | 13 | from readthedocs.projects.models import Project, EmailHook, WebHook
|
14 |
| -from readthedocs.projects.tasks import send_notifications |
| 14 | +from readthedocs.projects.tasks import send_notifications, UpdateDocsTask |
15 | 15 |
|
16 | 16 |
|
17 | 17 | class BuildNotificationsTests(TestCase):
|
@@ -46,3 +46,37 @@ def test_send_email_and_webhook__notification(self):
|
46 | 46 | send_notifications(self.version.pk, self.build.pk)
|
47 | 47 | mock.assert_called_once()
|
48 | 48 | self.assertEqual(len(mail.outbox), 1)
|
| 49 | + |
| 50 | + @patch('readthedocs.projects.tasks.UpdateDocsTask.get_project') |
| 51 | + @patch('readthedocs.projects.tasks.UpdateDocsTask.get_version') |
| 52 | + @patch('readthedocs.projects.tasks.UpdateDocsTask.get_build') |
| 53 | + @patch('readthedocs.projects.tasks.UpdateDocsTask.setup_vcs') |
| 54 | + def test_send_email_on_generic_failure_at_setup_vcs( |
| 55 | + self, setup_vcs, get_build, get_version, get_project): |
| 56 | + # TODO: this should be ``_at_run_setup`` but since we depend on |
| 57 | + # ``self.setup_env`` when an exception is raised, we need to raise the |
| 58 | + # exception after this variable is instantiated |
| 59 | + fixture.get(EmailHook, project=self.project) |
| 60 | + build = fixture.get( |
| 61 | + Build, |
| 62 | + project=self.project, |
| 63 | + version=self.project.versions.first(), |
| 64 | + ) |
| 65 | + # We force an unhandled raised at ``setup_vcs`` |
| 66 | + setup_vcs.side_effect = Exception('Generic exception raised at setup') |
| 67 | + |
| 68 | + # These mocks are needed at the beginning of the ``.run()`` method |
| 69 | + get_build.return_value = {'id': build.pk} |
| 70 | + get_version.return_value = self.version |
| 71 | + get_project.return_value = self.project |
| 72 | + |
| 73 | + update_docs = UpdateDocsTask() |
| 74 | + result = update_docs.delay( |
| 75 | + self.project.pk, |
| 76 | + build_pk=build.pk, |
| 77 | + record=False, |
| 78 | + intersphinx=False, |
| 79 | + ) |
| 80 | + self.assertTrue(result.successful()) |
| 81 | + self.assertFalse(result.result) |
| 82 | + self.assertEqual(len(mail.outbox), 1) |
0 commit comments