~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/launchpad/utilities/ftests/test_gpghandler.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-05-09 02:03:49 UTC
  • mfrom: (12990.2.1 rollback-12987)
  • Revision ID: launchpad@pqm.canonical.com-20110509020349-av7wi9hq7j9wa4nu
[rs=wgrant][rollback=12987] Roll back r12987. It makes poppy-sftp
 leak LoopingCalls,
 and relies on there being at least one SFTP session before the reaping.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
import unittest
5
5
 
6
 
from calendar import timegm
7
 
from datetime import (
8
 
    datetime,
9
 
    timedelta,
10
 
    )
11
 
from pytz import UTC
12
6
import gpgme
13
 
import os
14
7
from zope.component import getUtility
15
 
from zope.security.proxy import removeSecurityProxy
16
8
 
17
9
from canonical.launchpad.ftests import (
18
10
    ANONYMOUS,
183
175
            self.gpg_handler.importKeyringFile(ring)
184
176
        self.assertEqual(self.gpg_handler.checkTrustDb(), 0)
185
177
 
186
 
    def testHomeDirectoryJob(self):
187
 
        """Does the job to touch the home work."""
188
 
        gpghandler = getUtility(IGPGHandler)
189
 
        naked_gpghandler = removeSecurityProxy(gpghandler)
190
 
 
191
 
        # Get a list of all the files in the home directory.
192
 
        files_to_check = [os.path.join(naked_gpghandler.home, f)
193
 
            for f in os.listdir(naked_gpghandler.home)]
194
 
        files_to_check.append(naked_gpghandler.home)
195
 
        self.assertTrue(len(files_to_check) > 1)
196
 
 
197
 
        # Set the last modified times to 12 hours ago
198
 
        nowless12 = (datetime.now(UTC) - timedelta(hours=12)).utctimetuple()
199
 
        lm_time = timegm(nowless12)
200
 
        for fname in files_to_check:
201
 
            os.utime(fname, (lm_time, lm_time))
202
 
 
203
 
        # Touch the files and re-check the last modified times.
204
 
        gpghandler.touchConfigurationDirectory()
205
 
        second_last_modified_times = dict(
206
 
            (fname, os.path.getmtime(fname)) for fname in files_to_check)
207
 
        for fname in files_to_check:
208
 
            self.assertTrue(
209
 
                lm_time + 12 * 3600 <= second_last_modified_times[fname])
 
178
 
 
179
def test_suite():
 
180
    return unittest.TestLoader().loadTestsFromName(__name__)
 
181
 
 
182
 
 
183
if __name__ == "__main__":
 
184
    unittest.main(defaultTest=test_suite())
 
185
 
 
186