1
# test_config - tests for ubuntuone.oauthdesktop.config
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.config import get_config
25
class ConfigFileTests(MockerTestCase):
26
"""Test the config file finder"""
28
def test_get_file_from_tmp(self):
29
"""Does the tmp file get chosen?"""
31
# mock that tmp config file exists
32
tmp_config_file = os.path.realpath(os.path.join(
33
os.path.split(config.__file__)[0], "../../data/oauth_urls"
35
osp = self.mocker.replace("os.path")
36
osp.isfile(tmp_config_file)
37
self.mocker.result(True)
41
self.assertEqual(conf.FILENAME, tmp_config_file)
43
def test_get_file_from_home(self):
44
"""Does our home config file get chosen?"""
46
# mock that home config file exists
47
home_config_file = os.path.expanduser("~/.config/ubuntuone/oauth_urls")
48
osp = self.mocker.replace("os.path")
49
osp.exists(home_config_file)
50
self.mocker.result(True)
53
conf = get_config(use_tmpconfig=False) # pretend not in source tree
54
self.assertEqual(conf.FILENAME, home_config_file)
56
def test_get_file_from_etc(self):
57
"""Does our /etc config file get chosen?"""
59
# mock that etc config file exists
60
etc_config_file = os.path.expanduser("/etc/xdg/ubuntuone/oauth_urls")
61
osp = self.mocker.replace("os.path")
62
osp.exists(etc_config_file)
63
self.mocker.result(True)
66
conf = get_config(use_tmpconfig=False) # pretend not in source tree
67
self.assertEqual(conf.FILENAME, etc_config_file)
69
def test_tmp_file_parses(self):
70
"""Does the tmp file get chosen and parse correctly?"""
72
# mock that tmp config file exists
73
tmp_config_file = os.path.realpath(os.path.join(
74
os.path.split(config.__file__)[0], "../../data/oauth_urls"
76
osp = self.mocker.replace("os.path")
77
osp.isfile(tmp_config_file)
78
self.mocker.result(True)
80
sio = StringIO.StringIO("[default]\n")
81
mock_open = self.mocker.replace(open)
82
mock_open(tmp_config_file)
83
self.mocker.result(sio)
88
self.assertTrue(conf.has_section("default"))