예제 #1
0
파일: test_api.py 프로젝트: talpor/buffpy
def test_api_post_parse_buffpy_error():

    httpretty.register_uri(httpretty.POST, "https://api.bufferapp.com/1/hey",
                           body="{u'message': u\"Whoops, it looks like you've posted that one recently. Unfortunately, we're not able to post the same thing again so soon!\", u'code': 1025, u'success': False}",
                           status=400)

    api = API(client_id='1', client_secret='2', access_token='access_token')
    api.post(url='hey', data='new=True')
예제 #2
0
def test_api_post_request_no_access_token():
    """ Should raise ValueError if the API is called without an access_token. """

    with patch("buffpy.api.OAuth2Session", return_value=MagicMock(access_token=None)), \
            pytest.raises(ValueError):
        api = API(client_id="1",
                  client_secret="2",
                  access_token="access_token")
        api.post(url="hey", data="new=True")
예제 #3
0
def test_api_post_parse_buffpy_error():
    """ Should raise a BuffpyRestException, if the API's response is >= 400. """

    httpretty.register_uri(httpretty.POST,
                           "https://api.bufferapp.com/1/hey",
                           status=400)

    with pytest.raises(BuffpyRestException):
        api = API(client_id="1",
                  client_secret="2",
                  access_token="access_token")
        api.post(url="hey", data="new=True")
예제 #4
0
def test_api_post_request_no_access_token():
  '''
    Test simply api post request without access_token
  '''

  with patch('buffpy.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')
예제 #5
0
파일: test_api.py 프로젝트: talpor/buffpy
def test_api_post_request_no_access_token():
  '''
    Test simply api post request without access_token
  '''

  with patch('buffpy.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')
예제 #6
0
def test_api_post_request():
    """ Should call Buffer for a given POST request. """

    mocked_session = MagicMock()
    mocked_session.post.return_value = MOCKED_RESPONSE

    with patch("buffpy.api.OAuth2Session", 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")
예제 #7
0
def test_api_post_request():
  '''
    Test simply api post request
  '''

  with patch('buffpy.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')
예제 #8
0
파일: test_api.py 프로젝트: talpor/buffpy
def test_api_post_request():
  '''
    Test simply api post request
  '''

  with patch('buffpy.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')