Commit f9508d1f authored by Claude Paroz's avatar Claude Paroz

Replaced mocked_checkout by real mock patching

parent b66fe6ff
......@@ -5,6 +5,7 @@ import tempfile
from datetime import date
from pathlib import Path
from unittest import skipUnless
from unittest.mock import patch
from django.conf import settings
from django.contrib.auth.models import User
......@@ -31,13 +32,6 @@ except ImportError:
has_translate_subtitle_support = False
def mocked_checkout(branch):
""" Replace real vcs checkout by a mocked method """
if branch.name == 'trunk2':
raise
return
class ModuleTestCase(TestCase):
fixtures = ['sample_data.json']
SYS_DEPENDENCIES = (
......@@ -102,7 +96,10 @@ class ModuleTestCase(TestCase):
br = Branch(module=mod, name='master')
with patch_shell_command() as cmds:
br.checkout()
self.assertTrue('git clone https://gitlab.gnome.org/GNOME/eog.git %s/git/eog' % settings.SCRATCHDIR in cmds)
self.assertTrue(
'git clone https://gitlab.gnome.org/GNOME/eog.git %s/git/eog' % settings.SCRATCHDIR in cmds,
"%s is not the expected 'git clone' command." % cmds[0]
)
def test_branch_methods(self):
branch = Branch(module=self.mod, name='master')
......@@ -210,11 +207,11 @@ class ModuleTestCase(TestCase):
self.assertFalse(checkout_path.exists())
def test_create_unexisting_branch(self):
""" Try to create a non-existing branch """
"""Creating a non-existing branch should raise a ValidationError."""
Branch.checkout_on_creation = True
Branch.checkout = mocked_checkout
branch = Branch(name="trunk2", module=self.mod)
self.assertRaises(ValidationError, branch.clean)
with patch('stats.tests.tests.Branch.checkout', side_effect=OSError()):
branch = Branch(name="trunk2", module=self.mod)
self.assertRaises(ValidationError, branch.clean)
def test_edit_branches_form(self):
coord = User.objects.get(username='coord')
......@@ -473,7 +470,6 @@ class TestModuleBase(TestCase):
def setUpTestData(cls):
super().setUpTestData()
Branch.checkout_on_creation = False
Branch.checkout = mocked_checkout
cls.mod = Module.objects.create(
name="testmodule", vcs_type='git',
bugs_base='https://gitlab.gnome.org/GNOME/testmodule/issues',
......
......@@ -2,6 +2,7 @@ import os
import shutil
import tempfile
from pathlib import Path
from unittest.mock import patch
from xml.dom.minidom import parseString
from django.conf import settings
......@@ -800,7 +801,8 @@ class DocsBuildingTests(TeamsAndRolesMixin, TestModuleBase):
action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "Done by translator."})
self.assertTrue(action.can_build)
self.assertIsNone(action.build_url)
response = self.client.post(reverse('action-build-help', args=[action.pk]))
with patch('stats.models.Branch.checkout'):
response = self.client.post(reverse('action-build-help', args=[action.pk]))
self.assertRedirects(
response, '/HTML/%d/index.html' % action.pk, fetch_redirect_response=False
)
......@@ -825,7 +827,8 @@ class DocsBuildingTests(TeamsAndRolesMixin, TestModuleBase):
action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "Done by translator."})
self.assertTrue(action.can_build)
self.assertIsNone(action.build_url)
response = self.client.post(reverse('action-build-help', args=[action.pk]))
with patch('stats.models.Branch.checkout'):
response = self.client.post(reverse('action-build-help', args=[action.pk]))
self.assertRedirects(
response, '/HTML/%d/index.html' % action.pk, fetch_redirect_response=False
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment