Ejemplo n.º 1
0
def test_api_get_request_no_access_token():
  '''
    Test simply api get request without access_token
  '''

  with patch('bufferapp.api.OAuth2Session') as mocked_oauth2:
    mocked_session = MagicMock()
    mocked_session.access_token = None

    mocked_oauth2.return_value = mocked_session

    api = API(client_id='1', client_secret='2')
    api.get(url="hey")
Ejemplo n.º 2
0
def test_api_post_request_no_access_token():
  '''
    Test simply api post request without access_token
  '''

  with patch('bufferapp.api.OAuth2Session') as mocked_oauth2:
    mocked_session = MagicMock()

    mocked_session.access_token = None

    mocked_oauth2.return_value = mocked_session

    api = API(client_id='1', client_secret='2', access_token='access_token')
    api.post(url='hey', data='new=True')
Ejemplo n.º 3
0
def test_api_get_request():
  '''
    Test simply api get request
  '''

  with patch('bufferapp.api.OAuth2Session') as mocked_oauth2:
    mocked_session = MagicMock()

    mocked_response = MagicMock()
    mocked_response.content = json.dumps({'status': 'ok'})
    mocked_session.get.return_value = mocked_response

    mocked_oauth2.return_value = mocked_session

    api = API(client_id='1', client_secret='2', access_token='access_token')
    api.get(url="hey")

    mocked_session.get.assert_called_once_with(url='https://api.bufferapp.com/1/hey')
Ejemplo n.º 4
0
def test_api_post_request():
  '''
    Test simply api post request
  '''

  with patch('bufferapp.api.OAuth2Session') as mocked_oauth2:
    mocked_session = MagicMock()

    mocked_response = MagicMock()
    mocked_response.content = json.dumps({'status': 'ok'})
    mocked_session.post.return_value = mocked_response

    mocked_oauth2.return_value = mocked_session

    api = API(client_id='1', client_secret='2', access_token='access_token')
    api.post(url='hey', data='new=True')

    headers = {'Content-Type':'application/x-www-form-urlencoded'}
    mocked_session.post.assert_called_once_with(
        url='https://api.bufferapp.com/1/hey', headers=headers, data='new=True')