14
14
# You should have received a copy of the GNU General Public License along
15
15
# with this program. If not, see <http://www.gnu.org/licenses/>.
17
# In addition, as a special exception, the copyright holders give
18
# permission to link the code of portions of this program with the
19
# OpenSSL library under certain conditions as described in each
20
# individual source file, and distribute linked combinations
22
# You must obey the GNU General Public License in all respects
23
# for all of the code used other than OpenSSL. If you modify
24
# file(s) with this exception, you may extend this exception to your
25
# version of the file(s), but you are not obligated to do so. If you
26
# do not wish to do so, delete this exception statement from your
27
# version. If you delete this exception statement from all source
28
# files in the program, then also delete it here.
29
17
"""Tests for the Ubuntu SSO library."""
33
from collections import defaultdict
34
from functools import wraps
36
21
from twisted.internet import defer
37
22
from twisted.trial import unittest
39
24
from ubuntu_sso.keyring import get_token_name
41
APP_NAME = u'I ♥ Ubuntu'
42
CAPTCHA_ID = u'test ñiña'
26
APP_NAME = u'The Super App!'
43
28
CAPTCHA_PATH = os.path.abspath(os.path.join(os.curdir, 'ubuntu_sso', 'tests',
44
29
'files', 'captcha.png'))
45
CAPTCHA_SOLUTION = u'william Byrd ñandú'
30
CAPTCHA_SOLUTION = u'william Byrd'
46
31
EMAIL = u'test@example.com'
47
EMAIL_TOKEN = u'B2P☺ gtf'
48
GTK_GUI_EXE = 'ubuntu-sso-login-gtk'
49
HELP_TEXT = u'☛ Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' \
50
'Nam sed lorem nibh. Suspendisse gravida nulla non nunc suscipit pulvinar ' \
51
'tempus ut augue. Morbi consequat, ligula a elementum pretium, ' \
52
'dolor nulla tempus metus, sed viverra nisi risus non velit.'
53
NAME = u'Juanito ☀ Pérez'
54
PASSWORD = u'h3lloWorld☑ '
32
EMAIL_TOKEN = u'B2Pgtf'
33
GTK_GUI_CLASS = 'UbuntuSSOClientGUI'
34
GTK_GUI_MODULE = 'ubuntu_sso.gtk.gui'
35
HELP_TEXT = """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sed
36
lorem nibh. Suspendisse gravida nulla non nunc suscipit pulvinar tempus ut
37
augue. Morbi consequat, ligula a elementum pretium, dolor nulla tempus metus,
38
sed viverra nisi risus non velit."""
39
NAME = u'Juanito Pérez'
40
PASSWORD = u'h3lloWorld'
55
41
PING_URL = u'http://localhost/ping-me/'
56
POLICY_URL = u'http://localhost/policy/'
57
42
RESET_PASSWORD_TOKEN = u'8G5Wtq'
58
43
TOKEN = {u'consumer_key': u'xQ7xDAz',
59
44
u'consumer_secret': u'KzCJWCTNbbntwfyCKKjomJDzlgqxLy',
76
61
def _set_called(self, *args, **kwargs):
77
62
"""Keep track of a method call."""
78
63
self._called = (args, kwargs)
81
class Recorder(object):
82
"""A class that records every call clients made to it."""
87
def __init__(self, *args, **kwargs):
88
self._called = defaultdict(list)
90
def __getattribute__(self, attr_name):
91
"""Override so we can record calls to members."""
93
result = super(Recorder, self).__getattribute__(attr_name)
94
except AttributeError:
95
result = lambda *a, **kw: self._next_result
96
super(Recorder, self).__setattr__(attr_name, result)
98
if attr_name in super(Recorder, self).__getattribute__('no_wrap'):
101
called = super(Recorder, self).__getattribute__('_called')
107
"""Keep track of calls to 'f', execute it and return result."""
108
called[attr_name].append((a, kw))
114
return wrap_me(result)