711
718
"""Simulate to add the message to the label as SetupAccount do."""
721
class FakeSetupAccountView(FakeView):
727
captcha_refresh_executed = False
728
captcha_refreshing_value = False
730
def on_captcha_refresh_complete(self):
731
"""Fake the call to refresh finished."""
732
self.captcha_refresh_executed = True
734
def on_captcha_refreshing(self):
735
"""Fake the call to refreshing."""
736
self.captcha_refreshing_value = True
738
def fake_open(self, filename):
739
"""Fake open for Image."""
742
# pylint: disable=W0622
743
def save(self, io, format):
744
"""Fake save for Image."""
745
# pylint: enable=W0622
748
class FakeControllerForCaptcha(object):
750
"""Fake controller to test refresh_captcha method."""
753
"""Initialize FakeControllerForCaptcha."""
754
self.callback_error = False
756
def generate_captcha(self, *args):
757
"""Fake generate deferred for captcha."""
760
# pylint: disable=C0103
761
def addErrback(self, call):
762
"""Fake addErrback."""
763
self.callback_error = call is not None
764
# pylint: enable=C0103
714
767
class FakeEmailVerificationView(FakePageUiStyle):
715
768
"""Fake EmailVerification Page."""
721
774
self.next_button = self
777
class SetupAccountControllerCaptchaTest(BaseTestCase):
778
"""Tests for SetupAccountController, but without Mocker."""
781
"""Set the different tests."""
782
super(SetupAccountControllerCaptchaTest, self).setUp()
783
self.message_box = FakeMessageBox()
784
self.controller = SetUpAccountController(message_box=self.message_box)
785
self.patch(self.controller, 'view', FakeSetupAccountView())
786
self.fake_backend = FakeControllerForCaptcha()
787
self.patch(self.controller, 'backend', self.fake_backend)
789
def test_refresh_captcha(self):
790
"""Test the Refresh Captcha function."""
791
self.assertFalse(self.controller.view.captcha_refreshing_value)
792
self.controller._refresh_captcha()
793
self.assertTrue(self.controller.view.captcha_refreshing_value)
794
self.assertTrue(self.fake_backend.callback_error)
724
797
class SetupAccountControllerValidationTest(BaseTestCase):
725
798
"""Tests for SetupAccountController, but without Mocker."""
730
803
self.message_box = FakeMessageBox()
731
804
self.controller = SetUpAccountController(message_box=self.message_box)
732
805
self.patch(self.controller, '_refresh_captcha', self._set_called)
733
self.patch(self.controller, 'view', FakeView())
806
self.patch(self.controller, 'view', FakeSetupAccountView())
735
808
def test_on_user_registration_refresh_captcha(self):
736
809
"""If there is a user reg. error, captcha should refresh."""
764
837
expected = (('', self.controller.view), {})
765
838
self.assertEqual(self.message_box.critical_args, expected)
840
def test_on_captcha_generated(self):
841
"""Test if the method that shows the overlay is executed."""
842
self.patch(Image, "open", self.controller.view.fake_open)
843
self.assertFalse(self.controller.view.captcha_refresh_executed)
844
self.controller.on_captcha_generated('app_name', 'captcha_id')
845
self.assertTrue(self.controller.view.captcha_refresh_executed)
847
def test_on_captcha_generation_error(self):
848
"""Test if the method that hides the overlay is executed."""
849
self.assertFalse(self.controller.view.captcha_refresh_executed)
850
self.controller.on_captcha_generation_error({})
851
self.assertTrue(self.controller.view.captcha_refresh_executed)
768
854
class EmailVerificationControllerTestCase(MockerTestCase):
769
855
"""Test the controller."""