~diegosarmentero/ubuntu-sso-client/tests-broken

« back to all changes in this revision

Viewing changes to ubuntu_sso/keyring/tests/test_linux.py

  • Committer: Tarmac
  • Author(s): Alejandro J. Cura
  • Date: 2011-10-20 21:02:56 UTC
  • mfrom: (802.1.2 fix-get-token-name)
  • Revision ID: tarmac-20111020210256-2tcpsd16kcok0x5v
The hostname can now contain characters in the system encoding. (LP: #875331)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
2
#
3
 
# test_keyring - tests for ubuntu_sso.keyring
 
3
# test_linux - tests for ubuntu_sso.keyring under linux
4
4
#
5
5
# Author: Alejandro J. Cura <alecu@canonical.com>
6
6
# Author: Natalia B. Bidart <natalia.bidart@canonical.com>
20
20
# with this program.  If not, see <http://www.gnu.org/licenses/>.
21
21
"""Tests for the keyring.py module."""
22
22
 
23
 
import socket
24
 
 
25
23
from twisted.internet import defer
26
24
from twisted.internet.defer import inlineCallbacks
27
25
from twisted.trial.unittest import TestCase
31
29
from ubuntu_sso.tests import APP_NAME
32
30
 
33
31
 
34
 
def build_fake_gethostname(fake_hostname):
35
 
    """Return a fake hostname getter."""
36
 
    return lambda *a: fake_hostname
37
 
 
38
 
 
39
32
class MockItem(object):
40
33
    """An item contains a secret, lookup attributes and has a label."""
41
34
 
116
109
        return defer.succeed(self.collections["default"])
117
110
 
118
111
 
119
 
class TestTokenNameBuilder(TestCase):
120
 
    """Test the method that builds the token name."""
121
 
 
122
 
    def test_get_simple_token_name(self):
123
 
        """A simple token name is built right."""
124
 
        sample_app_name = "UbuntuTwo"
125
 
        sample_hostname = "Darkstar"
126
 
        expected_result = "UbuntuTwo @ Darkstar"
127
 
 
128
 
        fake_gethostname = build_fake_gethostname(sample_hostname)
129
 
        self.patch(socket, "gethostname", fake_gethostname)
130
 
        result = keyring.get_token_name(sample_app_name)
131
 
        self.assertEqual(result, expected_result)
132
 
 
133
 
    def test_get_complex_token_name_for_app_name(self):
134
 
        """A complex token name is built right too."""
135
 
        sample_app_name = "Ubuntu @ Eleven"
136
 
        sample_hostname = "Mate+Cocido"
137
 
        expected_result = "Ubuntu @ Eleven @ Mate+Cocido"
138
 
 
139
 
        fake_gethostname = build_fake_gethostname(sample_hostname)
140
 
        self.patch(socket, "gethostname", fake_gethostname)
141
 
        result = keyring.get_token_name(sample_app_name)
142
 
        self.assertEqual(result, expected_result)
143
 
 
144
 
    def test_get_complex_token_name_for_hostname(self):
145
 
        """A complex token name is built right too."""
146
 
        sample_app_name = "Ubuntu Eleven"
147
 
        sample_hostname = "Mate @ Cocido"
148
 
        expected_result = "Ubuntu Eleven @ Mate AT Cocido"
149
 
 
150
 
        fake_gethostname = build_fake_gethostname(sample_hostname)
151
 
        self.patch(socket, "gethostname", fake_gethostname)
152
 
        result = keyring.get_token_name(sample_app_name)
153
 
        self.assertEqual(result, expected_result)
154
 
 
155
 
 
156
112
class TestKeyring(TestCase):
157
113
    """Test the keyring related functions."""
158
114
 
163
119
        self.mock_service = None
164
120
        self.service = self.patch(keyring, "SecretService",
165
121
                                  self.get_mock_service)
166
 
        fake_gethostname = build_fake_gethostname("darkstar")
167
 
        self.patch(socket, "gethostname", fake_gethostname)
 
122
        self.patch(common_keyring, "gethostname", lambda: "darkstar")
168
123
 
169
124
    def get_mock_service(self):
170
125
        """Create only one instance of the mock service per test."""