Esempio n. 1
0
    def setUp(self):
        self.data = {'property': 'result', 'data': {'some_more': 'result'}}
        self.mock_response = MagicMock(autospec=Response)
        type(self.mock_response).status_code = PropertyMock(return_value=200)
        self.mock_response.raise_for_status.side_effect = requests.HTTPError()

        self.client = ApiClient('aoeu')
        self.client._session = MagicMock(spec_set=Session)
        self.client._session.send.return_value = self.mock_response
Esempio n. 2
0
class ApiTest(unittest.TestCase):
    def setUp(self):
        self.data = {'property': 'result', 'data': {'some_more': 'result'}}
        self.mock_response = MagicMock(autospec=Response)
        type(self.mock_response).status_code = PropertyMock(return_value=200)
        self.mock_response.raise_for_status.side_effect = requests.HTTPError()

        self.client = ApiClient('aoeu')
        self.client._session = MagicMock(spec_set=Session)
        self.client._session.send.return_value = self.mock_response

    def tearDown(self):
        pass

    def test_raises_httperror(self):
        type(self.mock_response).status_code = PropertyMock(return_value=400)
        with self.assertRaises(HttpError):
            self.client._make_request('GET', '/test')
        self.assertEqual(1, len(self.mock_response.reason.mock_calls))

    def test_raises_timeouterror(self):
        self.client._session.send.side_effect = requests.Timeout()
        with self.assertRaises(TimeoutError):
            self.client._make_request('GET', '/test')

    def test_raises_connectionerror(self):
        self.client._session.send.side_effect = requests.ConnectionError()
        with self.assertRaises(ClientError):
            self.client._make_request('GET', '/test')

    def test_response_returns_json(self):
        self.client._make_request('GET', '/test')
        self.assertEqual(self.mock_response.json.call_count, 1)

    def test_devices_property(self):
        isinstance(self.client.devices, Device)

    def test_services_property(self):
        isinstance(self.client.services, Service)

    def test_alerts_property(self):
        isinstance(self.client.alerts, Alert)

    def test_service_status_property(self):
        isinstance(self.client.service_status, ServiceStatus)

    def test_users_property(self):
        isinstance(self.client.users, User)

    def test_dashboards_property(self):
        isinstance(self.client.dashboards, Dashboard)

    def test_postbacks_property(self):
        isinstance(self.client.postbacks, Postback)

    def test_tag_property(self):
        isinstance(self.client.tags, Tag)

    def test_metrics_property(self):
        isinstance(self.client.metrics, Metrics)
    def setUp(self):
        self.schema = {
            '$schema': 'http://json-schema.org/draft-04/schema#',
            'title': 'Test schema',
            'type': 'object',
            'properties': {
                '_id': {
                    'type': 'string',
                    'format': 'mongoId'
                },
                'name': {
                    'type': 'string'
                }
            },
            'required': ['_id']
        }

        self.dummyschema = {
            '$schema': 'http://json-schema.org/draft-04/schema#',
            'type': 'object',
            'properties': {}
        }

        self.TestObj = JsonObject
        self.TestObj._schemaobj = self.schema
        self.client = ApiClient('aeou')
Esempio n. 4
0
    def setUp(self, mock_make_request):
        self.deviceobj = self.get_json('/json/device.json')

        self.client = ApiClient('aeou')
        self.client._make_request = mock_make_request
        self.client._make_request.return_value = self.deviceobj
        self.device = Device(api=self.client)
    def setUp(self, mock_make_request):
        self.widgetobj = self.get_json('/json/widget.json')

        self.client = ApiClient('aeou')
        self.client._make_request = mock_make_request
        self.client._make_request.return_value = self.widgetobj
        self.widget = Widget(api=self.client)
Esempio n. 6
0
    def setUp(self, mock_make_request):
        self.tagobj = self.get_json('/json/tag.json')

        self.client = ApiClient('aeou')
        self.client._make_request = mock_make_request
        self.client._make_request.return_value = self.tagobj
        self.tag = Tag(api=self.client)
    def setUp(self, mock_make_request):
        self.dashobj = self.get_json('/json/dashboard.json')

        self.client = ApiClient('aeou')
        self.client._make_request = mock_make_request
        self.client._make_request.return_value = self.dashobj
        self.dashboard = Dashboard(api=self.client)
Esempio n. 8
0
    def setUp(self, mock_make_request):
        self.userobj = self.get_json('/json/user.json')

        self.client = ApiClient('aeou')
        self.client._make_request = mock_make_request
        self.client._make_request.return_value = self.userobj
        self.user = User(api=self.client)
