Example #1
0
async def test_is_onboarded():
    """Test the is onboarded function."""
    opp = Mock()
    opp.data = {}

    assert onboarding.async_is_onboarded(opp)

    opp.data[onboarding.DOMAIN] = True
    assert onboarding.async_is_onboarded(opp)

    opp.data[onboarding.DOMAIN] = {"done": []}
    assert not onboarding.async_is_onboarded(opp)
Example #2
0
def _need_auth(opp, path: str) -> bool:
    """Return if a path need authentication."""
    if not async_is_onboarded(opp) and NO_AUTH_ONBOARDING.match(path):
        return False
    if NO_AUTH.match(path):
        return False
    return True
Example #3
0
async def test_migration(opp, opp_storage):
    """Test migrating onboarding to new version."""
    opp_storage[onboarding.STORAGE_KEY] = {
        "version": 1,
        "data": {
            "done": ["user"]
        }
    }
    assert await async_setup_component(opp, "onboarding", {})
    assert onboarding.async_is_onboarded(opp)
Example #4
0
async def test_not_setup_views_if_onboarded(opp, opp_storage):
    """Test if onboarding is done, we don't setup views."""
    mock_storage(opp_storage, {"done": onboarding.STEPS})

    with patch("openpeerpower.components.onboarding.views.async_setup"
               ) as mock_setup:
        assert await async_setup_component(opp, "onboarding", {})

    assert len(mock_setup.mock_calls) == 0
    assert onboarding.DOMAIN not in opp.data
    assert onboarding.async_is_onboarded(opp)
Example #5
0
async def test_setup_views_if_not_onboarded(opp):
    """Test if onboarding is not done, we setup views."""
    with patch(
            "openpeerpower.components.onboarding.views.async_setup",
            return_value=mock_coro(),
    ) as mock_setup:
        assert await async_setup_component(opp, "onboarding", {})

    assert len(mock_setup.mock_calls) == 1
    assert onboarding.DOMAIN in opp.data

    assert not onboarding.async_is_onboarded(opp)
Example #6
0
async def test_having_owner_finishes_user_step(opp, opp_storage):
    """If owner user already exists, mark user step as complete."""
    MockUser(is_owner=True).add_to_opp(opp)

    with patch("openpeerpower.components.onboarding.views.async_setup"
               ) as mock_setup, patch.object(onboarding, "STEPS",
                                             [onboarding.STEP_USER]):
        assert await async_setup_component(opp, "onboarding", {})

    assert len(mock_setup.mock_calls) == 0
    assert onboarding.DOMAIN not in opp.data
    assert onboarding.async_is_onboarded(opp)

    done = opp_storage[onboarding.STORAGE_KEY]["data"]["done"]
    assert onboarding.STEP_USER in done