~didrocks/ubuntuone-client/dont-suffer-zg-crash

« back to all changes in this revision

Viewing changes to tests/oauthdesktop/test_config.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2010-06-23 23:08:15 UTC
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: james.westby@ubuntu.com-20100623230815-4m3ugh10u9x9xzw5
Tags: upstream-1.3.2
ImportĀ upstreamĀ versionĀ 1.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# test_config - tests for ubuntuone.oauthdesktop.config
2
 
#
3
 
# Author: Stuart Langridge <stuart.langridge@canonical.com>
4
 
#
5
 
# Copyright 2009 Canonical Ltd.
6
 
#
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.
10
 
#
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.
15
 
#
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."""
19
 
 
20
 
import os, StringIO
21
 
from contrib.mocker import MockerTestCase
22
 
from ubuntuone.oauthdesktop import config
23
 
from ubuntuone.oauthdesktop.config import get_config
24
 
 
25
 
class ConfigFileTests(MockerTestCase):
26
 
    """Test the config file finder"""
27
 
 
28
 
    def test_get_file_from_tmp(self):
29
 
        """Does the tmp file get chosen?"""
30
 
        
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"
34
 
        ))
35
 
        osp = self.mocker.replace("os.path")
36
 
        osp.isfile(tmp_config_file)
37
 
        self.mocker.result(True)
38
 
        self.mocker.replay()
39
 
        
40
 
        conf = get_config()
41
 
        self.assertEqual(conf.FILENAME, tmp_config_file)
42
 
 
43
 
    def test_get_file_from_home(self):
44
 
        """Does our home config file get chosen?"""
45
 
        
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)
51
 
        self.mocker.replay()
52
 
        
53
 
        conf = get_config(use_tmpconfig=False) # pretend not in source tree
54
 
        self.assertEqual(conf.FILENAME, home_config_file)
55
 
 
56
 
    def test_get_file_from_etc(self):
57
 
        """Does our /etc config file get chosen?"""
58
 
        
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)
64
 
        self.mocker.replay()
65
 
        
66
 
        conf = get_config(use_tmpconfig=False) # pretend not in source tree
67
 
        self.assertEqual(conf.FILENAME, etc_config_file)
68
 
 
69
 
    def test_tmp_file_parses(self):
70
 
        """Does the tmp file get chosen and parse correctly?"""
71
 
        
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"
75
 
        ))
76
 
        osp = self.mocker.replace("os.path")
77
 
        osp.isfile(tmp_config_file)
78
 
        self.mocker.result(True)
79
 
        
80
 
        sio = StringIO.StringIO("[default]\n")
81
 
        mock_open = self.mocker.replace(open)
82
 
        mock_open(tmp_config_file)
83
 
        self.mocker.result(sio)
84
 
        
85
 
        self.mocker.replay()
86
 
        
87
 
        conf = get_config()
88
 
        self.assertTrue(conf.has_section("default"))
89
 
 
90