Permalink
Browse files

Added a couple more tests.

  • Loading branch information...
1 parent dd88b15 commit 42b3765584af8e4d74b80a68ce433e8b4a2d5cc0 @jacobian jacobian committed Apr 28, 2010
Showing with 28 additions and 4 deletions.
  1. +3 −0 tests/fakeserver.py
  2. +5 −0 tests/test_auth.py
  3. +12 −2 tests/test_base.py
  4. +8 −2 tests/test_shell.py
View
3 tests/fakeserver.py
@@ -254,6 +254,9 @@ def get_flavors_detail(self, **kw):
def get_flavors_1(self, **kw):
return (200, {'flavor': self.get_flavors_detail()[1]['flavors'][0]})
+ def get_flavors_2(self, **kw):
+ return (200, {'flavor': self.get_flavors_detail()[1]['flavors'][1]})
+
#
# Images
#
View
5 tests/test_auth.py
@@ -39,3 +39,8 @@ def test_auth_automatic():
mock_authenticate.assert_called()
mock_request.assert_called()
+def test_auth_manual():
+ cs = cloudservers.CloudServers("username", "password")
+ with mock.patch_object(cs.client, 'authenticate') as mocked:
+ cs.authenticate()
+ mocked.assert_called()
View
14 tests/test_base.py
@@ -1,8 +1,10 @@
-from __future__ import absolute_import
+from __future__ import absolute_import, with_statement
+import mock
import cloudservers.base
from .fakeserver import FakeServer
from cloudservers import Flavor
+from cloudservers.exceptions import NotFound
from cloudservers.base import Resource
from nose.tools import assert_equal, assert_not_equal, assert_raises
@@ -41,4 +43,12 @@ def test_eq():
# Two resources with no ID: equal if their info is equal
r1 = Resource(None, {'name': 'joe', 'age': 12})
r2 = Resource(None, {'name': 'joe', 'age': 12})
- assert_equal(r1, r2)
+ assert_equal(r1, r2)
+
+def test_findall_invalid_attribute():
+ # Make sure findall with an invalid attribute doesn't cause errors.
+ # The following should not raise an exception.
+ cs.flavors.findall(vegetable='carrot')
+
+ # However, find() should raise an error
+ assert_raises(NotFound, cs.flavors.find, vegetable='carrot')
View
10 tests/test_shell.py
@@ -2,6 +2,7 @@
import os
import mock
+import httplib2
from nose.tools import assert_raises
from cloudservers.shell import CloudserversShell, CommandError
from .fakeserver import FakeServer
@@ -13,7 +14,7 @@ def setup():
'CLOUD_SERVERS_USERNAME': 'username',
'CLOUD_SERVERS_API_KEY': 'password'
}
- _old_env, os.environ = os.environ, fake_env
+ _old_env, os.environ = os.environ, fake_env.copy()
# Make a fake shell object, a helping wrapper to call it, and a quick way
# of asserting that certain API calls were made.
@@ -181,4 +182,9 @@ def test_help():
with mock.patch_object(_shell.subcommands['delete'], 'print_help') as m:
shell('help delete')
m.assert_called()
- assert_raises(CommandError, shell, 'help foofoo')
+ assert_raises(CommandError, shell, 'help foofoo')
+
+def test_debug():
+ httplib2.debuglevel = 0
+ shell('--debug list')
+ assert httplib2.debuglevel == 1

0 comments on commit 42b3765

Please sign in to comment.