Skip to content

Commit

Permalink
Test for UpdateDocsTask.run_setup
Browse files Browse the repository at this point in the history
At this point the test is passing, but it's not running the section of
code that I want it to run :(
  • Loading branch information
humitos committed Mar 27, 2018
1 parent 8deb2cc commit 3472fc3
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion readthedocs/rtd_tests/tests/test_build_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from readthedocs.builds.models import Build, Version
from readthedocs.projects.models import Project, EmailHook, WebHook
from readthedocs.projects.tasks import send_notifications
from readthedocs.projects.tasks import send_notifications, UpdateDocsTask


class BuildNotificationsTests(TestCase):
Expand Down Expand Up @@ -46,3 +46,37 @@ def test_send_email_and_webhook__notification(self):
send_notifications(self.version.pk, self.build.pk)
mock.assert_called_once()
self.assertEqual(len(mail.outbox), 1)

@patch('readthedocs.projects.tasks.UpdateDocsTask.get_project')
@patch('readthedocs.projects.tasks.UpdateDocsTask.get_version')
@patch('readthedocs.projects.tasks.UpdateDocsTask.get_build')
@patch('readthedocs.projects.tasks.UpdateDocsTask.setup_vcs')
def test_send_email_on_generic_failure_at_setup_vcs(
self, setup_vcs, get_build, get_version, get_project):
# TODO: this should be ``_at_run_setup`` but since we depend on
# ``self.setup_env`` when an exception is raised, we need to raise the
# exception after this variable is instantiated
fixture.get(EmailHook, project=self.project)
build = fixture.get(
Build,
project=self.project,
version=self.project.versions.first(),
)
# We force an unhandled raised at ``setup_vcs``
setup_vcs.side_effect = Exception('Generic exception raised at setup')

# These mocks are needed at the beginning of the ``.run()`` method
get_build.return_value = {'id': build.pk}
get_version.return_value = self.version
get_project.return_value = self.project

update_docs = UpdateDocsTask()
result = update_docs.delay(
self.project.pk,
build_pk=build.pk,
record=False,
intersphinx=False,
)
self.assertTrue(result.successful())
self.assertFalse(result.result)
self.assertEqual(len(mail.outbox), 1)

0 comments on commit 3472fc3

Please sign in to comment.