# Path: devicecloud/monitor.py
# MON_TOPIC_ATTR = Attribute("monTopic")
# 
# MON_TRANSPORT_TYPE_ATTR = Attribute("monTransportType")
# 
# Path: devicecloud/test/unit/test_utilities.py
# class HttpTestBase(unittest.TestCase):
#     def setUp(self):
#         httpretty.enable()
#         # setup Device Cloud ping response
#         self.prepare_response("GET", "/ws/DeviceCore?size=1", "", status=200)
#         self.dc = DeviceCloud('user', 'pass')
# 
#     def tearDown(self):
#         httpretty.disable()
#         httpretty.reset()
# 
#     def _get_last_request(self):
#         return httpretty.last_request()
# 
#     def _get_last_request_params(self):
#         # Get the query params from the last request as a dictionary
#         params = urllib_parse.parse_qs(urllib_parse.urlparse(self._get_last_request().path).query)
#         return {k: v[0] for k, v in params.items()}  # convert from list values to single-value
# 
#     def prepare_response(self, method, path, data=None, status=200, match_querystring=False, **kwargs):
#         # TODO:
#         #   Should probably assert on more request headers and
#         #   respond with correct content type, etc.
#         if data is not None:
#             kwargs['body'] = data
#         httpretty.register_uri(method,
#                                "https://devicecloud.digi.com{}".format(path),
#                                match_querystring=match_querystring,
#                                status=status,
#                                **kwargs)
# 
#     def prepare_json_response(self, method, path, data, status=200):
#         self.prepare_response(method, path, json.dumps(data), status=status)


from devicecloud.monitor import MON_TOPIC_ATTR, MON_TRANSPORT_TYPE_ATTR
from devicecloud.test.unit.test_utilities import HttpTestBase
import six
        self.prepare_response("GET", "/ws/Monitor", data=GET_HTTP_MONITOR_SINGLE_FOUND)
        mon = self.dc.monitor.get_monitor(['DeviceCore', 'FileDataCore', 'FileData', 'DataPoint'])
        self.assertEqual(mon.get_id(), 178007)
        self.assertEqual(self._get_last_request_params(), {
            'condition': "monTopic='DeviceCore,FileDataCore,FileData,DataPoint'",
            'start': '0',
            'size': '1000'
        })

    def test_get_monitor_multiple(self):
        # Should just pick the first result (currently), so results are the same as ever
        self.prepare_response("GET", "/ws/Monitor", data=GET_MONITOR_MULTIPLE_FOUND)
        mon = self.dc.monitor.get_monitor(['DeviceCore', 'FileDataCore', 'FileData', 'DataPoint'])
        self.assertEqual(mon.get_id(), 178007)
        self.assertEqual(self._get_last_request_params(), {
            'condition': "monTopic='DeviceCore,FileDataCore,FileData,DataPoint'",
            'start': '0',
            'size': '1000'
        })

    def test_get_monitor_does_not_exist(self):
        # Should just pick the first result (currently), so results are the same as ever
        self.prepare_response("GET", "/ws/Monitor", data=GET_MONITOR_NONE_FOUND)
        mon = self.dc.monitor.get_monitor(['DeviceCore', 'FileDataCore', 'FileData', 'DataPoint'])
        self.assertEqual(mon, None)


class TestDeviceCloudMonitor(HttpTestBase):

    def setUp(self):

# Path: devicecloud/monitor.py
# MON_TOPIC_ATTR = Attribute("monTopic")
# 
# MON_TRANSPORT_TYPE_ATTR = Attribute("monTransportType")
# 
# Path: devicecloud/test/unit/test_utilities.py
# class HttpTestBase(unittest.TestCase):
#     def setUp(self):
#         httpretty.enable()
#         # setup Device Cloud ping response
#         self.prepare_response("GET", "/ws/DeviceCore?size=1", "", status=200)
#         self.dc = DeviceCloud('user', 'pass')
# 
#     def tearDown(self):
#         httpretty.disable()
#         httpretty.reset()
# 
#     def _get_last_request(self):
#         return httpretty.last_request()
# 
#     def _get_last_request_params(self):
#         # Get the query params from the last request as a dictionary
#         params = urllib_parse.parse_qs(urllib_parse.urlparse(self._get_last_request().path).query)
#         return {k: v[0] for k, v in params.items()}  # convert from list values to single-value
# 
#     def prepare_response(self, method, path, data=None, status=200, match_querystring=False, **kwargs):
#         # TODO:
#         #   Should probably assert on more request headers and
#         #   respond with correct content type, etc.
#         if data is not None:
#             kwargs['body'] = data
#         httpretty.register_uri(method,
#                                "https://devicecloud.digi.com{}".format(path),
#                                match_querystring=match_querystring,
#                                status=status,
#                                **kwargs)
# 
#     def prepare_json_response(self, method, path, data, status=200):
#         self.prepare_response(method, path, json.dumps(data), status=status)


# Path: devicecloud/test/unit/test_monitor.py
from devicecloud.monitor import MON_TOPIC_ATTR, MON_TRANSPORT_TYPE_ATTR
from devicecloud.test.unit.test_utilities import HttpTestBase
import six

        self.prepare_response("GET", "/ws/Monitor", data=GET_HTTP_MONITOR_SINGLE_FOUND)
        mon = self.dc.monitor.get_monitor(['DeviceCore', 'FileDataCore', 'FileData', 'DataPoint'])
        self.assertEqual(mon.get_id(), 178007)
        self.assertEqual(self._get_last_request_params(), {
            'condition': "monTopic='DeviceCore,FileDataCore,FileData,DataPoint'",
            'start': '0',
            'size': '1000'
        })

    def test_get_monitor_multiple(self):
        # Should just pick the first result (currently), so results are the same as ever
        self.prepare_response("GET", "/ws/Monitor", data=GET_MONITOR_MULTIPLE_FOUND)
        mon = self.dc.monitor.get_monitor(['DeviceCore', 'FileDataCore', 'FileData', 'DataPoint'])
        self.assertEqual(mon.get_id(), 178007)
        self.assertEqual(self._get_last_request_params(), {
            'condition': "monTopic='DeviceCore,FileDataCore,FileData,DataPoint'",
            'start': '0',
            'size': '1000'
        })

    def test_get_monitor_does_not_exist(self):
        # Should just pick the first result (currently), so results are the same as ever
        self.prepare_response("GET", "/ws/Monitor", data=GET_MONITOR_NONE_FOUND)
        mon = self.dc.monitor.get_monitor(['DeviceCore', 'FileDataCore', 'FileData', 'DataPoint'])
        self.assertEqual(mon, None)


class TestDeviceCloudMonitor(HttpTestBase):

    def setUp(self):

        HttpTestBase.setUp(self)