class GlanceClientTestCase(ValidatorTestCase):
    """Tests for class GlanceClient """

    def setUp(self):
        """Create a GlanceClient instance """
        super(GlanceClientTestCase, self).setUp()
        keystone_client = mock.MagicMock()
        CONF.set_override('endpoint', "1234", group='clients_glance')
        self.client = GlanceClient(keystone_client)
        self.client._client = mock.MagicMock()

    def test_list(self):
        """Tests for method list """
        self.client._client.images.list = mock.MagicMock()
        self.client._client.images.list.return_value = (mock.MagicMock()
                                                        for n in range(2))
        observed = tuple(self.client.list())
        expected = ("1", "2")
        self.assertEqual(len(expected), len(observed))

    def test_get_by_name(self):
        """Tests for method get_by_name """
        input = "MyInput"
        expected = None
        observed = self.client.get_by_name(input)
        self.assertEqual(expected, observed)

    def test_getById(self):
        """Tests for method getById """
        self.client._client.images.get.return_value = mock.MagicMock()
        expected = {"id": "myid", "name": "myname"}
        observed = self.client.getById("1234")
        self.assertEqual(len(expected.items()), len(observed.items()))

    def test_create_glance_client(self):
        """Tests for method create_glance_client """
        keystone_client = mock.MagicMock()
        keystone_client.auth_token = "1234"
        keystone_client.service_catalog = mock.MagicMock()
        self.client._client = mock.MagicMock()
        observed = self.client.create_glance_client(keystone_client)
        expected = None
        self.assertEqual(expected, observed)

    def tearDown(self):
        """Cleanup the GlanceClient instance """
        super(GlanceClientTestCase, self).tearDown()
        self.m.UnsetStubs()
        self.m.ResetAll()
 def setUp(self):
     """Create a GlanceClient instance """
     super(GlanceClientTestCase, self).setUp()
     keystone_client = mock.MagicMock()
     CONF.set_override('endpoint', "1234", group='clients_glance')
     self.client = GlanceClient(keystone_client)
     self.client._client = mock.MagicMock()