19
19
from itertools import count
20
20
from threading import Thread
22
from mocker import MATCH, Mocker
22
from mocker import MATCH, Mocker, MockerTestCase
24
24
from twisted.internet import defer, reactor
25
25
from twisted.trial.unittest import TestCase
26
26
from twisted.spread.pb import PBClientFactory, PBServerFactory
27
27
from ubuntu_sso.main.windows import (
29
30
CredentialsManagement,
30
31
CredentialsManagementClient,
51
52
self.protocolInstance = protocol
55
class FakeDecoratedObject(object):
56
"""An object that has decorators."""
59
"""Create a new instance."""
60
super(FakeDecoratedObject, self).__init__()
64
"""Get no args passwed."""
67
def on_just_args(self, *args):
71
def on_just_kwargs(self, **kwargs):
72
"""Just get kwargs."""
75
def on_both_args(self, *args, **kwargs):
79
# pylint: disable=W0201
80
class SignalTestCase(MockerTestCase):
81
"""Test the signal decorator."""
85
super(SignalTestCase, self).setUp()
86
self.fake_object = FakeDecoratedObject()
87
self.cb = self.mocker.mock()
89
def test_no_args(self):
90
"""Test when the cb should have no args."""
91
self.fake_object.on_no_args_cb = self.cb
94
self.fake_object.on_no_args()
96
def test_just_args(self):
97
"""Test when the cb just has *args"""
100
self.fake_object.on_just_args_cb = self.cb
101
self.cb(first, second)
103
self.fake_object.on_just_args(first, second)
105
def test_just_kwargs(self):
106
"""Test when the cb just has kwargs."""
109
self.fake_object.on_just_kwargs_cb = self.cb
110
self.cb(first=first, second=second)
112
self.fake_object.on_just_kwargs(first=first, second=second)
114
def test_just_kwargs_empty(self):
115
"""Test when the cb just has kwargs."""
116
self.fake_object.on_just_kwargs_cb = self.cb
119
self.fake_object.on_just_kwargs()
121
def test_both_args(self):
122
"""Test with args and kwargs."""
125
self.fake_object.on_both_args_cb = self.cb
126
self.cb(first, second, first=first, second=second)
128
self.fake_object.on_both_args(first, second, first=first,
131
def test_both_args_no_kwargs(self):
132
"""Test with args and kwargs."""
135
self.fake_object.on_both_args_cb = self.cb
136
self.cb(first, second)
138
self.fake_object.on_both_args(first, second)
140
def test_both_args_no_args(self):
141
"""Test with args and kwargs."""
144
self.fake_object.on_both_args_cb = self.cb
145
self.cb(first=first, second=second)
147
self.fake_object.on_both_args(first=first, second=second)
148
# pylint: enable=W0201
54
151
class SSOLoginTestCase(TestCase):
55
152
"""Test the login class."""
98
195
client = SSOLoginClient(remote)
99
196
yield client.register_to_signals()
101
for signal in ['on_captcha_generated_cb',
102
'on_captcha_generation_error_cb',
103
'on_user_registered_cb',
104
'on_user_registration_error_cb',
107
'on_user_not_validated_cb',
108
'on_email_validated_cb',
109
'on_email_validation_error_cb',
110
'on_password_reset_token_sent_cb',
111
'on_password_reset_error_cb',
112
'on_password_changed_cb',
113
'on_password_change_error_cb']:
114
setattr(client, signal, self.mocker.mock())
198
for signal_name in ['on_captcha_generated_cb',
199
'on_captcha_generation_error_cb',
200
'on_user_registered_cb',
201
'on_user_registration_error_cb',
204
'on_user_not_validated_cb',
205
'on_email_validated_cb',
206
'on_email_validation_error_cb',
207
'on_password_reset_token_sent_cb',
208
'on_password_reset_error_cb',
209
'on_password_changed_cb',
210
'on_password_change_error_cb']:
211
setattr(client, signal_name, self.mocker.mock())
115
212
defer.returnValue(client)
117
214
def test_emit_captcha_generated(self):
596
693
client = SSOCredentialsClient(remote)
597
694
yield client.register_to_signals()
599
for signal in ['on_authorization_denied_cb',
600
'on_credentials_found_cb',
601
'on_credentials_error_cb']:
602
setattr(client, signal, self.mocker.mock())
696
for signal_name in ['on_authorization_denied_cb',
697
'on_credentials_found_cb',
698
'on_credentials_error_cb']:
699
setattr(client, signal_name, self.mocker.mock())
603
700
defer.returnValue(client)
605
702
def test_emit_authorization_denied(self):
850
947
client = CredentialsManagementClient(remote)
851
948
yield client.register_to_signals()
853
for signal in ['on_authorization_denied_cb',
854
'on_credentials_found_cb',
855
'on_credentials_not_found_cb',
856
'on_credentials_cleared_cb',
857
'on_credentials_stored_cb',
858
'on_credentials_error_cb']:
859
setattr(client, signal, self.mocker.mock())
950
for signal_name in ['on_authorization_denied_cb',
951
'on_credentials_found_cb',
952
'on_credentials_not_found_cb',
953
'on_credentials_cleared_cb',
954
'on_credentials_stored_cb',
955
'on_credentials_error_cb']:
956
setattr(client, signal_name, self.mocker.mock())
860
957
defer.returnValue(client)
862
959
def test_shutdown(self):