コード例 #1
0
def test_fifteen_retries(yahoo_response):
    r = yahoo_response('v1/groups/groupname/', ygError={}, status=500)
    yga = YahooGroupsAPI('groupname')
    with raises(yahoogroupsapi.Recoverable):
        yga.HackGroupInfo()

    assert len(r.calls) == 15
コード例 #2
0
def test_one_retry(yahoo_response):
    result = {'ok': 'on second try'}
    r = yahoo_response('v1/groups/groupname/', ygError={}, status=500)
    r = yahoo_response('v1/groups/groupname/', result)
    yga = YahooGroupsAPI('groupname')
    json = yga.HackGroupInfo()

    assert len(r.calls) == 2
    assert json == result
コード例 #3
0
def test_unauthorized_error(yahoo_response):
    r = yahoo_response('v1/groups/groupname/',
                       ygError={"hostname": "gapi17.grp.bf1.yahoo.com", "httpStatus": 401,
                                "errorMessage": "User does not have READ permission for GROUP. Mess...", "errorCode": 1103,
                                "sid": "SID:YHOO:groups.yahoo.com:00000000000000000000000000000000:0"},
                       ygPerms=YGPERMS_NONE, status=401)
    yga = YahooGroupsAPI('groupname')
    with raises(yahoogroupsapi.Unauthorized):
        yga.HackGroupInfo()
    assert len(r.calls) == 1
コード例 #4
0
def test_warc_enabled():
    # Note that this does not use the responses mocking framework, as it conflicts with the warc captures.
    # This makes a real request to Yahoo, so might fail.
    url = 'https://groups.yahoo.com/api/v1/groups/test/'

    yga = YahooGroupsAPI('test')
    writer = BufferWARCWriter(gzip=False)
    yga.set_warc_writer(writer)
    yga.HackGroupInfo()

    expected = [(url, 'response'), (url, 'request')]
    actual = [(record.rec_headers['WARC-Target-URI'], record.rec_type)
              for record in ArchiveIterator(writer.get_stream())]
    assert expected == actual
コード例 #5
0
def test_not_authenticated_error(yahoo_response):
    r = yahoo_response('v1/groups/groupname/', status=307)
    yga = YahooGroupsAPI('groupname')
    with raises(yahoogroupsapi.NotAuthenticated):
        yga.HackGroupInfo()
    assert len(r.calls) == 15
コード例 #6
0
def test_correct_ua(yahoo_response):
    r = yahoo_response('v1/groups/groupname/', {})
    yga = YahooGroupsAPI('groupname', headers={'User-Agent': 'test'})
    yga.HackGroupInfo()
    assert r.calls[0].request.headers['user-agent'] == 'test'
コード例 #7
0
def test_not_authenticated_error(yahoo_response):
    r = yahoo_response('v1/groups/groupname/', status=307)
    yga = YahooGroupsAPI('groupname')
    with raises(yahoogroupsapi.Recoverable):    # Temporary fix, replaced: yahoogroupsapi.NotAuthenticated
        yga.HackGroupInfo()
    assert len(r.calls) == 15