예제 #1
0
def test_request_strategy_sets_session_on_parent_when_not_already_set(
        mock_client):
    mock_client.client.get_session.return_value = None
    strategy = RequestStrategy()
    strategy.set_client(mock_client.client)
    mock_client.client.get_session.assert_called_once_with()
    mock_client.client.set_session.assert_called_once()
def test_request_strategy_get_method_delegates_to_parent_handlers(mock_requests, mock_client):
    mock_requests.get("mock://testserver.com", json={"active": True}, status_code=200)

    strategy = RequestStrategy()
    strategy.set_client(mock_client.client)

    response = strategy.get("mock://testserver.com", params={"foo": sentinel.params})

    assert response == sentinel.result
    assert_request_called_once(mock_requests, "mock://testserver.com", "GET")
    assert_mock_client_called_once(mock_client, None)
def test_request_strategy_does_not_set_session_if_already_set(mock_client):
    mock_client.client.get_session.return_value = sentinel.session
    strategy = RequestStrategy()
    strategy.set_client(mock_client.client)
    mock_client.client.get_session.assert_called_once_with()
    mock_client.client.set_session.assert_not_called()