From f6007104948e21d97e09e608245f7217dde09bdb Mon Sep 17 00:00:00 2001 From: Juan Funez Date: Fri, 6 Jun 2014 01:01:18 -0300 Subject: [PATCH] Melhora dos tests para evitar request ao balaio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [doubles.py] - adiciono uma classe double, pra simular que o balaio esta offline [tests_pages.py] - nos tests que fazem get do notice_detail, aonde é invocada a BalaioAPI, faço um replace com o novo double: ``doubles.BalaioAPIDoubleDisabled`` para simular o balaio offline --- scielomanager/articletrack/tests/doubles.py | 8 ++++++++ .../articletrack/tests/tests_pages.py | 20 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/scielomanager/articletrack/tests/doubles.py b/scielomanager/articletrack/tests/doubles.py index 9c458297..5d6379d8 100644 --- a/scielomanager/articletrack/tests/doubles.py +++ b/scielomanager/articletrack/tests/doubles.py @@ -39,3 +39,11 @@ def list_files_members_by_attempt(self, attempt_id): def get_xml_uri(self, attempt_id, target_name): tests_xmls_dirs = path.abspath(path.join(path.dirname(__file__), 'xml_tests_files')) return "file://%s" % path.join(tests_xmls_dirs, "valid.xml") + + +class BalaioAPIDoubleDisabled(BalaioAPI): + def is_up(self): + return False + + def list_files_members_by_attempt(self, attempt_id): + raise ValueError diff --git a/scielomanager/articletrack/tests/tests_pages.py b/scielomanager/articletrack/tests/tests_pages.py index 726831aa..608fc0c7 100644 --- a/scielomanager/articletrack/tests/tests_pages.py +++ b/scielomanager/articletrack/tests/tests_pages.py @@ -27,7 +27,7 @@ def _makePermission(perm, model, app_label='articletrack'): return auth_models.Permission.objects.get(codename=perm, content_type=ct) -class CheckinListTests(WebTest): +class CheckinListTests(WebTest, mocker.MockerTestCase): def setUp(self): self.user = auth.UserF(is_active=True) @@ -186,6 +186,12 @@ def test_status_code_notice_list(self): self._addWaffleFlag() notice = self._makeOne() + # to avoid making a request will replace it with a double + balaio = self.mocker.replace('articletrack.balaio.BalaioAPI') + balaio() + self.mocker.result(doubles.BalaioAPIDoubleDisabled()) + self.mocker.replay() + response = self.app.get(reverse('notice_detail', args=[notice.checkin.pk]), user=self.user) @@ -203,6 +209,12 @@ def test_notice_list_with_itens(self): self._addWaffleFlag() notice = self._makeOne() + # to avoid making a request will replace it with a double + balaio = self.mocker.replace('articletrack.balaio.BalaioAPI') + balaio() + self.mocker.result(doubles.BalaioAPIDoubleDisabled()) + self.mocker.replay() + response = self.app.get(reverse('notice_detail', args=[notice.checkin.pk]), user=self.user) @@ -212,6 +224,12 @@ def test_notice_list_must_have_link_to_checkin_list(self): self._addWaffleFlag() notice = self._makeOne() + # to avoid making a request will replace it with a double + balaio = self.mocker.replace('articletrack.balaio.BalaioAPI') + balaio() + self.mocker.result(doubles.BalaioAPIDoubleDisabled()) + self.mocker.replay() + response = self.app.get(reverse('notice_detail', args=[notice.checkin.pk]), user=self.user)