Files
rally/tests/benchmark/scenarios/keystone/test_basic.py
Boris Pavlovic a4e906dcfc Use cls instances instead of object in benchmarks
Using @classmethod as a base for scenarios was actually caused
by historical reasons (of using pytest as a base for benchmarks)
As we don't use it anymore (for a long time) we are able to simplify
benchmark framework and use cls instances and plain methods.

This is only the first step. That just make required changes and fix
unit tests. In next patchset I will refactor & clean exisitng unit tests.

blueprint refactor-scenarios-to-use-class-instances

Change-Id: Idd270635f70731ccf575174f8f96dc1e95cc0f8a
2014-01-23 18:15:42 +04:00

56 lines
2.2 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
from rally.benchmark.scenarios.keystone import basic
from tests import test
KEYSTONE_BASE = "rally.benchmark.scenarios.keystone."
KEYSTONE_BASIC = KEYSTONE_BASE + "basic.KeystoneBasic."
KEYSTONE_UTILS = KEYSTONE_BASE + "utils."
class KeystoneBasicTestCase(test.TestCase):
@mock.patch(KEYSTONE_UTILS + "generate_keystone_name")
def test_create_user(self, mock_gen_name):
scenario = basic.KeystoneBasic()
mock_gen_name.return_value = "teeeest"
scenario._user_create = mock.MagicMock()
scenario.create_user(name_length=20, password="tttt",
**{"tenant_id": "id"})
scenario._user_create.assert_called_once_with(name_length=20,
password="tttt",
**{"tenant_id": "id"})
@mock.patch(KEYSTONE_UTILS + "generate_keystone_name")
def test_create_delete_user(self, mock_gen_name):
create_result = mock.MagicMock()
scenario = basic.KeystoneBasic()
scenario._user_create = mock.MagicMock(return_value=create_result)
scenario._resource_delete = mock.MagicMock()
mock_gen_name.return_value = "teeeest"
scenario.create_delete_user(name_length=30, email="abcd",
**{"enabled": True})
scenario._user_create.assert_called_once_with(name_length=30,
email="abcd",
**{"enabled": True})
scenario._resource_delete.assert_called_once_with(create_result)