예제 #1
0
def session(
    url: str,
    username: str,
    password: str,
    mock_session_factory: Callable[[], requests.Session],
):
    """Create a LimeSurvey Session fixture."""
    session = Session(url, username, password, mock_session_factory)

    yield session

    session.close()
예제 #2
0
def test_interface_off(
    url: str,
    username: str,
    password: str,
    off_session_factory: Callable[[], requests.Session],
):
    """Test effect of JSON RPC not enabled."""
    with pytest.raises(LimeSurveyError,
                       match="JSON RPC interface is not enabled"):
        Session(url, username, password, off_session_factory)
예제 #3
0
def test_session_context(
    url: str,
    username: str,
    password: str,
    mock_session_factory: Callable[[], requests.Session],
):
    """Test context creates a session key."""
    with Session(url, username, password, mock_session_factory) as session:
        assert not session.closed
        assert session.key == LimeSurveyMockAdapter.session_key

    assert session.closed
    assert session.key is None

    with pytest.raises(AttributeError, match="can't set attribute"):
        session.key = "123456"

    with pytest.raises(AttributeError, match="can't set attribute"):
        session.closed = False
예제 #4
0
def test_api_error(session: Session):
    """Test non-null error raises LimeSurveyApiError."""
    with pytest.raises(LimeSurveyApiError, match="API Error!"):
        session.__api_error()
예제 #5
0
def test_empty_response(session: Session):
    """Test empty response."""
    with pytest.raises(LimeSurveyError, match="RPC interface not enabled"):
        session.__disabled()
예제 #6
0
def test_http_error(session: Session):
    """Test HTTP errors."""
    with pytest.raises(requests.HTTPError):
        session.__http_error()
예제 #7
0
def test_json_rpc(session: Session):
    """Test JSON RPC response structure."""
    result = session.__ok()

    assert result == "OK"
예제 #8
0
def test_mismatching_request_id(session: Session):
    """Test result with status key raises LimeSurveyStatusError."""
    with pytest.raises(LimeSurveyError,
                       match="response does not match the one in the request"):
        session.__bad_id()
예제 #9
0
def test_status_ok(session: Session):
    """Test result with OK status does not raise errors."""
    result = session.__status_ok()

    assert result["status"] == "OK"
예제 #10
0
def test_status_error(session: Session):
    """Test result with status key raises LimeSurveyStatusError."""
    with pytest.raises(LimeSurveyStatusError, match="Status Error!"):
        session.__status_error()