Clean imports in code
In some part in the code we import objects. In the Openstack style guidelines they recommend to import only modules. http://docs.openstack.org/developer/hacking/#imports Change-Id: I80c70abd2f6973e1285eb7af2871d40d0a276712
This commit is contained in:
parent
58d92abb16
commit
79a6914961
@ -22,7 +22,7 @@ from murano.common.i18n import _, _LE
|
|||||||
from murano.common import policy
|
from murano.common import policy
|
||||||
from murano.common import utils
|
from murano.common import utils
|
||||||
from murano.common import wsgi
|
from murano.common import wsgi
|
||||||
from murano.db.models import EnvironmentTemplate
|
from murano.db import models
|
||||||
from murano.db.services import core_services
|
from murano.db.services import core_services
|
||||||
from murano.db.services import environment_templates as env_temps
|
from murano.db.services import environment_templates as env_temps
|
||||||
from murano.db.services import environments as envs
|
from murano.db.services import environments as envs
|
||||||
@ -59,8 +59,8 @@ class Controller(object):
|
|||||||
get_env_templates_by(filters)
|
get_env_templates_by(filters)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
filters = (EnvironmentTemplate.is_public,
|
filters = (models.EnvironmentTemplate.is_public,
|
||||||
EnvironmentTemplate.tenant_id == tenant_id)
|
models.EnvironmentTemplate.tenant_id == tenant_id)
|
||||||
list_templates = env_temps.EnvTemplateServices.\
|
list_templates = env_temps.EnvTemplateServices.\
|
||||||
get_env_templates_or_by(filters)
|
get_env_templates_or_by(filters)
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ from oslo_db import options
|
|||||||
from oslo_db.sqlalchemy import session as db_session
|
from oslo_db.sqlalchemy import session as db_session
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
|
|
||||||
from murano.db.models import Lock
|
from murano.db import models
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
|
||||||
@ -68,11 +68,11 @@ def _get_or_create_lock(name, session, nested, retry=0):
|
|||||||
session.begin_nested()
|
session.begin_nested()
|
||||||
else:
|
else:
|
||||||
session.begin()
|
session.begin()
|
||||||
existing = session.query(Lock).get(name)
|
existing = session.query(models.Lock).get(name)
|
||||||
if existing is None:
|
if existing is None:
|
||||||
try:
|
try:
|
||||||
# no lock found, creating a new one
|
# no lock found, creating a new one
|
||||||
lock = Lock(id=name, ts=timeutils.utcnow())
|
lock = models.Lock(id=name, ts=timeutils.utcnow())
|
||||||
lock.save(session)
|
lock.save(session)
|
||||||
return session.transaction
|
return session.transaction
|
||||||
# lock created and acquired
|
# lock created and acquired
|
||||||
|
@ -13,9 +13,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from mock import ANY
|
import mock
|
||||||
from mock import MagicMock
|
|
||||||
from mock.mock import call
|
|
||||||
|
|
||||||
from murano.dsl import helpers
|
from murano.dsl import helpers
|
||||||
from murano.engine.system import logger
|
from murano.engine.system import logger
|
||||||
@ -26,12 +24,12 @@ from murano.tests.unit.dsl.foundation import test_case
|
|||||||
class TestLogger(test_case.DslTestCase):
|
class TestLogger(test_case.DslTestCase):
|
||||||
|
|
||||||
FORMAT_CALLS = [
|
FORMAT_CALLS = [
|
||||||
call(ANY, 'str', (), {}),
|
mock.call(mock.ANY, 'str', (), {}),
|
||||||
call(ANY, u'тест', (), {}),
|
mock.call(mock.ANY, u'тест', (), {}),
|
||||||
call(ANY, 'str', (1,), {}),
|
mock.call(mock.ANY, 'str', (1,), {}),
|
||||||
call(ANY, 'str {0}', ('message',), {}),
|
mock.call(mock.ANY, 'str {0}', ('message',), {}),
|
||||||
call(ANY, 'str {message}', (), {'message': 'message'}),
|
mock.call(mock.ANY, 'str {message}', (), {'message': 'message'}),
|
||||||
call(ANY, 'str {message}{0}', (), {})]
|
mock.call(mock.ANY, 'str {message}{0}', (), {})]
|
||||||
|
|
||||||
LOG_CALLS = FORMAT_CALLS
|
LOG_CALLS = FORMAT_CALLS
|
||||||
|
|
||||||
@ -51,14 +49,14 @@ class TestLogger(test_case.DslTestCase):
|
|||||||
logger_instance = self._runner.testCreate()
|
logger_instance = self._runner.testCreate()
|
||||||
logger_ext = logger_instance.extension
|
logger_ext = logger_instance.extension
|
||||||
|
|
||||||
underlying_logger_mock = MagicMock()
|
underlying_logger_mock = mock.MagicMock()
|
||||||
logger_ext._underlying_logger = underlying_logger_mock
|
logger_ext._underlying_logger = underlying_logger_mock
|
||||||
logger_ext._underlying_logger.return_value = None
|
logger_ext._underlying_logger.return_value = None
|
||||||
|
|
||||||
format_mock = MagicMock(return_value='format_mock')
|
format_mock = mock.MagicMock(return_value='format_mock')
|
||||||
# do not verify number of conversions to string
|
# do not verify number of conversions to string
|
||||||
format_mock.__str__ = MagicMock(return_value='format_mock')
|
format_mock.__str__ = mock.MagicMock(return_value='format_mock')
|
||||||
format_mock.__unicode__ = MagicMock(return_value='format_mock')
|
format_mock.__unicode__ = mock.MagicMock(return_value='format_mock')
|
||||||
|
|
||||||
logger_ext._format_without_exceptions = format_mock
|
logger_ext._format_without_exceptions = format_mock
|
||||||
|
|
||||||
@ -67,7 +65,7 @@ class TestLogger(test_case.DslTestCase):
|
|||||||
def test_trace(self):
|
def test_trace(self):
|
||||||
logger_instance, format_mock, underlying_logger_mock \
|
logger_instance, format_mock, underlying_logger_mock \
|
||||||
= self._create_logger_mock()
|
= self._create_logger_mock()
|
||||||
log_method = MagicMock()
|
log_method = mock.MagicMock()
|
||||||
|
|
||||||
underlying_logger_mock.trace = log_method
|
underlying_logger_mock.trace = log_method
|
||||||
self._runner.testTrace(logger_instance)
|
self._runner.testTrace(logger_instance)
|
||||||
@ -78,7 +76,7 @@ class TestLogger(test_case.DslTestCase):
|
|||||||
def test_debug(self):
|
def test_debug(self):
|
||||||
logger_instance, format_mock, underlying_logger_mock \
|
logger_instance, format_mock, underlying_logger_mock \
|
||||||
= self._create_logger_mock()
|
= self._create_logger_mock()
|
||||||
log_method = MagicMock()
|
log_method = mock.MagicMock()
|
||||||
|
|
||||||
underlying_logger_mock.debug = log_method
|
underlying_logger_mock.debug = log_method
|
||||||
self._runner.testDebug(logger_instance)
|
self._runner.testDebug(logger_instance)
|
||||||
@ -89,7 +87,7 @@ class TestLogger(test_case.DslTestCase):
|
|||||||
def test_info(self):
|
def test_info(self):
|
||||||
logger_instance, format_mock, underlying_logger_mock \
|
logger_instance, format_mock, underlying_logger_mock \
|
||||||
= self._create_logger_mock()
|
= self._create_logger_mock()
|
||||||
log_method = MagicMock()
|
log_method = mock.MagicMock()
|
||||||
|
|
||||||
underlying_logger_mock.info = log_method
|
underlying_logger_mock.info = log_method
|
||||||
self._runner.testInfo(logger_instance)
|
self._runner.testInfo(logger_instance)
|
||||||
@ -100,7 +98,7 @@ class TestLogger(test_case.DslTestCase):
|
|||||||
def test_warning(self):
|
def test_warning(self):
|
||||||
logger_instance, format_mock, underlying_logger_mock \
|
logger_instance, format_mock, underlying_logger_mock \
|
||||||
= self._create_logger_mock()
|
= self._create_logger_mock()
|
||||||
log_method = MagicMock()
|
log_method = mock.MagicMock()
|
||||||
|
|
||||||
underlying_logger_mock.warning = log_method
|
underlying_logger_mock.warning = log_method
|
||||||
self._runner.testWarning(logger_instance)
|
self._runner.testWarning(logger_instance)
|
||||||
@ -111,7 +109,7 @@ class TestLogger(test_case.DslTestCase):
|
|||||||
def test_error(self):
|
def test_error(self):
|
||||||
logger_instance, format_mock, underlying_logger_mock \
|
logger_instance, format_mock, underlying_logger_mock \
|
||||||
= self._create_logger_mock()
|
= self._create_logger_mock()
|
||||||
log_method = MagicMock()
|
log_method = mock.MagicMock()
|
||||||
|
|
||||||
underlying_logger_mock.error = log_method
|
underlying_logger_mock.error = log_method
|
||||||
self._runner.testError(logger_instance)
|
self._runner.testError(logger_instance)
|
||||||
@ -122,7 +120,7 @@ class TestLogger(test_case.DslTestCase):
|
|||||||
def test_critical(self):
|
def test_critical(self):
|
||||||
logger_instance, format_mock, underlying_logger_mock \
|
logger_instance, format_mock, underlying_logger_mock \
|
||||||
= self._create_logger_mock()
|
= self._create_logger_mock()
|
||||||
log_method = MagicMock()
|
log_method = mock.MagicMock()
|
||||||
|
|
||||||
underlying_logger_mock.critical = log_method
|
underlying_logger_mock.critical = log_method
|
||||||
self._runner.testCritical(logger_instance)
|
self._runner.testCritical(logger_instance)
|
||||||
@ -133,7 +131,7 @@ class TestLogger(test_case.DslTestCase):
|
|||||||
def test_exception(self):
|
def test_exception(self):
|
||||||
logger_instance, format_mock, underlying_logger_mock = \
|
logger_instance, format_mock, underlying_logger_mock = \
|
||||||
self._create_logger_mock()
|
self._create_logger_mock()
|
||||||
log_method = MagicMock()
|
log_method = mock.MagicMock()
|
||||||
|
|
||||||
underlying_logger_mock.error = log_method
|
underlying_logger_mock.error = log_method
|
||||||
self._runner.testException(logger_instance)
|
self._runner.testException(logger_instance)
|
||||||
|
Loading…
Reference in New Issue
Block a user