Esempio n. 9
0
    def __init__(self, token, conf):
        self.token = token
        self.conf = conf
        self.historic_data = None
        client = ApiClient(self.token, timeout=(3.05, 18))
        self.device = Device(self.token)
        self.tag = Tag(self.token)
        self.metrics = Metrics(client)

        self._validation()
Esempio n. 10
0
    def setUp(self):
        self.data = {
            'property': 'result',
            'data': {'some_more': 'result'}
        }
        self.mock_response = MagicMock(autospec=Response)
        type(self.mock_response).status_code = PropertyMock(return_value=200)
        self.mock_response.raise_for_status.side_effect = requests.HTTPError()

        self.client = ApiClient('aoeu')
        self.client._session = MagicMock(spec_set=Session)
        self.client._session.send.return_value = self.mock_response
Esempio n. 11
0
class ApiTest(unittest.TestCase):

    def setUp(self):
        self.data = {
            'property': 'result',
            'data': {'some_more': 'result'}
        }
        self.mock_response = MagicMock(autospec=Response)
        type(self.mock_response).status_code = PropertyMock(return_value=200)
        self.mock_response.raise_for_status.side_effect = requests.HTTPError()

        self.client = ApiClient('aoeu')
        self.client._session = MagicMock(spec_set=Session)
        self.client._session.send.return_value = self.mock_response

    def tearDown(self):
        pass

    def test_raises_httperror(self):
        type(self.mock_response).status_code = PropertyMock(return_value=400)
        with self.assertRaises(HttpError):
            self.client._make_request('GET', '/test')
        self.assertEqual(1, len(self.mock_response.reason.mock_calls))

    def test_raises_timeouterror(self):
        self.client._session.send.side_effect = requests.Timeout()
        with self.assertRaises(TimeoutError):
            self.client._make_request('GET', '/test')

    def test_raises_connectionerror(self):
        self.client._session.send.side_effect = requests.ConnectionError()
        with self.assertRaises(ClientError):
            self.client._make_request('GET', '/test')

    def test_kwargs_with_query_params(self):
        self.client._make_request('GET', '/test', perPage='10', page='4')
        self.assertIn('perPage', self.client.params)
        self.assertIn('page', self.client.params)

    def test_kwargs_with_field_param(self):
        self.client._make_request('GET', '/test', fields=['name', '_id'])
        self.assertIn('fields', self.client.params)
        self.assertEquals(self.client.params['fields'], '["name", "_id"]')

    def test_kwargs_with_field_which_is_dict(self):
        self.client._make_request('GET', '/test', fields={'name': '_id'})
        self.assertIn('fields', self.client.params)
        self.assertEquals(self.client.params['fields'], '{"name": "_id"}')

    def test_params_is_cleaned_out_for_new_request(self):
        self.client._make_request('GET', '/test', perPage='10', page='4')
        self.assertIn('perPage', self.client.params)
        self.client._make_request('GET', '/test')
        self.assertNotIn('perPage', self.client.params)

    def test_response_returns_json(self):
        self.client._make_request('GET', '/test')
        self.assertEqual(self.mock_response.json.call_count, 1)

    def test_devices_property(self):
        isinstance(self.client.devices, Device)

    def test_services_property(self):
        isinstance(self.client.services, Service)

    def test_alerts_property(self):
        isinstance(self.client.alerts, Alert)

    def test_service_status_property(self):
        isinstance(self.client.service_status, ServiceStatus)

    def test_users_property(self):
        isinstance(self.client.users, User)

    def test_dashboards_property(self):
        isinstance(self.client.dashboards, Dashboard)

    def test_postbacks_property(self):
        isinstance(self.client.postbacks, Postback)

    def test_tag_property(self):
        isinstance(self.client.tags, Tag)

    def test_metrics_property(self):
        isinstance(self.client.metrics, Metrics)
