Skip to content

Commit 3472fc3

Browse files
committed
Test for UpdateDocsTask.run_setup
At this point the test is passing, but it's not running the section of code that I want it to run :(
1 parent 8deb2cc commit 3472fc3

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

readthedocs/rtd_tests/tests/test_build_notifications.py

+35-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from readthedocs.builds.models import Build, Version
1313
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
1515

1616

1717
class BuildNotificationsTests(TestCase):
@@ -46,3 +46,37 @@ def test_send_email_and_webhook__notification(self):
4646
send_notifications(self.version.pk, self.build.pk)
4747
mock.assert_called_once()
4848
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

Comments
 (0)