1
# test_main - tests for ubuntuone.oauthdesktop.main
3
# Author: Stuart Langridge <stuart.langridge@canonical.com>
5
# Copyright 2009 Canonical Ltd.
7
# This program is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
# PURPOSE. See the GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License along
17
# with this program. If not, see <http://www.gnu.org/licenses/>.
18
"""Tests for the OAuth client code for StorageFS."""
21
from contrib.mocker import MockerTestCase
22
from ubuntuone.oauthdesktop import config
23
from ubuntuone.oauthdesktop.main import LoginProcessor, BadRealmError
25
class Realm(MockerTestCase):
26
"""Test the realm handling finder"""
28
def test_invalid_realm(self):
29
"""Are invalid realms rejected?"""
31
login = LoginProcessor(None, use_libnotify=False)
32
self.assertRaises(BadRealmError, login.login, "bad realm", "key")
34
def test_realms(self):
35
"""Are realm URLs correctly retrieved from the config?"""
37
# mock that tmp config file exists
38
tmp_config_file = os.path.realpath(os.path.join(
39
os.path.split(config.__file__)[0], "../../data/oauth_urls"
41
osp = self.mocker.replace("os.path")
42
osp.isfile(tmp_config_file)
43
self.mocker.result(True)
45
sio = StringIO.StringIO("""[default]
46
request_token_url = /rtu-default
47
user_authorisation_url = /uau-default
48
access_token_url = /atu-default
49
consumer_secret = foo-default
52
request_token_url = /rtu-localhost
53
user_authorisation_url = /uau-localhost
54
access_token_url = /atu-localhost
55
consumer_secret = foo-localhost
57
[http://ubuntuone.com]
58
request_token_url = /rtu-ubuntuone
59
user_authorisation_url = /uau-ubuntuone
60
access_token_url = /atu-ubuntuone
61
consumer_secret = foo-ubuntuone
64
mock_open = self.mocker.replace(open)
65
mock_open(tmp_config_file)
66
self.mocker.result(sio)
70
login = LoginProcessor(None, use_libnotify=False)
72
# are localhost:XXXX URLs correctly fetched?
73
(rtu, uau, atu, cs) = login.get_config_urls("http://localhost:9876")
74
self.assertEqual(rtu, "http://localhost:9876/rtu-localhost")
75
self.assertEqual(uau, "http://localhost:9876/uau-localhost")
76
self.assertEqual(atu, "http://localhost:9876/atu-localhost")
77
self.assertEqual(cs, "foo-localhost")
79
# is a URL specifically in the config correctly fetched?
80
(rtu, uau, atu, cs) = login.get_config_urls("http://ubuntuone.com")
81
self.assertEqual(rtu, "http://ubuntuone.com/rtu-ubuntuone")
82
self.assertEqual(uau, "http://ubuntuone.com/uau-ubuntuone")
83
self.assertEqual(atu, "http://ubuntuone.com/atu-ubuntuone")
84
self.assertEqual(cs, "foo-ubuntuone")
86
# is a URL not in the config correctly fetched as default?
87
(rtu, uau, atu, cs) = login.get_config_urls("http://other.example.net")
88
self.assertEqual(rtu, "http://other.example.net/rtu-default")
89
self.assertEqual(uau, "http://other.example.net/uau-default")
90
self.assertEqual(atu, "http://other.example.net/atu-default")
91
self.assertEqual(cs, "foo-default")