~tribaal/txaws/xss-hardening

« back to all changes in this revision

Viewing changes to txaws/testing/base.py

  • Committer: Duncan McGreggor
  • Date: 2009-08-28 02:32:44 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: duncan@canonical.com-20090828023244-6t44fi741heukb8p
- Fixed the creds parameter in the get_ec2_client method.
- Removed redundant code in check_parsed_instances.
- Created a testing subpackage for generally useful testing classes.
- Added fake ec2 client and region classes.
- Moved base test case into new testing module.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
 
 
3
from twisted.trial.unittest import TestCase
 
4
 
 
5
 
 
6
class TXAWSTestCase(TestCase):
 
7
    """Support for isolation of txaws tests."""
 
8
 
 
9
    def setUp(self):
 
10
        TestCase.setUp(self)
 
11
        self.stash_environ()
 
12
 
 
13
    def stash_environ(self):
 
14
        self.orig_environ = dict(os.environ)
 
15
        self.addCleanup(self.restore_environ)
 
16
        if 'AWS_ACCESS_KEY_ID' in os.environ:
 
17
            del os.environ['AWS_ACCESS_KEY_ID']
 
18
        if 'AWS_SECRET_ACCESS_KEY' in os.environ:
 
19
            del os.environ['AWS_SECRET_ACCESS_KEY']
 
20
 
 
21
    def restore_environ(self):
 
22
        for key in set(os.environ) - set(self.orig_environ):
 
23
            del os.environ[key]
 
24
        os.environ.update(self.orig_environ)
 
25