def test_request_keep_sending_last_cookies(): mocker = Mox() http_mock = mocker.CreateMockAnything() response_headers1 = {'set-cookie': 5} response_headers2 = {'good': 10} response_headers3 = {'set-cookie': 20} request_headers1 = {} request_headers2 = {'Cookie': 5} request_headers3 = {'Cookie': 5} request_headers4 = {'Cookie': 20} # 1st request http_mock.request('http://somewhere.com', 'GET', '', request_headers1). \ AndReturn((response_headers1, '')) # 2nd request http_mock.request('http://somewhere.com', 'GET', '', request_headers2). \ AndReturn((response_headers2, '')) # 3rd request http_mock.request('http://somewhere.com', 'GET', '', request_headers3). \ AndReturn((response_headers3, '')) # 4th request http_mock.request('http://somewhere.com', 'GET', '', request_headers4). \ AndReturn(({}, '')) mocker.ReplayAll() bol = Bolacha() bol.http = http_mock for x in range(4): bol.request('http://somewhere.com', 'GET') mocker.VerifyAll()
def test_request_handle_cookies(): mocker = Mox() http_mock = mocker.CreateMockAnything() request_headers1 = {} response_headers1 = {'set-cookie': 'Will log in'} request_headers2 = {'Cookie': 'Will log in'} response_headers2 = {'set-cookie': 'Already logged as root'} request_headers3 = {'Cookie': 'Already logged as root'} response_headers3 = {'set-cookie': 'Just logged out'} request_headers4 = {'Cookie': 'Just logged out'} response_headers4 = {'set-cookie': 'Will log in'} http_mock.request('http://somewhere.com', 'GET', '', request_headers1). \ AndReturn((response_headers1, '')) http_mock.request('http://somewhere.com', 'GET', '', request_headers2). \ AndReturn((response_headers2, '')) http_mock.request('http://somewhere.com', 'GET', '', request_headers3). \ AndReturn((response_headers3, '')) http_mock.request('http://somewhere.com', 'GET', '', request_headers4). \ AndReturn((response_headers4, '')) mocker.ReplayAll() bol = Bolacha() bol.http = http_mock for x in range(4): bol.request('http://somewhere.com', 'GET') mocker.VerifyAll()