예제 #1
0
    def test_eq(self):
        # Two resources of the same type with the same id: not equal
        r1 = base.Resource(None, {'id': 1, 'name': 'hi'})
        r2 = base.Resource(None, {'id': 1, 'name': 'hello'})
        self.assertNotEqual(r1, r2)

        # Two resources of different types: never equal
        r1 = base.Resource(None, {'id': 1})
        r2 = fakes.FakeResource(None, {'id': 1})
        self.assertNotEqual(r1, r2)

        # Two resources with no ID: equal if their info is equal
        r1 = base.Resource(None, {'name': 'joe', 'age': 12})
        r2 = base.Resource(None, {'name': 'joe', 'age': 12})
        self.assertEqual(r1, r2)
예제 #2
0
    def test_resource_lazy_getattr(self):
        fake_manager = mock.Mock()
        return_resource = base.Resource(
            None, dict(uuid=mock.sentinel.fake_id, foo='bar',
                       name='fake_name'))
        fake_manager.get.return_value = return_resource

        r = base.Resource(fake_manager,
                          dict(uuid=mock.sentinel.fake_id, foo='bar'))
        self.assertTrue(hasattr(r, 'foo'))
        self.assertEqual('bar', r.foo)
        self.assertFalse(r.is_loaded())

        # Trigger load
        self.assertEqual('fake_name', r.name)
        fake_manager.get.assert_called_once_with(mock.sentinel.fake_id)
        self.assertTrue(r.is_loaded())

        # Missing stuff still fails after a second get
        self.assertRaises(AttributeError, getattr, r, 'blahblah')
예제 #3
0
 def test_resource_object_with_compute_request_ids(self):
     resp_obj = fakes.create_response_obj_with_compute_header()
     r = base.Resource(None, {'name': '1'}, resp=resp_obj)
     self.assertEqual(fakes.FAKE_REQUEST_ID_LIST, r.request_ids)
예제 #4
0
 def test_init_with_attribute_info(self):
     r = base.Resource(None, dict(foo='bar', baz='spam'))
     self.assertTrue(hasattr(r, 'foo'))
     self.assertEqual('bar', r.foo)
     self.assertTrue(hasattr(r, 'baz'))
     self.assertEqual('spam', r.baz)
예제 #5
0
 def test_resource_repr(self):
     r = base.Resource(None, dict(foo='bar', baz='spam'))
     self.assertEqual('<Resource baz=spam, foo=bar>', repr(r))