~txawsteam/txaws/trunk

« back to all changes in this revision

Viewing changes to txaws/testing/base.py

Merged 416109-arbitrary-endpoints [r=therve,jkakar] [f=416109].

The primary change of this branch is support of arbitrary endpoints (needed for
the support of Eucalyptus). In addition, the following was also performed:
 * Added a parse utility function from Twisted
 * Created a testing subpackage for use by txAWS unit tests
 * Created a service module for abstracting regions and associated
   serices/credentials

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