def test_get_contacts_by_external_ids(mock_session): """ Should send GET request to specific URL """ extids = ( '&[email protected]' + '&[email protected]' + '&[email protected]') data = create_everbridge_contacts([1, 2, 3,], True) raw = { 'message': 'OK', 'page': { 'pageSize': 100, 'start': 0, 'totalCount': 3, 'totalPageCount': 0, 'currentPageNo': 0, 'data': data } } params = '?sortBy=externalId&direction=ASC&searchType=AND' + extids expected = json.loads(json.dumps(raw)) # Set up mocks session = create_session_mock(expected, code=200, method='GET') mock_session.return_value = session ever = create_everbridge_instance() expected_url = ever.contacts_url(params) # call get_contacts_by_external_ids rslt = ever.get_contacts_by_external_ids(extids) # Check if correct arguments are passed to session functions session.get.assert_called_with(expected_url) session.headers.update.assert_called_with(expected_header()) assert rslt == data
def test_delete_group(mock_session): """ Should send DELETE request to specific URL """ raw = {'message': 'OK'} expected = json.loads(json.dumps(raw)) # Set up mocks session = create_session_mock(expected, code=200, method='DELETE') mock_session.return_value = session ever = create_everbridge_instance() expected_url = ever.groups_url('123') # call delete_group ever.delete_group(123) # Check if correct arguments are passed to session functions session.delete.assert_called_with(expected_url) session.headers.update.assert_called_with(expected_header())
def test_get_group_id_by_name(mock_session): """ Should send GET request to specific URL """ raw = {'message': 'OK', 'result': {'id': 123}} expected = json.loads(json.dumps(raw)) # Set up mocks session = create_session_mock(expected, code=200, method='GET') mock_session.return_value = session ever = create_everbridge_instance() expected_url = ever.groups_url('xxxxx?queryType=name') # call get_group_by_name ever.get_group_id_by_name('xxxxx') # Check if correct arguments are passed to session functions session.get.assert_called_with(expected_url) session.headers.update.assert_called_with(expected_header())
def test_upsert_contacts(mock_session): """ Should send POST request to specific URL with data """ contacts = create_everbridge_contacts([1, 2, 3,], True) raw = {'code': 100, 'message': 'OK'} expected = json.loads(json.dumps(raw)) # Set up mocks session = create_session_mock(expected, code=200, method='POST') mock_session.return_value = session ever = create_everbridge_instance() expected_url = ever.contacts_url('batch?version=1') # call upsert_contacts ever.upsert_contacts(contacts) # Check if correct arguments are passed to session functions session.post.assert_called_with(expected_url, json=contacts) session.headers.update.assert_called_with(expected_header())
def test_add_group(mock_session): """ Should send POST request to specific URL """ raw = {'message': 'OK'} expected = json.loads(json.dumps(raw)) # Set up mocks session = create_session_mock(expected, code=200, method='POST') mock_session.return_value = session ever = create_everbridge_instance() expected_url = ever.groups_url('') data = {'name': 'xxxxx', 'organizationId': '1234567', 'parentId': None} # call add_group ever.add_group('xxxxx') # Check if correct arguments are passed to session functions session.post.assert_called_with(expected_url, json=data) session.headers.update.assert_called_with(expected_header())
def test_add_members_to_group(mock_session): """ Should send POST request to specific URL """ members = [1, 2, 3] raw = {'message': 'OK', 'code': 100} expected = json.loads(json.dumps(raw)) # Set up mocks session = create_session_mock(expected, code=200, method='POST') mock_session.return_value = session ever = create_everbridge_instance() expected_url = ever.groups_url('contacts?byType=id&groupId=123&idType=id') # call add_members_to_group ever.add_members_to_group(123, members) # Check if correct arguments are passed to session functions session.post.assert_called_with(expected_url, json=members) session.headers.update.assert_called_with(expected_header())
def test_paged_group_members(mock_session): """ Should send GET request to specific URL """ raw = {'message': 'OK', 'page': {'data': []}} expected = json.loads(json.dumps(raw)) # Set up mocks session = create_session_mock(expected, code=200, method='GET') mock_session.return_value = session ever = create_everbridge_instance() params = '?groupIds=123&pageSize=100&pageNumber=1&sortBy=externalId&direction=ASC' expected_url = ever.contacts_url(params) # call get_group_by_name ever.get_paged_group_members(123) # Check if correct arguments are passed to session functions session.get.assert_called_with(expected_url) session.headers.update.assert_called_with(expected_header())
def test_delete_contacts(mock_session): """ Should send DELETE request to specific URL with data """ contacts = [1, 2, 3] raw = {'message': 'OK', 'code': 100} expected = json.loads(json.dumps(raw)) # Set up mocks session = create_session_mock(expected, code=200, method='DELETE') mock_session.return_value = session ever = create_everbridge_instance() expected_url = ever.contacts_url('batch') # call delete_contacts ever.delete_contacts(contacts) # Check if correct arguments are passed to session functions session.delete.assert_called_with(expected_url, json=contacts) session.headers.update.assert_called_with(expected_header())