~ubuntu-branches/ubuntu/saucy/python-cinderclient/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/test_base.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-06-27 13:32:14 UTC
  • Revision ID: package-import@ubuntu.com-20120627133214-n2gx1yxu97efvhg8
Tags: upstream-2012.2~f1~20120621.8
ImportĀ upstreamĀ versionĀ 2012.2~f1~20120621.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from cinderclient import base
 
2
from cinderclient import exceptions
 
3
from cinderclient.v1 import volumes
 
4
from tests import utils
 
5
from tests.v1 import fakes
 
6
 
 
7
 
 
8
cs = fakes.FakeClient()
 
9
 
 
10
 
 
11
class BaseTest(utils.TestCase):
 
12
 
 
13
    def test_resource_repr(self):
 
14
        r = base.Resource(None, dict(foo="bar", baz="spam"))
 
15
        self.assertEqual(repr(r), "<Resource baz=spam, foo=bar>")
 
16
 
 
17
    def test_getid(self):
 
18
        self.assertEqual(base.getid(4), 4)
 
19
 
 
20
        class TmpObject(object):
 
21
            id = 4
 
22
        self.assertEqual(base.getid(TmpObject), 4)
 
23
 
 
24
    def test_eq(self):
 
25
        # Two resources of the same type with the same id: equal
 
26
        r1 = base.Resource(None, {'id': 1, 'name': 'hi'})
 
27
        r2 = base.Resource(None, {'id': 1, 'name': 'hello'})
 
28
        self.assertEqual(r1, r2)
 
29
 
 
30
        # Two resoruces of different types: never equal
 
31
        r1 = base.Resource(None, {'id': 1})
 
32
        r2 = volumes.Volume(None, {'id': 1})
 
33
        self.assertNotEqual(r1, r2)
 
34
 
 
35
        # Two resources with no ID: equal if their info is equal
 
36
        r1 = base.Resource(None, {'name': 'joe', 'age': 12})
 
37
        r2 = base.Resource(None, {'name': 'joe', 'age': 12})
 
38
        self.assertEqual(r1, r2)
 
39
 
 
40
    def test_findall_invalid_attribute(self):
 
41
        # Make sure findall with an invalid attribute doesn't cause errors.
 
42
        # The following should not raise an exception.
 
43
        cs.volumes.findall(vegetable='carrot')
 
44
 
 
45
        # However, find() should raise an error
 
46
        self.assertRaises(exceptions.NotFound,
 
47
                          cs.volumes.find,
 
48
                          vegetable='carrot')