# Path: ricloud/samples/utils.py
# def await_response(resource, timeout=60):
#     """Poll the API until processing resolves or the timeout is reached."""
#     timeout_time = time.time() + timeout
#     while resource.state in ("pending", "processing") and time.time() < timeout_time:
# 
#         time.sleep(1)
# 
#         resource.refresh()


import pytest
import ricloud
from ricloud.samples.utils import await_response
SOURCE_IDENTIFIER = "john.appleseed@reincubate.com"


@pytest.mark.integration
class TestIntegration(object):
    def test_ok(self):
        user = ricloud.User.create(identifier=USER_IDENTIFIER)

        assert isinstance(user, ricloud.User)
        assert user.identifier == USER_IDENTIFIER

        session = ricloud.Session.create(
            source={
                "user": user,
                "type": "mocks.mock",
                "identifier": SOURCE_IDENTIFIER,
            },
            payload={"password": "abcd1234"},
        )

        assert isinstance(session, ricloud.Session)

        await_response(session)

        assert session.state == "active"

        info_poll = ricloud.Poll.create(session=session, payload={"info_types": ["*"]})

        assert isinstance(info_poll, ricloud.Poll)


# Path: ricloud/samples/utils.py
# def await_response(resource, timeout=60):
#     """Poll the API until processing resolves or the timeout is reached."""
#     timeout_time = time.time() + timeout
#     while resource.state in ("pending", "processing") and time.time() < timeout_time:
# 
#         time.sleep(1)
# 
#         resource.refresh()


# Path: tests/test_integration.py
import pytest
import ricloud
from ricloud.samples.utils import await_response

SOURCE_IDENTIFIER = "john.appleseed@reincubate.com"


@pytest.mark.integration
class TestIntegration(object):
    def test_ok(self):
        user = ricloud.User.create(identifier=USER_IDENTIFIER)

        assert isinstance(user, ricloud.User)
        assert user.identifier == USER_IDENTIFIER

        session = ricloud.Session.create(
            source={
                "user": user,
                "type": "mocks.mock",
                "identifier": SOURCE_IDENTIFIER,
            },
            payload={"password": "abcd1234"},
        )

        assert isinstance(session, ricloud.Session)

        await_response(session)

        assert session.state == "active"

        info_poll = ricloud.Poll.create(session=session, payload={"info_types": ["*"]})

        assert isinstance(info_poll, ricloud.Poll)


        await_response(info_poll)