def _delete(self, endpoint, endpointid=None, subendpoint=None, subendpointid=None): r = requests.delete(url=compose_url(self.url, endpoint, endpointid=endpointid, subendpoint=subendpoint, subendpointid=subendpointid), headers=self.headers)
def _get(self, endpoint, endpointid=None, subendpoint=None, subendpointid=None): r = requests.get(url=compose_url(self.url, endpoint, endpointid=endpointid, subendpoint=subendpoint, subendpointid=subendpointid), headers=self.headers) if r.ok: return r.json() else: raise Exception('Get request unsuccessful, url: {}'.format(r.url))
def connect(self, client_id, client_secret): """Gets Access Token from Looker, setting token on LookerConnection""" login = requests.post(url=compose_url(self.url, 'login'), data={ 'client_id': client_id, 'client_secret': client_secret }) try: access_token = login.json()['access_token'] headers = {'Authorization': 'token {}'.format(access_token)} except KeyError: logging.error('Incorrect Client Credentials') headers = None return headers
def _patch(self, payload, endpoint, endpointid=None, subendpoint=None, subendpointid=None): r = requests.patch(url=compose_url(self.url, endpoint, endpointid=endpointid, subendpoint=subendpoint, subendpointid=subendpointid), headers=self.headers, json=payload) if r.ok: return r.json() else: raise Exception('Patch request unsuccessful, url: {}'.format( r.url))
def test_compose_url_endpoint(): assert compose_url( BASE_URL, 'projects') == 'https://test_url.looker.com:19999/api/3.0/projects'
def test_compose_url_no_url(): with pytest.raises(Exception): compose_url(endpoint='projects')
def test_compose_url_no_endpoint(): with pytest.raises(Exception): compose_url(BASE_URL)
def test_compose_url_subendpoint(): assert compose_url( BASE_URL, 'projects', 'looker_project', 'git_branches', 'hotfix_2' ) == 'https://test_url.looker.com:19999/api/3.0/projects/looker_project/git_branches/hotfix_2'