Skip to content

Commit

Permalink
Melhora dos tests para evitar request ao balaio
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
jfunez committed Jun 6, 2014
1 parent 211cb35 commit f600710
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions scielomanager/articletrack/tests/doubles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 19 additions & 1 deletion scielomanager/articletrack/tests/tests_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down

0 comments on commit f600710

Please sign in to comment.