def test_get_stats_gets_the_client_stats(self): expected_stats = ['s1', 's2', 's3'] mock = Mock(spec=Client) mock.stats.return_value = expected_stats wrapper = DockerClientWrapper(mock) actual = wrapper.get_stats('c1', 3) self.assertEqual(expected_stats, [stat for time, stat in actual])
def test_get_stats_gets_requested_number_of_stats_from_the_client(self): mock = Mock(spec=Client) mock.stats.return_value = map(lambda i: "s{0}".format(i), range(0, 100000)) expected = ["s0", "s1", "s2"] wrapper = DockerClientWrapper(mock) actual = wrapper.get_stats('c1', 3) self.assertEqual(expected, [stat for time, stat in actual])
def test_get_stats_return_empty_list_on_timeout(self): mock = Mock() mock.stats.side_effect = ReadTimeoutError('pool', 'url', 'message') wrapper = DockerClientWrapper(mock) actual = wrapper.get_stats('c1', 3) self.assertEqual([], [stat for time, stat in actual])
def test_get_stats_return_empty_list_on_api_error(self): mock = Mock() mock.stats.side_effect = APIError("boom", "boom", "boom") wrapper = DockerClientWrapper(mock) actual = wrapper.get_stats('c1', 3) self.assertEqual([], [stat for time, stat in actual])