def test_get(self, mock_get): expected_result = {'key': 'value'} self.assertEqual( get('http://someurl.com/test.json', headers={ 'key': 'value' }).json(), expected_result)
def get_gist_access(slug): """Get the access permission of a gist""" res = get(url=_u('/gist/' + slug + '/check-access'), headers=_h()) if res.status_code == 200: return res.json()['data'] raise Exception('Failed to retrieve access permission for notebook "' + slug + '" (retry with new_project=True to create a new notebook): ' + pretty(res))
def add_slack(): """prints instructions for connecting Slack, if Slack connection is not already present. if Slack is already connected, prints details about the workspace and the channel""" url = _u('/slack/integration_details') res = get(url, headers=_h()) if res.status_code == 200: res = res.json() if not res.get('errors'): slack_account = res.get('data').get('slackAccount') log('Slack already connected. \nWorkspace: {}\nConnected Channel: {}' .format(slack_account.get('workspace'), slack_account.get('channel'))) else: log(str(res.get('errors')[0].get('message'))) else: raise ApiError('Slack trigger failed: ' + pretty(res))
def get_gist(slug, version=None, check_exists=True): """Get the metadata for a gist""" if '/' in slug: parts = slug.split('/') username, title = parts[0], parts[1] url = _u('user/' + username + '/gist/' + title + _v(version)) else: url = _u('gist/' + slug + _v(version)) res = get(url=url, headers=_h()) if res.status_code == 200: return res.json()['data'] elif check_exists and res.status_code == 404: return False raise Exception('Failed to retrieve metadata for notebook "' + slug + '": ' + pretty(res))
def test_get_called_twice(self, mock_get): get('http://someurl.com/noauth', headers={'key': 'value'}) assert mock_get.call_count == 2
def test_get_called_once(self, mock_get): get('http://someurl.com/test.json', headers={'key': 'value'}) assert mock_get.call_count == 1
def get_current_user(): res = get(url=_u('/user/profile'), headers=_h()) if res.status_code == 200: return res.json()['data'] raise Exception('Failed to fetch current user profile. ' + pretty(res))