Esempio n. 12
0
class ApiTest(unittest.TestCase):

    def setUp(self):
        self.data = {
            'property': 'result',
            'data': {'some_more': 'result'}
        }
        self.mock_response = MagicMock(autospec=Response)
        type(self.mock_response).status_code = PropertyMock(return_value=200)
        self.mock_response.raise_for_status.side_effect = requests.HTTPError()

        self.client = ApiClient('aoeu')
        self.client._session = MagicMock(spec_set=Session)
        self.client._session.send.return_value = self.mock_response

    def tearDown(self):
        pass

    def test_raises_httperror(self):
        type(self.mock_response).status_code = PropertyMock(return_value=400)
        with self.assertRaises(HttpError):
            self.client._make_request('GET', '/test')
        self.assertEqual(1, len(self.mock_response.reason.mock_calls))

    def test_raises_timeouterror(self):
        self.client._session.send.side_effect = requests.Timeout()
        with self.assertRaises(TimeoutError):
            self.client._make_request('GET', '/test')

    def test_raises_connectionerror(self):
        self.client._session.send.side_effect = requests.ConnectionError()
        with self.assertRaises(ClientError):
            self.client._make_request('GET', '/test')

    def test_response_returns_json(self):
        self.client._make_request('GET', '/test')
        self.assertEqual(self.mock_response.json.call_count, 1)

    def test_devices_property(self):
        isinstance(self.client.devices, Device)

    def test_services_property(self):
        isinstance(self.client.services, Service)

    def test_alerts_property(self):
        isinstance(self.client.alerts, Alert)

    def test_service_status_property(self):
        isinstance(self.client.service_status, ServiceStatus)

    def test_users_property(self):
        isinstance(self.client.users, User)

    def test_dashboards_property(self):
        isinstance(self.client.dashboards, Dashboard)

    def test_postbacks_property(self):
        isinstance(self.client.postbacks, Postback)

    def test_tags_property(self):
        isinstance(self.client.postbacks, Tags)

    def test_metrics_property(self):
        isinstance(self.client.postbacks, Metrics)
Esempio n. 13
0
class ApiTest(unittest.TestCase):
    def setUp(self):
        self.data = {'property': 'result', 'data': {'some_more': 'result'}}
        self.mock_response = MagicMock(autospec=Response)
        type(self.mock_response).status_code = PropertyMock(return_value=200)
        self.mock_response.raise_for_status.side_effect = requests.HTTPError()

        self.client = ApiClient('aoeu')
        self.client._session = MagicMock(spec_set=Session)
        self.client._session.send.return_value = self.mock_response

    def tearDown(self):
        pass

    def test_raises_httperror(self):
        type(self.mock_response).status_code = PropertyMock(return_value=400)
        with self.assertRaises(HttpError):
            self.client._make_request('GET', '/test')
        self.assertEqual(1, len(self.mock_response.reason.mock_calls))

    def test_raises_timeouterror(self):
        self.client._session.send.side_effect = requests.Timeout()
        with self.assertRaises(TimeoutError):
            self.client._make_request('GET', '/test')

    def test_raises_connectionerror(self):
        self.client._session.send.side_effect = requests.ConnectionError()
        with self.assertRaises(ClientError):
            self.client._make_request('GET', '/test')

    def test_kwargs_with_query_params(self):
        self.client._make_request('GET', '/test', perPage='10', page='4')
        self.assertIn('perPage', self.client.params)
        self.assertIn('page', self.client.params)

    def test_kwargs_with_field_param(self):
        self.client._make_request('GET', '/test', fields=['name', '_id'])
        self.assertIn('fields', self.client.params)
        self.assertEquals(self.client.params['fields'], '["name", "_id"]')

    def test_kwargs_with_field_which_is_dict(self):
        self.client._make_request('GET', '/test', fields={'name': '_id'})
        self.assertIn('fields', self.client.params)
        self.assertEquals(self.client.params['fields'], '{"name": "_id"}')

    def test_params_is_cleaned_out_for_new_request(self):
        self.client._make_request('GET', '/test', perPage='10', page='4')
        self.assertIn('perPage', self.client.params)
        self.client._make_request('GET', '/test')
        self.assertNotIn('perPage', self.client.params)

    def test_response_returns_json(self):
        self.client._make_request('GET', '/test')
        self.assertEqual(self.mock_response.json.call_count, 1)

    def test_devices_property(self):
        isinstance(self.client.devices, Device)

    def test_services_property(self):
        isinstance(self.client.services, Service)

    def test_alerts_property(self):
        isinstance(self.client.alerts, Alert)

    def test_service_status_property(self):
        isinstance(self.client.service_status, ServiceStatus)

    def test_users_property(self):
        isinstance(self.client.users, User)

    def test_dashboards_property(self):
        isinstance(self.client.dashboards, Dashboard)

    def test_postbacks_property(self):
        isinstance(self.client.postbacks, Postback)

    def test_tag_property(self):
        isinstance(self.client.tags, Tag)

    def test_metrics_property(self):
        isinstance(self.client.metrics, Metrics)
Esempio n. 14
0
 def setUp(self, mock_make_request):
     self.client = ApiClient('aeou')
     self.client._make_request = mock_make_request
     self.client._make_request.return_value = {'service_status': 'result'}
     self.service_status = ServiceStatus(api=self.client)
Esempio n. 15
0
 def setUp(self, mock_make_request):
     self.client = ApiClient('aeou')
     self.client._make_request = mock_make_request
     self.client._make_request.return_value = {'postbacks': 'result'}
     self.postbacks = Postback(api=self.client)