def _url(endpoint): """ Get rest query url of account resource id. """ if endpoint == 'owner': return 'https://rest.logentries.com/management/accounts/' + str( apiutils.get_account_resource_id()) + '/owners' elif endpoint == 'user': return 'https://rest.logentries.com/management/accounts/' + str( apiutils.get_account_resource_id()) + '/users'
def test_get_valid_account_resource_id(): with patch.object(ConfigParser.ConfigParser, 'get', return_value=misc_ex.TEST_APIKEY_WITH_VALID_LENGTH): account_resource_id = apiutils.get_account_resource_id() assert account_resource_id == misc_ex.TEST_APIKEY_WITH_VALID_LENGTH
def add_new_user(first_name, last_name, email): """ Add a new user to the current account. """ action = 'management/accounts/' + str( apiutils.get_account_resource_id()) + '/users' json_content = { "user": { "email": str(email), "first_name": str(first_name), "last_name": str(last_name) } } body = json.dumps(json_content) headers = apiutils.generate_headers('owner', method='POST', action=action, body=body) try: response = requests.request('POST', _url('user'), json=json_content, headers=headers) handle_create_user_response(response) except requests.exceptions.RequestException as error: print error exit(1)
def test_get_invalid_account_resource_id(capsys): with patch.object(ConfigParser.ConfigParser, 'get', return_value=misc_ex.TEST_APIKEY_WITH_INVALID_LENGTH): account_resource_id = apiutils.get_account_resource_id() out, err = capsys.readouterr() assert account_resource_id == misc_ex.TEST_APIKEY_WITH_INVALID_LENGTH assert 'Error: Account Resource ID not of correct length\n' == out
def test_get_invalid_account_resource_id(capsys): with patch.object(ConfigParser.ConfigParser, 'get', return_value=misc_ex.TEST_APIKEY_WITH_INVALID_LENGTH): with pytest.raises(SystemExit): result = apiutils.get_account_resource_id() out, err = capsys.readouterr() assert result is None assert misc_ex.TEST_APIKEY_WITH_INVALID_LENGTH in out assert 'is not of correct length' in out
def list_users(): """ List users that is in the current account. """ action = 'management/accounts/' + str(apiutils.get_account_resource_id()) + '/users' try: response = requests.request('GET', _url('user'), headers=apiutils.generate_headers( 'owner', 'GET', action, '')) handle_userlist_response(response) except requests.exceptions.RequestException as error: print error exit(1)
def list_users(): """ List users that is in the current account. """ action = 'management/accounts/' + str( apiutils.get_account_resource_id()) + '/users' try: response = requests.request('GET', _url('user'), headers=apiutils.generate_headers( 'owner', 'GET', action, '')) handle_userlist_response(response) except requests.exceptions.RequestException as error: print error exit(1)
def add_new_user(first_name, last_name, email): """ Add a new user to the current account. """ action = 'management/accounts/' + str(apiutils.get_account_resource_id()) + '/users' body = { "email": str(email), "first_name": str(first_name), "last_name": str(last_name) } body = json.dumps(body, separators=(',', ':')) headers = apiutils.generate_headers('owner', method='POST', action=action, body=body) try: response = requests.request('POST', _url('user'), data=body, headers=headers) handle_create_user_response(response) except requests.exceptions.RequestException as error: print error exit(1)
def _url(): """ Get rest query url of account resource id. """ return 'https://rest.logentries.com/management/accounts/%s/teams' % \ apiutils.get_account_resource_id()
def _url(): """ Get rest query url of account resource id. """ return 'https://rest.logentries.com/management/accounts/%s' + \ apiutils.get_account_resource_id() + '/teams'