コード例 #1
0
def test_run_refresh(monkeypatch):
    """Test refreshing a query view."""
    _was_called = False

    def _get_run(url, parms=None, default=None):
        nonlocal _was_called
        assert url == "/livequery/v1/orgs/Z100/runs/abcdefg"
        _was_called = True
        return {
            "org_key": "Z100",
            "name": "FoobieBletch",
            "id": "abcdefg",
            "status": "COMPLETE"
        }

    api = CBCloudAPI(url="https://example.com",
                     token="ABCD/1234",
                     org_key="Z100",
                     ssl_verify=True)
    patch_cbc_sdk_api(monkeypatch, api, GET=_get_run)
    run = Run(
        api, "abcdefg", {
            "org_key": "Z100",
            "name": "FoobieBletch",
            "id": "abcdefg",
            "status": "ACTIVE"
        })
    rc = run.refresh()
    assert _was_called
    assert rc
    assert run.org_key == "Z100"
    assert run.name == "FoobieBletch"
    assert run.id == "abcdefg"
    assert run.status == "COMPLETE"
コード例 #2
0
def test_run_stop_failed(monkeypatch):
    """Test the failure to stop a running query."""
    _was_called = False

    def _execute_stop(url, body, **kwargs):
        nonlocal _was_called
        assert url == "/livequery/v1/orgs/Z100/runs/abcdefg/status"
        assert body == {"status": "CANCELLED"}
        _was_called = True
        return StubResponse(
            {"error_message": "The query is not presently running."}, 409)

    api = CBCloudAPI(url="https://example.com",
                     token="ABCD/1234",
                     org_key="Z100",
                     ssl_verify=True)
    patch_cbc_sdk_api(monkeypatch, api, PUT=_execute_stop)
    run = Run(
        api, "abcdefg", {
            "org_key": "Z100",
            "name": "FoobieBletch",
            "id": "abcdefg",
            "status": "CANCELLED"
        })
    rc = run.stop()
    assert _was_called
    assert not rc
コード例 #3
0
def test_run_stop(monkeypatch):
    """Test stopping a running query."""
    _was_called = False

    def _execute_stop(url, body, **kwargs):
        nonlocal _was_called
        assert url == "/livequery/v1/orgs/Z100/runs/abcdefg/status"
        assert body == {"status": "CANCELLED"}
        _was_called = True
        return StubResponse({
            "org_key": "Z100",
            "name": "FoobieBletch",
            "id": "abcdefg",
            "status": "CANCELLED"
        })

    api = CBCloudAPI(url="https://example.com",
                     token="ABCD/1234",
                     org_key="Z100",
                     ssl_verify=True)
    patch_cbc_sdk_api(monkeypatch, api, PUT=_execute_stop)
    run = Run(
        api, "abcdefg", {
            "org_key": "Z100",
            "name": "FoobieBletch",
            "id": "abcdefg",
            "status": "ACTIVE"
        })
    rc = run.stop()
    assert _was_called
    assert rc
    assert run.org_key == "Z100"
    assert run.name == "FoobieBletch"
    assert run.id == "abcdefg"
    assert run.status == "CANCELLED"
コード例 #4
0
def test_run_delete_failed(monkeypatch):
    """Test a failure in the attempt to delete a query."""
    _was_called = False

    def _execute_delete(url):
        nonlocal _was_called
        assert url == "/livequery/v1/orgs/Z100/runs/abcdefg"
        _was_called = True
        return StubResponse(None, 403)

    api = CBCloudAPI(url="https://example.com",
                     token="ABCD/1234",
                     org_key="Z100",
                     ssl_verify=True)
    patch_cbc_sdk_api(monkeypatch, api, DELETE=_execute_delete)
    run = Run(
        api, "abcdefg", {
            "org_key": "Z100",
            "name": "FoobieBletch",
            "id": "abcdefg",
            "status": "ACTIVE"
        })
    rc = run.delete()
    assert _was_called
    assert not rc
    assert not run._is_deleted
コード例 #5
0
def test_run_stop_exception(cbcsdk_mock):
    """Testing Run.stop() when response from server is not JSON parsable."""
    api = cbcsdk_mock.api
    cbcsdk_mock.mock_request("GET", "/livequery/v1/orgs/test/runs/run_id",
                             GET_RUN_RESP)
    unparsable_response = CBCSDKMock.StubResponse(
        contents="ThisIsntJSONParsable", scode=200, json_parsable=False)
    cbcsdk_mock.mock_request("PUT",
                             "/livequery/v1/orgs/test/runs/run_id/status",
                             unparsable_response)
    assert unparsable_response._json_parsable is False
    run = Run(api, model_unique_id="run_id")
    with pytest.raises(ServerError):
        run.stop()
コード例 #6
0
def test_run_delete(monkeypatch):
    _was_called = False

    def _execute_delete(url):
        nonlocal _was_called
        assert url == "/livequery/v1/orgs/Z100/runs/abcdefg"
        if _was_called:
            pytest.fail("_execute_delete should not be called twice!")
        _was_called = True
        return StubResponse(None)

    api = CBCloudAPI(url="https://example.com",
                     token="ABCD/1234",
                     org_key="Z100",
                     ssl_verify=True)
    patch_cbapi(monkeypatch, api, DELETE=_execute_delete)
    run = Run(
        api, "abcdefg", {
            "org_key": "Z100",
            "name": "FoobieBletch",
            "id": "abcdefg",
            "status": "ACTIVE"
        })
    rc = run.delete()
    assert _was_called
    assert rc
    assert run._is_deleted
    # Now ensure that certain operations that don't make sense on a deleted object raise ApiError
    with pytest.raises(ApiError):
        run.refresh()
    with pytest.raises(ApiError):
        run.stop()
    # And make sure that deleting a deleted object returns True immediately
    rc = run.delete()
    assert rc