Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added a couple more tests.

  • Loading branch information...
commit 42b3765584af8e4d74b80a68ce433e8b4a2d5cc0 1 parent dd88b15
Jacob Kaplan-Moss authored April 28, 2010
3  tests/fakeserver.py
@@ -254,6 +254,9 @@ def get_flavors_detail(self, **kw):
254 254
     def get_flavors_1(self, **kw):
255 255
         return (200, {'flavor': self.get_flavors_detail()[1]['flavors'][0]})
256 256
     
  257
+    def get_flavors_2(self, **kw):
  258
+        return (200, {'flavor': self.get_flavors_detail()[1]['flavors'][1]})
  259
+    
257 260
     #
258 261
     # Images
259 262
     #
5  tests/test_auth.py
@@ -39,3 +39,8 @@ def test_auth_automatic():
39 39
             mock_authenticate.assert_called()
40 40
             mock_request.assert_called()
41 41
             
  42
+def test_auth_manual():
  43
+    cs = cloudservers.CloudServers("username", "password")
  44
+    with mock.patch_object(cs.client, 'authenticate') as mocked:
  45
+        cs.authenticate()
  46
+        mocked.assert_called()
14  tests/test_base.py
... ...
@@ -1,8 +1,10 @@
1  
-from __future__ import absolute_import
  1
+from __future__ import absolute_import, with_statement
2 2
 
  3
+import mock
3 4
 import cloudservers.base
4 5
 from .fakeserver import FakeServer
5 6
 from cloudservers import Flavor
  7
+from cloudservers.exceptions import NotFound
6 8
 from cloudservers.base import Resource
7 9
 from nose.tools import assert_equal, assert_not_equal, assert_raises
8 10
 
@@ -41,4 +43,12 @@ def test_eq():
41 43
     # Two resources with no ID: equal if their info is equal
42 44
     r1 = Resource(None, {'name': 'joe', 'age': 12})
43 45
     r2 = Resource(None, {'name': 'joe', 'age': 12})
44  
-    assert_equal(r1, r2)
  46
+    assert_equal(r1, r2)
  47
+    
  48
+def test_findall_invalid_attribute():
  49
+    # Make sure findall with an invalid attribute doesn't cause errors.
  50
+    # The following should not raise an exception.
  51
+    cs.flavors.findall(vegetable='carrot')
  52
+    
  53
+    # However, find() should raise an error
  54
+    assert_raises(NotFound, cs.flavors.find, vegetable='carrot')
10  tests/test_shell.py
@@ -2,6 +2,7 @@
2 2
 
3 3
 import os
4 4
 import mock
  5
+import httplib2
5 6
 from nose.tools import assert_raises
6 7
 from cloudservers.shell import CloudserversShell, CommandError
7 8
 from .fakeserver import FakeServer
@@ -13,7 +14,7 @@ def setup():
13 14
         'CLOUD_SERVERS_USERNAME': 'username',
14 15
         'CLOUD_SERVERS_API_KEY': 'password'
15 16
     }
16  
-    _old_env, os.environ = os.environ, fake_env
  17
+    _old_env, os.environ = os.environ, fake_env.copy()
17 18
 
18 19
     # Make a fake shell object, a helping wrapper to call it, and a quick way
19 20
     # of asserting that certain API calls were made.
@@ -181,4 +182,9 @@ def test_help():
181 182
     with mock.patch_object(_shell.subcommands['delete'], 'print_help') as m:
182 183
         shell('help delete')
183 184
         m.assert_called()
184  
-    assert_raises(CommandError, shell, 'help foofoo')
  185
+    assert_raises(CommandError, shell, 'help foofoo')
  186
+
  187
+def test_debug():
  188
+    httplib2.debuglevel = 0
  189
+    shell('--debug list')
  190
+    assert httplib2.debuglevel == 1

0 notes on commit 42b3765

Please sign in to comment.
Something went wrong with that request. Please try again.