~mvo/ubuntu-sso-client/strawman-lp711413

« back to all changes in this revision

Viewing changes to ubuntu_sso/main/tests/test_windows.py

  • Committer: Manuel de la Pena
  • Date: 2011-06-16 17:05:26 UTC
  • mfrom: (719 ubuntu-sso-client)
  • mto: This revision was merged to the branch mainline in revision 721.
  • Revision ID: mandel@themacaque.com-20110616170526-pvdvfhin2t2ppbxl
Merged with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from itertools import count
20
20
from threading import Thread
21
21
 
22
 
from mocker import MATCH, Mocker
 
22
from mocker import MATCH, Mocker, MockerTestCase
23
23
 
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 (
28
28
    blocking,
 
29
    signal,
29
30
    CredentialsManagement,
30
31
    CredentialsManagementClient,
31
32
    SSOCredentials,
51
52
        self.protocolInstance = protocol
52
53
 
53
54
 
 
55
class FakeDecoratedObject(object):
 
56
    """An object that has decorators."""
 
57
 
 
58
    def __init__(self):
 
59
        """Create a new instance."""
 
60
        super(FakeDecoratedObject, self).__init__()
 
61
 
 
62
    @signal
 
63
    def on_no_args(self):
 
64
        """Get no args passwed."""
 
65
 
 
66
    @signal
 
67
    def on_just_args(self, *args):
 
68
        """Just get args."""
 
69
 
 
70
    @signal
 
71
    def on_just_kwargs(self, **kwargs):
 
72
        """Just get kwargs."""
 
73
 
 
74
    @signal
 
75
    def on_both_args(self, *args, **kwargs):
 
76
        """Both args."""
 
77
 
 
78
 
 
79
# pylint: disable=W0201
 
80
class SignalTestCase(MockerTestCase):
 
81
    """Test the signal decorator."""
 
82
 
 
83
    def setUp(self):
 
84
        """Set the tests."""
 
85
        super(SignalTestCase, self).setUp()
 
86
        self.fake_object = FakeDecoratedObject()
 
87
        self.cb = self.mocker.mock()
 
88
 
 
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
 
92
        self.cb()
 
93
        self.mocker.replay()
 
94
        self.fake_object.on_no_args()
 
95
 
 
96
    def test_just_args(self):
 
97
        """Test when the cb just has *args"""
 
98
        first = 'first'
 
99
        second = 'second'
 
100
        self.fake_object.on_just_args_cb = self.cb
 
101
        self.cb(first, second)
 
102
        self.mocker.replay()
 
103
        self.fake_object.on_just_args(first, second)
 
104
 
 
105
    def test_just_kwargs(self):
 
106
        """Test when the cb just has kwargs."""
 
107
        first = 'first'
 
108
        second = 'second'
 
109
        self.fake_object.on_just_kwargs_cb = self.cb
 
110
        self.cb(first=first, second=second)
 
111
        self.mocker.replay()
 
112
        self.fake_object.on_just_kwargs(first=first, second=second)
 
113
 
 
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
 
117
        self.cb()
 
118
        self.mocker.replay()
 
119
        self.fake_object.on_just_kwargs()
 
120
 
 
121
    def test_both_args(self):
 
122
        """Test with args and kwargs."""
 
123
        first = 'first'
 
124
        second = 'second'
 
125
        self.fake_object.on_both_args_cb = self.cb
 
126
        self.cb(first, second, first=first, second=second)
 
127
        self.mocker.replay()
 
128
        self.fake_object.on_both_args(first, second, first=first,
 
129
                                      second=second)
 
130
 
 
131
    def test_both_args_no_kwargs(self):
 
132
        """Test with args and kwargs."""
 
133
        first = 'first'
 
134
        second = 'second'
 
135
        self.fake_object.on_both_args_cb = self.cb
 
136
        self.cb(first, second)
 
137
        self.mocker.replay()
 
138
        self.fake_object.on_both_args(first, second)
 
139
 
 
140
    def test_both_args_no_args(self):
 
141
        """Test with args and kwargs."""
 
142
        first = 'first'
 
143
        second = 'second'
 
144
        self.fake_object.on_both_args_cb = self.cb
 
145
        self.cb(first=first, second=second)
 
146
        self.mocker.replay()
 
147
        self.fake_object.on_both_args(first=first, second=second)
 
148
# pylint: enable=W0201
 
149
 
 
150
 
54
151
class SSOLoginTestCase(TestCase):
55
152
    """Test the login class."""
56
153
 
98
195
        client = SSOLoginClient(remote)
99
196
        yield client.register_to_signals()
100
197
        # set the cb
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',
105
 
                       'on_logged_in_cb',
106
 
                       'on_login_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',
 
202
                            'on_logged_in_cb',
 
203
                            'on_login_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)
116
213
 
117
214
    def test_emit_captcha_generated(self):
596
693
        client = SSOCredentialsClient(remote)
597
694
        yield client.register_to_signals()
598
695
        # set the cb
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)
604
701
 
605
702
    def test_emit_authorization_denied(self):
850
947
        client = CredentialsManagementClient(remote)
851
948
        yield client.register_to_signals()
852
949
        # set the cb
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)
861
958
 
862
959
    def test_shutdown(self):