class NRNotificationChannelsTests(TestCase): def setUp(self): super(NRNotificationChannelsTests, self).setUp() self.channels = NotificationChannels(api_key='dummy_key') self.list_response = { "notification_channels": [ { "id": 111222, "type": "user", "downtime_only": False, "mobile_alerts": False, "email_alerts": True, "links": { "user": 222333 } } ] } self.show_response = { 'notification_channel': self.list_response['notification_channels'][0] } @patch.object(requests, 'get') def test_list(self, mock_get): """ Test notification channels .list() """ self.channels.list(filter_type=['user'], page=0) mock_get.assert_called_once_with( url='https://api.newrelic.com/v2/notification_channels.json', headers=self.channels.headers, params='filter[type]=user' ) @patch.object(requests, 'get') def test_list_with_filter_ids(self, mock_get): """ Test notification channels .list() with filter_ids """ self.channels.list(filter_type=['user'], filter_ids=[111222], page=0) mock_get.assert_called_once_with( url='https://api.newrelic.com/v2/notification_channels.json', headers=self.channels.headers, params='filter[type]=user&filter[ids]=111222' ) @patch.object(requests, 'get') def test_show(self, mock_get): """ Test notification channels .show() """ self.channels.show(id=11122) mock_get.assert_called_once_with( url='https://api.newrelic.com/v2/notification_channels/11122.json', headers=self.channels.headers, )
class NRNotificationChannelsTests(TestCase): def setUp(self): super(NRNotificationChannelsTests, self).setUp() self.channels = NotificationChannels(api_key='dummy_key') self.list_response = { "channels": [ { "id": 111222, "type": "user", "name": "Some User", "links": { "policy_ids": [] }, "configuration": { "user": 222333 } } ] } self.single_response = { 'channels': self.list_response['channels'][0] } @patch.object(requests, 'get') def test_list_success(self, mock_get): """ Test notification channels .list() """ mock_response = Mock(name='response') mock_response.json.return_value = self.list_response mock_get.return_value = mock_response response = self.channels.list() self.assertIsInstance(response, dict) mock_get.assert_called_once_with( url='https://api.newrelic.com/v2/alerts_channels.json', headers=self.channels.headers, params='' ) @patch.object(requests, 'get') def test_list_success_with_pagination(self, mock_get): """ Test notification channels .list() with page parameter """ self.channels.list(page=2) mock_get.assert_called_once_with( url='https://api.newrelic.com/v2/alerts_channels.json', headers=self.channels.headers, params='page=2' ) @patch.object(requests, 'post') def test_create_success(self, mock_post): """ Test notification channels .create() calls put with correct parameters """ self.channels.create( name=self.single_response['channels']['name'], type=self.single_response['channels']['type'], configuration=self.single_response['channels']['configuration'] ) mock_post.assert_called_once_with( url='https://api.newrelic.com/v2/alerts_channels.json', headers=self.channels.headers, data=json.dumps({ "channel": { "name": self.single_response['channels']['name'], "type": self.single_response['channels']['type'], "configuration": self.single_response['channels']['configuration'] } }) )
class NRNotificationChannelsTests(TestCase): def setUp(self): super(NRNotificationChannelsTests, self).setUp() self.channels = NotificationChannels(api_key='dummy_key') self.list_response = { "channels": [{ "id": 111222, "type": "user", "name": "Some User", "links": { "policy_ids": [] }, "configuration": { "user": 222333 } }] } self.single_response = {'channels': self.list_response['channels'][0]} @patch.object(requests, 'get') def test_list_success(self, mock_get): """ Test notification channels .list() """ mock_response = Mock(name='response') mock_response.json.return_value = self.list_response mock_get.return_value = mock_response response = self.channels.list() self.assertIsInstance(response, dict) mock_get.assert_called_once_with( url='https://api.newrelic.com/v2/alerts_channels.json', headers=self.channels.headers, params='') @patch.object(requests, 'get') def test_list_success_with_pagination(self, mock_get): """ Test notification channels .list() with page parameter """ self.channels.list(page=2) mock_get.assert_called_once_with( url='https://api.newrelic.com/v2/alerts_channels.json', headers=self.channels.headers, params='page=2') @patch.object(requests, 'post') def test_create_success(self, mock_post): """ Test notification channels .create() calls put with correct parameters """ self.channels.create( name=self.single_response['channels']['name'], type=self.single_response['channels']['type'], configuration=self.single_response['channels']['configuration']) mock_post.assert_called_once_with( url='https://api.newrelic.com/v2/alerts_channels.json', headers=self.channels.headers, data=json.dumps({ "channel": { "name": self.single_response['channels']['name'], "type": self.single_response['channels']['type'], "configuration": self.single_response['channels']['configuration'] } }))