openstacksdk/shade/tests/unit/test_usage.py
Morgan Fainberg 76a01bf851 Remove mock of keystone where single projects are consumed
Any case that mocked keystoneclient for simple get of a single
project has been updated to now use requests mock. This change
required some minor adjusting to the base RequestMock test case
to make it easy to mock out for projects without needing to
duplicate a ton of code.

Change-Id: Ic19ec7ea199759a0aa69d107636fadbaf27dae5e
2017-02-12 15:16:32 -08:00

34 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
# 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 datetime
import mock
import shade
from shade.tests.unit import base
class TestUsage(base.RequestsMockTestCase):
@mock.patch.object(shade.OpenStackCloud, 'nova_client')
def test_get_usage(self, mock_nova):
self._add_discovery_uri_call()
project = self.mock_for_keystone_projects(project_count=1,
list_get=True)[0]
start = end = datetime.datetime.now()
self.op_cloud.get_compute_usage(project.project_id, start, end)
mock_nova.usage.get.assert_called_once_with(
start=start, end=end, tenant_id=project.project_id)
self.assert_calls()