def test_response_unixtime_converted_to_isodate(self, mock_get_request): mock_response = Mock() mock_response.json.return_value = { 'summary': { 'hours': [{ 'starttime': 1356998400 }, { 'starttime': 1356998500 }] } } mock_get_request.return_value = mock_response pingdom = Pingdom(self.config) mock_check_id = Mock() mock_check_id.return_value = '12345' pingdom.check_id = mock_check_id uptime = pingdom.stats(check_name='Foo', start=date(2012, 12, 31), end=date(2013, 1, 1)) assert_that(uptime[0]['starttime'], is_(datetime(2013, 1, 1, 0, tzinfo=pytz.UTC))) assert_that(uptime[1]['starttime'], is_(datetime(2013, 1, 1, 0, 1, 40, tzinfo=pytz.UTC)))
def test_stats_returns_none_when_there_is_an_error(self, send_request): send_request.side_effect = requests.exceptions.HTTPError() pingdom = Pingdom(self.config) mock_check_id = Mock() mock_check_id.return_value = '12345' pingdom.check_id = mock_check_id uptime = pingdom.stats_for_24_hours(name="don't care", limit_time=date(2013, 1, 1)) assert_that(uptime, is_(None))
def test_stats_returns_none_when_there_is_an_error(self, send_request): send_request.side_effect = requests.exceptions.HTTPError() pingdom = Pingdom(self.config) mock_check_id = Mock() mock_check_id.return_value = '12345' pingdom.check_id = mock_check_id uptime = pingdom.stats(check_name="don't care", start=date(2012, 12, 31), end=date(2013, 1, 1)) assert_that(uptime, is_(None))
def test_response_unixtime_converted_to_isodate(self, mock_get_request): mock_response = Mock() mock_response.json.return_value = { 'summary': { 'hours': [{'starttime': 1356998400}, {'starttime': 1356998500}] } } mock_get_request.return_value = mock_response pingdom = Pingdom(self.config) mock_check_id = Mock() mock_check_id.return_value = '12345' pingdom.check_id = mock_check_id uptime = pingdom.stats_for_24_hours(name='Foo', limit_time=date(2013, 1, 1)) assert_that(uptime[0]['starttime'], is_(datetime(2013, 1, 1, 0, tzinfo=pytz.UTC))) assert_that(uptime[1]['starttime'], is_(datetime(2013, 1, 1, 0, 1, 40, tzinfo=pytz.UTC)))