def test_can_send_version(self, mock_session): self.assertTrue(self.client.can_send_version('1.42')) self.client = client.Client(self.serializer, version_cap='1.42') self.assertTrue(self.client.can_send_version('1.42')) self.assertTrue(self.client.can_send_version('1.0')) self.assertFalse(self.client.can_send_version('1.99')) self.assertFalse(self.client.can_send_version('2.0'))
def test_call_failure_with_version_and_cap(self, mock_session): self.client = client.Client(self.serializer, version_cap='1.42') cctx = self.client.prepare('foo.example.com', version='1.99') self.assertRaisesRegex(RuntimeError, "requested version 1.99, maximum allowed " "version is 1.42", cctx.call, self.context, 'do_something', answer=42) self.assertFalse(mock_session.return_value.post.called)
def test_call_success_with_version_and_cap(self, mock_session): self.client = client.Client(self.serializer, version_cap='1.99') response = mock_session.return_value.post.return_value response.json.return_value = { 'jsonrpc': '2.0', 'result': 42 } cctx = self.client.prepare('foo.example.com', version='1.42') self.assertEqual('example.com', cctx.host) result = cctx.call(self.context, 'do_something', answer=42) self.assertEqual(42, result) mock_session.return_value.post.assert_called_once_with( 'http://example.com:8089', json={'jsonrpc': '2.0', 'method': 'do_something', 'params': {'answer': 42, 'context': self.ctx_json, 'rpc.version': '1.42'}, 'id': self.context.request_id})
def setUp(self): super(TestClient, self).setUp() self.serializer = objects_base.IronicObjectSerializer(is_server=True) self.client = client.Client(self.serializer) self.ctx_json = self.context.to_dict()