# Path: performanceplatform/collector/pingdom/core.py
# class Pingdom(object):
#     def __init__(self, config):
#         self.user = config['user']
#         self.password = config['password']
#         self.app_key = config['app_key']
#         self.account_email = config['account_email']
#         self.API_LOCATION = "https://api.pingdom.com/api/2.0/"
# 
#     def _make_request(self, path, url_params=None):
#         if url_params is None:
#             url_params = {}
#         response = requests_with_backoff.get(
#             url=self.API_LOCATION + path,
#             auth=(self.user, self.password),
#             headers={
#                 "App-Key": self.app_key,
#                 "Account-Email": self.account_email
#             },
#             params=url_params
#         )
#         response.raise_for_status()
# 
#         return response.json()
# 
#     def _build_response(self, data):
#         hours = data['summary']['hours']
#         new_hours = []
#         for hour in hours:
#             hour.update({'starttime': datetime.fromtimestamp(
#                 hour['starttime'],
#                 tz=pytz.UTC
#             )})
#             new_hours.append(hour)
#         return new_hours
# 
#     def stats(self, check_name, start, end):
#         app_code = self.check_id(check_name)
#         params = {
#             "includeuptime": "true",
#             "from": time.mktime(start.timetuple()),
#             "to": time.mktime(end.timetuple()),
#             "resolution": "hour"
#         }
#         path = "summary.performance/" + str(app_code)
# 
#         try:
#             return self._build_response(self._make_request(
#                 path=path,
#                 url_params=params
#             ))
#         except requests_with_backoff.exceptions.HTTPError as e:
#             logging.error("Request to pingdom failed: %s" % str(e),
#                           extra=extra_fields_from_exception(e))
# 
#     def check_id(self, name):
#         checks = self._make_request(path="checks")
# 
#         check_to_find = [check for check in checks["checks"]
#                          if check["name"] == name]
# 
#         return check_to_find[0]["id"]


from datetime import date, datetime
from time import mktime
from hamcrest import assert_that, is_, instance_of
from mock import patch, Mock
from performanceplatform.collector.pingdom.core import Pingdom
import unittest
import pytz
import requests
        )

        assert_that(uptime, is_([]))

    @patch("performanceplatform.utils.requests_with_backoff.get")
    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):

# Path: performanceplatform/collector/pingdom/core.py
# class Pingdom(object):
#     def __init__(self, config):
#         self.user = config['user']
#         self.password = config['password']
#         self.app_key = config['app_key']
#         self.account_email = config['account_email']
#         self.API_LOCATION = "https://api.pingdom.com/api/2.0/"
# 
#     def _make_request(self, path, url_params=None):
#         if url_params is None:
#             url_params = {}
#         response = requests_with_backoff.get(
#             url=self.API_LOCATION + path,
#             auth=(self.user, self.password),
#             headers={
#                 "App-Key": self.app_key,
#                 "Account-Email": self.account_email
#             },
#             params=url_params
#         )
#         response.raise_for_status()
# 
#         return response.json()
# 
#     def _build_response(self, data):
#         hours = data['summary']['hours']
#         new_hours = []
#         for hour in hours:
#             hour.update({'starttime': datetime.fromtimestamp(
#                 hour['starttime'],
#                 tz=pytz.UTC
#             )})
#             new_hours.append(hour)
#         return new_hours
# 
#     def stats(self, check_name, start, end):
#         app_code = self.check_id(check_name)
#         params = {
#             "includeuptime": "true",
#             "from": time.mktime(start.timetuple()),
#             "to": time.mktime(end.timetuple()),
#             "resolution": "hour"
#         }
#         path = "summary.performance/" + str(app_code)
# 
#         try:
#             return self._build_response(self._make_request(
#                 path=path,
#                 url_params=params
#             ))
#         except requests_with_backoff.exceptions.HTTPError as e:
#             logging.error("Request to pingdom failed: %s" % str(e),
#                           extra=extra_fields_from_exception(e))
# 
#     def check_id(self, name):
#         checks = self._make_request(path="checks")
# 
#         check_to_find = [check for check in checks["checks"]
#                          if check["name"] == name]
# 
#         return check_to_find[0]["id"]


# Path: tests/performanceplatform/collector/pingdom/test_pingdom_api.py
from datetime import date, datetime
from time import mktime
from hamcrest import assert_that, is_, instance_of
from mock import patch, Mock
from performanceplatform.collector.pingdom.core import Pingdom
import unittest
import pytz
import requests

        )

        assert_that(uptime, is_([]))

    @patch("performanceplatform.utils.requests_with_backoff.get")
    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):

        pingdom = Pingdom(self.config)