From 77f06d5425d4c9ea14c1278b7240278994e9d285 Mon Sep 17 00:00:00 2001 From: Rahul Nair Date: Thu, 15 Sep 2016 19:10:23 -0500 Subject: [PATCH] Adding unittests for glance client Adding unittest for glance client extension. Change-Id: Id51cd81d1a5f1d24a0362d6d38b4186409567d11 --- tests/unit/test_glance_client.py | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/unit/test_glance_client.py diff --git a/tests/unit/test_glance_client.py b/tests/unit/test_glance_client.py new file mode 100644 index 00000000..bc07b600 --- /dev/null +++ b/tests/unit/test_glance_client.py @@ -0,0 +1,49 @@ +# Copyright 2016 Intel +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import mock +import testtools + +from syntribos.extensions.glance import client + + +class _Image_meta_data(): + def __init__(self): + self.id = 1234 + + +class _Images(): + + def create(self, name): + return _Image_meta_data() + + def list(data): + return [] + + +class _FakeGlance(): + """Fake glance client object.""" + images = _Images() + + +def fake_get_client(): + return _FakeGlance() + + +class TestGlanceClientCreateResources(testtools.TestCase): + """Tests all getter methods for glance extension client.""" + + @mock.patch("syntribos.extensions.glance.client._get_client", + side_effect=fake_get_client) + def test_get_image_id(self, get_client_fn): + self.assertEqual(1234, client.get_image_id())