~ubuntu-branches/ubuntu/vivid/software-center/vivid

« back to all changes in this revision

Viewing changes to test/test_utils.py

  • Committer: Package Import Robot
  • Author(s): Michael Vogt, Michael Vogt, Ken VanDine, Gary Lasker, Robert Roth, Dave Morley
  • Date: 2012-05-15 20:22:02 UTC
  • Revision ID: package-import@ubuntu.com-20120515202202-ndm7k54wsqvaoj3y
Tags: 5.2.2
[ Michael Vogt ]
* lp:~mvo/software-center/whatsnew-leak-lp985389:
  - search filter fix for the case when the "installed-only"
    filter leaks into subsequent searches (LP: #985389)
* lp:~mvo/software-center/fix-lp994632:
  - add a dep to ensure we get the correct ubuntu-sso-client-gtk
    (LP: #994632)
* lp:~mvo/software-center/proper-error-on-unknown-files:
  - show a proper error message when attempting to open unknown
    file types (LP: #944868)
* lp:~mvo/software-center/lp921799:
  - fix crash when decoding screenshots JSON (LP: #921799)
* lp:~mvo/software-center/lp959612:
  - fix crash when selecting the Installed view very quickly
    after startup (LP: #959612)

[ Ken VanDine ]
* lp:~ken-vandine/software-center/lp_982567:
  - Check if the proxy is enabled, if the proxy host is set but not 
    enabled we shouldn't attempt to use the proxy (LP: #982567)

[ Gary Lasker ]
* lp:~gary-lasker/software-center/fix-crash-lp969732:
  - need to explicitly declare the needs-refresh signal in the 
    AppTreeStore class to prevent a crash (LP: #969732)
* lp:~gary-lasker/software-center/fix-crash-lp870822:
  - don't crash if we don't get a pkgversion object back 
    (LP: #870822)
* lp:~gary-lasker/software-center/fix-shutdown-crash-lp996333:
  - never crash when writing out the software center config file on
    shutdown (LP: #996333)
* lp:~gary-lasker/software-center/fix-makedirs-race-crashes:
  - fix crash on race when creating the cache or config directories
    (LP: #743003, LP: #621182)
* lp:~gary-lasker/software-center/fix-crash_lp973379:
  - ensure that the cache is ready before using the recommender 
    service (LP: #973379 )
* lp:~gary-lasker/software-center/toolbar-buttons-insensitive-during-startup:
  - set the toolbar buttons insensitive for the duration of time that the 
    lobby panels are initializing (LP: #999486, LP: #994341)

[ Robert Roth ]
* lp:~evfool/software-center/bug532072:
  - escape markup for support info and license (LP: #993279)
  - ellipsize summary at trailing end (LP: #532072)
* lp:~evfool/software-center/lp626037:
  - subtle background color tweak for consistency
    between views (LP: #626037)
* lp:~evfool/software-center/lp835005:
  - no need for the software-properties dialog to be modal
    to software-center (LP: #835005)
* lp:~evfool/software-center/lp839389:
  - don't display an "icon not found" image in the Unity
    launcher when a report a review window is opened (LP: #839389)
* lp:~evfool/software-center/867588:
  - capitalize the first letter of the package summary
    (LP: #867588)
* lp:~evfool/software-center/lp876657:
  - make sure the search field does not disappear when an
    install or remove is in progress (LP: #876657)
* lp:~evfool/software-center/lp987797:
  - fix alignment in the reviews part of the appdetails (LP: #987797)
* lp:~evfool/software-center/lp844768:
  - show a indeterminate progress bar when software-center waits for
    another packagemanager to exit (LP: #844768)

[ Dave Morley ]
* lp:~davmor2/software-center/add-performance:
  - test code change only! add memory and cpt stats to the
    test script 

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
import glob
5
5
import multiprocessing
6
6
import os
 
7
import stat
7
8
import subprocess
 
9
import shutil
8
10
import tempfile
9
11
import time
10
12
import unittest
11
13
 
 
14
from mock import patch
 
15
 
12
16
from testutils import setup_test_env
13
17
setup_test_env()
14
18
from softwarecenter.utils import (decode_xml_char_reference,
158
162
        self.assertEqual(
159
163
            make_string_from_list(base, l),
160
164
            "There was a problem posting this review to twister, factbook, identi.catz and baz (omg!)")
161
 
        
 
165
 
 
166
    def test_capitalize_first_word(self):
 
167
        from softwarecenter.utils import capitalize_first_word
 
168
        test_synopsis = "feature-rich console based todo list manager"
 
169
        capitalized = capitalize_first_word(test_synopsis)
 
170
        self.assertTrue(
 
171
            capitalized == "Feature-rich console based todo list manager")
 
172
        test_synopsis = "MPlayer's Movie Encoder"
 
173
        capitalized = capitalize_first_word(test_synopsis)
 
174
        self.assertTrue(
 
175
            capitalized == "MPlayer's Movie Encoder")
 
176
            
 
177
    def test_ensure_file_writable_and_delete_if_not(self):
 
178
        from softwarecenter.utils import ensure_file_writable_and_delete_if_not
 
179
        from tempfile import NamedTemporaryFile
 
180
        # first test that a non-writable file (0400) is deleted
 
181
        test_file_not_writeable = NamedTemporaryFile()
 
182
        os.chmod(test_file_not_writeable.name, stat.S_IRUSR)
 
183
        self.assertFalse(os.access(test_file_not_writeable.name, os.W_OK))
 
184
        ensure_file_writable_and_delete_if_not(test_file_not_writeable.name)
 
185
        self.assertFalse(os.path.exists(test_file_not_writeable.name))
 
186
        # then test that a writable file (0600) is not deleted
 
187
        test_file_writeable = NamedTemporaryFile()
 
188
        os.chmod(test_file_writeable.name, stat.S_IRUSR|stat.S_IWUSR)
 
189
        self.assertTrue(os.access(test_file_writeable.name, os.W_OK))
 
190
        ensure_file_writable_and_delete_if_not(test_file_writeable.name)
 
191
        self.assertTrue(os.path.exists(test_file_writeable.name))
 
192
 
 
193
    def test_safe_makedirs(self):
 
194
        from softwarecenter.utils import safe_makedirs
 
195
        from tempfile import mkdtemp
 
196
        tmp = mkdtemp()
 
197
        # create base dir
 
198
        target = os.path.join(tmp, "foo", "bar")
 
199
        safe_makedirs(target)
 
200
        # we need the patch to ensure that the code is actually executed
 
201
        with patch("os.path.exists") as mock_:
 
202
            mock_.return_value = False
 
203
            self.assertTrue(os.path.isdir(target))
 
204
            # ensure that creating the base dir again does not crash
 
205
            safe_makedirs(target)
 
206
            self.assertTrue(os.path.isdir(target))
 
207
            # ensure we still get regular errors like permission denied
 
208
            # (stat.S_IRUSR)
 
209
            os.chmod(os.path.join(tmp, "foo"), 0400)
 
210
            self.assertRaises(OSError, safe_makedirs, target)
 
211
            # set back to stat.(S_IRUSR|S_IWUSR|S_IXUSR) to make rmtree work
 
212
            os.chmod(os.path.join(tmp, "foo"), 0700)
 
213
        # cleanup
 
214
        shutil.rmtree(tmp)
162
215
 
163
216
class TestExpungeCache(unittest.TestCase):
164
217