def test__consume_attrs(self): serverside_key1 = "someKey1" clientside_key1 = "some_key1" serverside_key2 = "someKey2" clientside_key2 = "some_key2" value1 = "value1" value2 = "value2" mapping = {clientside_key1: serverside_key1, clientside_key2: serverside_key2} other_key = "otherKey" other_value = "other" attrs = {clientside_key1: value1, serverside_key2: value2, other_key: other_value} sot = resource2.Resource() result = sot._consume_attrs(mapping, attrs) # Make sure that the expected key was consumed and we're only # left with the other stuff. self.assertDictEqual({other_key: other_value}, attrs) # Make sure that after we've popped our relevant client-side # key off that we are returning it keyed off of its server-side # name. self.assertDictEqual({serverside_key1: value1, serverside_key2: value2}, result)
def test_initialize_basic(self): body = {"body": 1} header = {"header": 2} uri = {"uri": 3} everything = dict(itertools.chain(body.items(), header.items(), uri.items())) mock_collect = mock.Mock() mock_collect.return_value = body, header, uri with mock.patch.object(resource2.Resource, "_collect_attrs", mock_collect): sot = resource2.Resource(synchronized=False, **everything) mock_collect.assert_called_once_with(everything) self.assertIsInstance(sot._body, resource2._ComponentManager) self.assertEqual(body, sot._body.dirty) self.assertIsInstance(sot._header, resource2._ComponentManager) self.assertEqual(header, sot._header.dirty) self.assertIsInstance(sot._uri, resource2._ComponentManager) self.assertEqual(uri, sot._uri.dirty) self.assertFalse(sot.allow_create) self.assertFalse(sot.allow_get) self.assertFalse(sot.allow_update) self.assertFalse(sot.allow_delete) self.assertFalse(sot.allow_list) self.assertFalse(sot.allow_head) self.assertFalse(sot.patch_update) self.assertFalse(sot.put_create)
def setUp(self): super(TestProxyList, self).setUp() self.session = mock.Mock() self.args = {"a": "A", "b": "B", "c": "C"} self.fake_response = [resource2.Resource()] self.sot = proxy2.BaseProxy(self.session) ListableResource.list = mock.Mock() ListableResource.list.return_value = self.fake_response
def test__collect_attrs(self): sot = resource2.Resource() expected_attrs = ["body", "header", "uri"] sot._consume_attrs = mock.Mock() sot._consume_attrs.side_effect = expected_attrs # It'll get passed an empty dict at the least. actual_attrs = sot._collect_attrs(dict()) self.assertItemsEqual(expected_attrs, actual_attrs)
def test__filter_component(self): client_name = "client_name" server_name = "serverName" value = "value" # Include something in the mapping that we don't receive # so the branch that looks at existence in the compoment is checked. mapping = {client_name: server_name, "other": "blah"} component = {server_name: value, "something": "else"} sot = resource2.Resource() result = sot._filter_component(component, mapping) # The something:else mapping should not make it into here. self.assertEqual({server_name: value}, result)
def test__update(self): sot = resource2.Resource() body = "body" header = "header" uri = "uri" sot._collect_attrs = mock.Mock(return_value=(body, header, uri)) sot._body.update = mock.Mock() sot._header.update = mock.Mock() sot._uri.update = mock.Mock() args = {"arg": 1} sot._update(**args) sot._collect_attrs.assert_called_once_with(args) sot._body.update.assert_called_once_with(body) sot._header.update.assert_called_once_with(header) sot._uri.update.assert_called_once_with(uri)
def test__check_resource_correct_resource(self): res = resource2.Resource() self._test_correct(res)
def test__prepare_request_missing_id(self): sot = resource2.Resource(id=None) self.assertRaises(exceptions.InvalidRequest, sot._prepare_request, requires_id=True)