コード例 #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
コード例 #2
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"