Beispiel #1
0
    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)
Beispiel #2
0
    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))
Beispiel #3
0
    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
Beispiel #4
0
    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))
Beispiel #5
0
def test_compose_url_endpoint():

    assert compose_url(
        BASE_URL,
        'projects') == 'https://test_url.looker.com:19999/api/3.0/projects'
Beispiel #6
0
def test_compose_url_no_url():

    with pytest.raises(Exception):
        compose_url(endpoint='projects')
Beispiel #7
0
def test_compose_url_no_endpoint():

    with pytest.raises(Exception):
        compose_url(BASE_URL)
Beispiel #8
0
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'