~ubuntuone-control-tower/software-center/trunk

« back to all changes in this revision

Viewing changes to test/test_utils.py

  • Committer: Gary Lasker
  • Date: 2012-02-29 22:47:33 UTC
  • mfrom: (2788.1.3 expunge-cache)
  • Revision ID: gary.lasker@canonical.com-20120229224733-zodt5r2l7u7r2qtx
merged lp:~mvo/software-center/expunge-cache, thanks mvo

Show diffs side-by-side

added added

removed removed

Lines of Context:
124
124
        uuid = get_uuid()
125
125
        self.assertTrue(uuid and len(uuid) > 0)
126
126
 
 
127
class TestExpungeCache(unittest.TestCase):
 
128
 
 
129
    def test_expunge_cache(self):
 
130
        import subprocess
 
131
        import tempfile
 
132
        dirname = tempfile.mkdtemp('s-c-testsuite')
 
133
        for name, content in [ ("foo-301", "status: 301"),
 
134
                               ("foo-200", "status: 200"),
 
135
                               ("foo-random", "random"),
 
136
                             ]:
 
137
            fullpath = os.path.join(dirname, name)
 
138
            open(fullpath, "w").write(content)
 
139
            # set to 1970+1s time to ensure the cleaner finds it
 
140
            os.utime(fullpath, (1,1))
 
141
        res = subprocess.call(["../utils/expunge-cache.py", dirname])
 
142
        # no arguments
 
143
        self.assertEqual(res, 1)
 
144
        # by status
 
145
        res = subprocess.call(["../utils/expunge-cache.py",
 
146
                               "--debug",
 
147
                               "--by-unsuccessful-http-states",
 
148
                               dirname])
 
149
        self.assertFalse(os.path.exists(os.path.join(dirname, "foo-301")))
 
150
        self.assertTrue(os.path.exists(os.path.join(dirname, "foo-200")))
 
151
        self.assertTrue(os.path.exists(os.path.join(dirname, "foo-random")))
 
152
 
 
153
        # by time 
 
154
        res = subprocess.call(["../utils/expunge-cache.py",
 
155
                               "--debug",
 
156
                               "--by-days", "1",
 
157
                               dirname])
 
158
        # now we expect the old file to be gone but the unknown one not to
 
159
        # be touched
 
160
        self.assertFalse(os.path.exists(os.path.join(dirname, "foo-200")))
 
161
        self.assertTrue(os.path.exists(os.path.join(dirname, "foo-random")))
 
162
 
127
163
 
128
164
if __name__ == "__main__":
129
165
    import logging