
Reasons: - code should be pythonicaly clean, that is why number of ignored rules should reduced Changes: - E125, F811, H102, H103, F201, H23, H302, F841, H301, H702, H703 rules are now enabled Change-Id: Ibf4025162244d3c2f1278b49a76ec1527a729042
132 lines
4.6 KiB
Python
132 lines
4.6 KiB
Python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
# Copyright 2011 OpenStack Foundation
|
|
# Copyright 2013 Mirantis, Inc.
|
|
# All Rights Reserved.
|
|
#
|
|
# 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 testtools
|
|
import mock
|
|
|
|
from troveclient.v1 import datastores
|
|
from troveclient import base
|
|
|
|
|
|
"""
|
|
Unit tests for datastores.py
|
|
"""
|
|
|
|
|
|
class DatastoreTest(testtools.TestCase):
|
|
|
|
def setUp(self):
|
|
super(DatastoreTest, self).setUp()
|
|
self.orig__init = datastores.Datastore.__init__
|
|
datastores.Datastore.__init__ = mock.Mock(return_value=None)
|
|
self.datastore = datastores.Datastore()
|
|
self.datastore.manager = mock.Mock()
|
|
|
|
def tearDown(self):
|
|
super(DatastoreTest, self).tearDown()
|
|
datastores.Datastore.__init__ = self.orig__init
|
|
|
|
def test___repr__(self):
|
|
self.datastore.name = "datastore-1"
|
|
self.assertEqual('<Datastore: datastore-1>',
|
|
self.datastore.__repr__())
|
|
|
|
|
|
class DatastoresTest(testtools.TestCase):
|
|
|
|
def setUp(self):
|
|
super(DatastoresTest, self).setUp()
|
|
self.orig__init = datastores.Datastores.__init__
|
|
datastores.Datastores.__init__ = mock.Mock(return_value=None)
|
|
self.datastores = datastores.Datastores()
|
|
self.datastores.api = mock.Mock()
|
|
self.datastores.api.client = mock.Mock()
|
|
self.datastores.resource_class = mock.Mock(return_value="ds-1")
|
|
|
|
self.orig_base_getid = base.getid
|
|
base.getid = mock.Mock(return_value="datastore1")
|
|
|
|
def tearDown(self):
|
|
super(DatastoresTest, self).tearDown()
|
|
datastores.Datastores.__init__ = self.orig__init
|
|
base.getid = self.orig_base_getid
|
|
|
|
def test_list(self):
|
|
def side_effect_func(path, inst, limit, marker):
|
|
return path, inst, limit, marker
|
|
|
|
self.datastores._list = mock.Mock(side_effect=side_effect_func)
|
|
limit = "test-limit"
|
|
marker = "test-marker"
|
|
expected = ("/datastores", "datastores", limit, marker)
|
|
self.assertEqual(expected, self.datastores.list(limit, marker))
|
|
|
|
def test_get(self):
|
|
def side_effect_func(path, inst):
|
|
return path, inst
|
|
|
|
self.datastores._get = mock.Mock(side_effect=side_effect_func)
|
|
self.assertEqual(('/datastores/datastore1',
|
|
'datastore'),
|
|
self.datastores.get(1))
|
|
|
|
|
|
class DatastoreVersionsTest(testtools.TestCase):
|
|
|
|
def setUp(self):
|
|
super(DatastoreVersionsTest, self).setUp()
|
|
self.orig__init = datastores.DatastoreVersions.__init__
|
|
datastores.DatastoreVersions.__init__ = mock.Mock(return_value=None)
|
|
self.datastore_versions = datastores.DatastoreVersions()
|
|
self.datastore_versions.api = mock.Mock()
|
|
self.datastore_versions.api.client = mock.Mock()
|
|
self.datastore_versions.resource_class = mock.Mock(
|
|
return_value="ds_version-1")
|
|
|
|
self.orig_base_getid = base.getid
|
|
base.getid = mock.Mock(return_value="datastore_version1")
|
|
|
|
def tearDown(self):
|
|
super(DatastoreVersionsTest, self).tearDown()
|
|
datastores.DatastoreVersions.__init__ = self.orig__init
|
|
base.getid = self.orig_base_getid
|
|
|
|
def test_list(self):
|
|
def side_effect_func(path, inst, limit, marker):
|
|
return path, inst, limit, marker
|
|
|
|
self.datastore_versions._list = mock.Mock(side_effect=side_effect_func)
|
|
limit = "test-limit"
|
|
marker = "test-marker"
|
|
expected = ("/datastores/datastore1/versions",
|
|
"versions", limit, marker)
|
|
self.assertEqual(expected, self.datastore_versions.list(
|
|
"datastore1", limit, marker))
|
|
|
|
def test_get(self):
|
|
def side_effect_func(path, inst):
|
|
return path, inst
|
|
|
|
self.datastore_versions._get = mock.Mock(side_effect=side_effect_func)
|
|
self.assertEqual(('/datastores/datastore1/versions/'
|
|
'datastore_version1',
|
|
'version'),
|
|
self.datastore_versions.get("datastore1",
|
|
"datastore_version1"))
|