| 1 |
# |
| 2 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 3 |
# not use this file except in compliance with the License. You may obtain |
| 4 |
# a copy of the License at |
| 5 |
# |
| 6 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 |
# |
| 8 |
# Unless required by applicable law or agreed to in writing, software |
| 9 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 10 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 11 |
# License for the specific language governing permissions and limitations |
| 12 |
# under the License. |
| 13 |
|
| 14 |
from seamicroclient import base |
| 15 |
from seamicroclient.tests import utils |
| 16 |
from seamicroclient.tests.v2 import fakes |
| 17 |
from seamicroclient.v2 import servers |
| 18 |
|
| 19 |
|
| 20 |
cs = fakes.FakeClient() |
| 21 |
|
| 22 |
|
| 23 |
class BaseTest(utils.TestCase): |
| 24 |
|
| 25 |
def test_resource_repr(self): |
| 26 |
r = base.Resource(None, dict(foo="bar", baz="spam")) |
| 27 |
self.assertEqual(repr(r), "<Resource baz=spam, foo=bar>") |
| 28 |
|
| 29 |
def test_getid(self): |
| 30 |
self.assertEqual(base.getid(4), 4) |
| 31 |
|
| 32 |
class TmpObject(object): |
| 33 |
id = 4 |
| 34 |
self.assertEqual(base.getid(TmpObject), 4) |
| 35 |
|
| 36 |
def test_resource_lazy_getattr(self): |
| 37 |
f = servers.Server(cs.servers, {'id': 1}) |
| 38 |
self.assertEqual(f.name, 'sample-server') |
| 39 |
cs.assert_called('GET', '/servers/1') |
| 40 |
|
| 41 |
# Missing stuff still fails after a second get |
| 42 |
self.assertRaises(AttributeError, getattr, f, 'blahblah') |
| 43 |
|
| 44 |
def test_eq(self): |
| 45 |
# Two resources of the same type with the same id: equal |
| 46 |
r1 = base.Resource(None, {'id': 1, 'name': 'hi'}) |
| 47 |
r2 = base.Resource(None, {'id': 1, 'name': 'hello'}) |
| 48 |
self.assertEqual(r1, r2) |
| 49 |
|
| 50 |
# Two resoruces of different types: never equal |
| 51 |
r1 = base.Resource(None, {'id': 1}) |
| 52 |
r2 = servers.Server(None, {'id': 1}) |
| 53 |
self.assertNotEqual(r1, r2) |
| 54 |
|
| 55 |
# Two resources with no ID: equal if their info is equal |
| 56 |
r1 = base.Resource(None, {'name': 'joe', 'age': 12}) |
| 57 |
r2 = base.Resource(None, {'name': 'joe', 'age': 12}) |
| 58 |
self.assertEqual(r1, r2) |