|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | +# not use this file except in compliance with the License. You may obtain |
| 3 | +# a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations |
| 11 | +# under the License. |
| 12 | +# |
| 13 | + |
| 14 | +"""Test Timing pseudo-command""" |
| 15 | + |
| 16 | +from openstackclient.common import timing |
| 17 | +from openstackclient.tests import fakes |
| 18 | +from openstackclient.tests import utils |
| 19 | + |
| 20 | + |
| 21 | +timing_url = 'GET http://localhost:5000' |
| 22 | +timing_start = 1404802774.872809 |
| 23 | +timing_end = 1404802775.724802 |
| 24 | + |
| 25 | + |
| 26 | +class FakeGenericClient(object): |
| 27 | + |
| 28 | + def __init__(self, **kwargs): |
| 29 | + self.auth_token = kwargs['token'] |
| 30 | + self.management_url = kwargs['endpoint'] |
| 31 | + |
| 32 | + |
| 33 | +class TestTiming(utils.TestCommand): |
| 34 | + |
| 35 | + def setUp(self): |
| 36 | + super(TestTiming, self).setUp() |
| 37 | + |
| 38 | + self.app.timing_data = [] |
| 39 | + |
| 40 | + self.app.client_manager.compute = FakeGenericClient( |
| 41 | + endpoint=fakes.AUTH_URL, |
| 42 | + token=fakes.AUTH_TOKEN, |
| 43 | + ) |
| 44 | + |
| 45 | + self.app.client_manager.volume = FakeGenericClient( |
| 46 | + endpoint=fakes.AUTH_URL, |
| 47 | + token=fakes.AUTH_TOKEN, |
| 48 | + ) |
| 49 | + |
| 50 | + # Get the command object to test |
| 51 | + self.cmd = timing.Timing(self.app, None) |
| 52 | + |
| 53 | + def test_timing_list_no_data(self): |
| 54 | + arglist = [] |
| 55 | + verifylist = [] |
| 56 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 57 | + |
| 58 | + # DisplayCommandBase.take_action() returns two tuples |
| 59 | + columns, data = self.cmd.take_action(parsed_args) |
| 60 | + |
| 61 | + collist = ('URL', 'Seconds') |
| 62 | + self.assertEqual(collist, columns) |
| 63 | + datalist = [ |
| 64 | + ('Total', 0.0,) |
| 65 | + ] |
| 66 | + self.assertEqual(datalist, data) |
| 67 | + |
| 68 | + def test_timing_list(self): |
| 69 | + self.app.timing_data = [ |
| 70 | + (timing_url, timing_start, timing_end), |
| 71 | + ] |
| 72 | + |
| 73 | + arglist = [] |
| 74 | + verifylist = [] |
| 75 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 76 | + |
| 77 | + # DisplayCommandBase.take_action() returns two tuples |
| 78 | + columns, data = self.cmd.take_action(parsed_args) |
| 79 | + |
| 80 | + collist = ('URL', 'Seconds') |
| 81 | + self.assertEqual(collist, columns) |
| 82 | + timing_sec = timing_end - timing_start |
| 83 | + datalist = [ |
| 84 | + (timing_url, timing_sec), |
| 85 | + ('Total', timing_sec) |
| 86 | + ] |
| 87 | + self.assertEqual(datalist, data) |
0 commit comments