~ubuntu-branches/ubuntu/raring/software-center/raring-proposed

« back to all changes in this revision

Viewing changes to tests/test_utils.py

  • Committer: Package Import Robot
  • Author(s): Michael Vogt
  • Date: 2012-10-11 15:33:05 UTC
  • mfrom: (195.1.18 quantal)
  • Revision ID: package-import@ubuntu.com-20121011153305-fm5ln7if3rpzts4n
Tags: 5.4.1.1
* lp:~mvo/software-center/reinstall-previous-purchase-token-fix:
  - fix reinstall previous purchases that have a system-wide
    license key LP: #1065481
* lp:~mvo/software-center/lp1060106:
  - Add missing gettext init for utils/update-software-center-agent
    (LP: #1060106)

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
from tests.utils import (
17
17
    do_events,
 
18
    get_test_gtk3_icon_cache,
18
19
    setup_test_env,
19
20
    UTILS_DIR,
20
21
)
26
27
    clear_token_from_ubuntu_sso_sync,
27
28
    decode_xml_char_reference,
28
29
    ensure_file_writable_and_delete_if_not,
 
30
    get_file_path_from_iconname,
29
31
    get_http_proxy_string_from_libproxy,
30
32
    get_http_proxy_string_from_gsettings,
31
33
    get_nice_date_string,
 
34
    get_oem_channel_descriptor,
32
35
    get_title_from_html,
33
36
    get_uuid,
 
37
    get_recommender_uuid,
34
38
    is_no_display_desktop_file,
35
39
    make_string_from_list,
36
40
    release_filename_in_lists_from_deb_line,
37
41
    safe_makedirs,
38
42
    split_icon_ext,
 
43
    TraceMemoryUsage,
39
44
)
40
45
 
41
46
EXPUNGE_SCRIPT = os.path.join(UTILS_DIR, 'expunge-cache.py')
146
151
    def test_get_uuid(self):
147
152
        uuid = get_uuid()
148
153
        self.assertTrue(uuid and len(uuid) > 0)
 
154
        
 
155
    def test_get_recommender_uuid(self):
 
156
        uuid = get_recommender_uuid()
 
157
        self.assertTrue("-" not in uuid and len(uuid) > 0)
149
158
 
150
159
    def test_clear_credentials(self):
151
160
        clear_token_from_ubuntu_sso_sync("fo")
186
195
        # ensure it does not crash for empty strings, LP: #1002271
187
196
        self.assertEqual(capitalize_first_word(""), "")
188
197
 
 
198
    @unittest.skipIf(
 
199
        os.getuid() == 0, 
 
200
        "fails when run as root as os.access() is always successful")
189
201
    def test_ensure_file_writable_and_delete_if_not(self):
190
202
        # first test that a non-writable file (0400) is deleted
191
203
        test_file_not_writeable = NamedTemporaryFile()
200
212
        ensure_file_writable_and_delete_if_not(test_file_writeable.name)
201
213
        self.assertTrue(os.path.exists(test_file_writeable.name))
202
214
 
 
215
    @unittest.skipIf(
 
216
        os.getuid() == 0, 
 
217
        "fails when run as root as os.chmod() is always successful")
203
218
    def test_safe_makedirs(self):
204
219
        tmp = mkdtemp()
205
220
        # create base dir
221
236
        # cleanup
222
237
        shutil.rmtree(tmp)
223
238
 
 
239
    def test_get_file_path_from_iconname(self):
 
240
        icons = get_test_gtk3_icon_cache()
 
241
        icon_path = get_file_path_from_iconname(
 
242
                icons,
 
243
                "softwarecenter")
 
244
        self.assertEqual(
 
245
                icon_path,
 
246
                "/usr/share/icons/hicolor/48x48/apps/softwarecenter.svg")
 
247
 
224
248
 
225
249
class TestExpungeCache(unittest.TestCase):
226
250
 
277
301
        # ensure that the second one was not called
278
302
        self.assertEqual(len(glob.glob(os.path.join(tmpdir, "marker.*"))), 1)
279
303
 
 
304
    def test_oem_channel_extractor(self):
 
305
        s = get_oem_channel_descriptor("./tests/data/ubuntu_dist_channel")
 
306
        self.assertEqual(s, "canonical-oem-watauga-precise-amd64-20120517-2")
 
307
 
 
308
    def test_memory_growth(self):
 
309
        with TraceMemoryUsage("list append"):
 
310
            l=[]
 
311
            for i in range(64*1024):
 
312
                l.append(i)
 
313
 
280
314
 
281
315
if __name__ == "__main__":
282
316
    unittest.main()