
* Scenario methods now use @with_default_task_id which initialize the task_id parameter: it sets task_id to the 'RALLY_TASK' env var available in the global file ~/.rally/globals * Added @with_default_task_id global to use @default_from_global decorator with task_id, so we can use directly @with_default_task_id and don't have to use @default_from_global that requires parameters. Implements blueprint: cli-use-task-subcommand Change-Id: I3fdd80b0fa89354ba24aa78b2b7db84d8a6d58c1
66 lines
2.7 KiB
Python
66 lines
2.7 KiB
Python
# 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 mock
|
|
import os
|
|
|
|
from rally.cmd import envutils
|
|
from rally import exceptions
|
|
from tests import test
|
|
|
|
|
|
class EnvUtilsTestCase(test.TestCase):
|
|
|
|
@mock.patch.dict(os.environ, values={'RALLY_DEPLOYMENT': 'my_deploy_id'},
|
|
clear=True)
|
|
def test_get_deployment_id_in_env(self):
|
|
deploy_id = envutils.get_global('RALLY_DEPLOYMENT')
|
|
self.assertEqual('my_deploy_id', deploy_id)
|
|
|
|
@mock.patch.dict(os.environ, values={}, clear=True)
|
|
@mock.patch('rally.cmd.envutils.fileutils.load_env_file')
|
|
def test_get_deployment_id_with_exception(self, mock_file):
|
|
self.assertRaises(exceptions.InvalidArgumentsException,
|
|
envutils.get_global, 'RALLY_DEPLOYMENT', True)
|
|
mock_file.assert_called_once_with(os.path.expanduser(
|
|
'~/.rally/globals'))
|
|
|
|
@mock.patch.dict(os.environ, values={}, clear=True)
|
|
@mock.patch('rally.cmd.envutils.fileutils.load_env_file')
|
|
def test_get_deployment_id_with_none(self, mock_file):
|
|
self.assertEqual(None, envutils.get_global('RALLY_DEPLOYMENT'))
|
|
mock_file.assert_called_once_with(os.path.expanduser(
|
|
'~/.rally/globals'))
|
|
|
|
@mock.patch.dict(os.environ, values={'RALLY_TASK': 'my_task_id'},
|
|
clear=True)
|
|
def test_get_task_id_in_env(self):
|
|
self.assertEqual('my_task_id', envutils.get_global('RALLY_TASK'))
|
|
|
|
@mock.patch.dict(os.environ, values={}, clear=True)
|
|
@mock.patch('rally.cmd.envutils.fileutils.load_env_file')
|
|
def test_get_task_id_with_exception(self, mock_file):
|
|
self.assertRaises(exceptions.InvalidArgumentsException,
|
|
envutils.get_global, 'RALLY_TASK', True)
|
|
mock_file.assert_called_once_with(os.path.expanduser(
|
|
'~/.rally/globals'))
|
|
|
|
@mock.patch.dict(os.environ, values={}, clear=True)
|
|
@mock.patch('rally.cmd.envutils.fileutils.load_env_file')
|
|
def test_get_task_id_with_none(self, mock_file):
|
|
self.assertEqual(None, envutils.get_global('RALLY_TASK'))
|
|
mock_file.assert_called_once_with(os.path.expanduser(
|
|
'~/.rally/globals'))
|