When endpoint is None, the default situation, an AttributeError will
be raised because self.endpoint is not defined when get_uri tries to
access it. It looks like get_uri should be instantiating and
returning a new endpoint instance, instead of mutating the existing
one. It would be good to add a test to ensure defaults are handled
properly.
[3]
+ def stash_environ(self):
+ self.orig_environ = dict(os.environ)
+ self.addCleanup(self.restore_environ)
+ if 'AWS_ACCESS_KEY_ID' in os.environ:
+ del os.environ['AWS_ACCESS_KEY_ID']
+ if 'AWS_SECRET_ACCESS_KEY' in os.environ:
+ del os.environ['AWS_SECRET_ACCESS_KEY']
+
+ def restore_environ(self):
+ for key in set(os.environ) - set(self.orig_environ):
+ del os.environ[key]
+ os.environ.update(self.orig_environ)
I think these methods should be private. It's not safe for a user
to call stash_environ during a test because it will rewrite
self.orig_environ with the test environment, defeating the purpose
of this code.
If you have already seen it you may want to check out https://launchpad.net/testresources. It provides a nice framework
for writing helpers that provide per-test services. It could be
useful for doing the kind of thing you're doing above (though maybe
testscenarios is more relevant here?).
The default list value here will be shared by all FakeEC2Client
instances, which could cause tricky bugs. I recommend you use None
as the default here along with 'self.instances = instances or []'.
[5]
+ def setUp(self):
+ self.addCleanup(self.clean_environment)
+
+ def clean_environment(self):
+ if os.environ.has_key(ENV_ACCESS_KEY):
+ del os.environ[ENV_ACCESS_KEY]
+ if os.environ.has_key(ENV_SECRET_KEY):
+ del os.environ[ENV_SECRET_KEY]
This code is unnecessary given the {stash,restore}_environ methods
in TXAWSTestCase.
[1]
+ def get_s3_ client( self): client( self): client( self):
+ raise NotImplementedError
+
+ def get_simpledb_
+ raise NotImplementedError
+
+ def get_sqs_
+ raise NotImplementedError
I think you should leave these out since they don't add any useful
functionality.
[2]
You have:
+ self.endpoint = endpoint or self.get_uri()
and then a bit later:
def get_uri(self): set_path( self.get_ path()) get_uri( )
- return self.root_uri + self.get_uri_path()
+ self.endpoint.
+ return self.endpoint.
When endpoint is None, the default situation, an AttributeError will
be raised because self.endpoint is not defined when get_uri tries to
access it. It looks like get_uri should be instantiating and
returning a new endpoint instance, instead of mutating the existing
one. It would be good to add a test to ensure defaults are handled
properly.
[3]
+ def stash_environ( self): (self.restore_ environ) 'AWS_ACCESS_ KEY_ID' ] ACCESS_ KEY' in os.environ: 'AWS_SECRET_ ACCESS_ KEY'] environ( self): orig_environ) : update( self.orig_ environ)
+ self.orig_environ = dict(os.environ)
+ self.addCleanup
+ if 'AWS_ACCESS_KEY_ID' in os.environ:
+ del os.environ[
+ if 'AWS_SECRET_
+ del os.environ[
+
+ def restore_
+ for key in set(os.environ) - set(self.
+ del os.environ[key]
+ os.environ.
I think these methods should be private. It's not safe for a user
to call stash_environ during a test because it will rewrite
self.orig_environ with the test environment, defeating the purpose
of this code.
If you have already seen it you may want to check out /launchpad. net/testresourc es. It provides a nice framework
https:/
for writing helpers that provide per-test services. It could be
useful for doing the kind of thing you're doing above (though maybe
testscenarios is more relevant here?).
[4]
+ def __init__(self, creds, endpoint, instances=[]):
The default list value here will be shared by all FakeEC2Client
instances, which could cause tricky bugs. I recommend you use None
as the default here along with 'self.instances = instances or []'.
[5]
+ def setUp(self): (self.clean_ environment) nt(self) : has_key( ENV_ACCESS_ KEY): ENV_ACCESS_ KEY] has_key( ENV_SECRET_ KEY): ENV_SECRET_ KEY]
+ self.addCleanup
+
+ def clean_environme
+ if os.environ.
+ del os.environ[
+ if os.environ.
+ del os.environ[
This code is unnecessary given the {stash, restore} _environ methods
in TXAWSTestCase.
Looks good, +1!