Esempio n. 1
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
Esempio n. 2
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()
Esempio n. 3
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
Esempio n. 4
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"