コード例 #1
0
def test_subscription_not_expired():
    """Test subscription not being expired."""
    cl = cloud.Cloud(None, cloud.MODE_DEV)
    cl.id_token = jwt.encode({'custom:sub-exp': '2017-11-13'}, 'test')

    with patch('homeassistant.util.dt.utcnow',
               return_value=utcnow().replace(year=2017, month=11, day=9)):
        assert not cl.subscription_expired
コード例 #2
0
ファイル: test_init.py プロジェクト: ywhere/home-assistant
def test_subscription_not_expired(hass):
    """Test subscription not being expired."""
    cl = cloud.Cloud(hass, cloud.MODE_DEV, None, None)
    token_val = {'custom:sub-exp': '2017-11-13'}
    with patch.object(cl, '_decode_claims', return_value=token_val), \
            patch('homeassistant.util.dt.utcnow',
                  return_value=utcnow().replace(year=2017, month=11, day=9)):
        assert not cl.subscription_expired
コード例 #3
0
ファイル: test_init.py プロジェクト: ywhere/home-assistant
def test_logout_clears_info(mock_os, hass):
    """Test logging out disconnects and removes info."""
    cl = cloud.Cloud(hass, cloud.MODE_DEV, None, None)
    cl.iot = MagicMock()
    cl.iot.disconnect.return_value = mock_coro()

    yield from cl.logout()

    assert len(cl.iot.disconnect.mock_calls) == 1
    assert cl.id_token is None
    assert cl.access_token is None
    assert cl.refresh_token is None
    assert len(mock_os.remove.mock_calls) == 1
コード例 #4
0
ファイル: test_init.py プロジェクト: ywhere/home-assistant
def test_write_user_info():
    """Test writing user info works."""
    mopen = mock_open()

    cl = cloud.Cloud(MagicMock(), cloud.MODE_DEV, None, None)
    cl.id_token = 'test-id-token'
    cl.access_token = 'test-access-token'
    cl.refresh_token = 'test-refresh-token'

    with patch('homeassistant.components.cloud.open', mopen, create=True):
        cl.write_user_info()

    handle = mopen()

    assert len(handle.write.mock_calls) == 1
    data = json.loads(handle.write.mock_calls[0][1][0])
    assert data == {
        'access_token': 'test-access-token',
        'id_token': 'test-id-token',
        'refresh_token': 'test-refresh-token',
    }
コード例 #5
0
def test_initialize_loads_info(mock_os, hass):
    """Test initialize will load info from config file."""
    mock_os.path.isfile.return_value = True
    mopen = mock_open(read_data=json.dumps({
        'id_token': 'test-id-token',
        'access_token': 'test-access-token',
        'refresh_token': 'test-refresh-token',
    }))

    cl = cloud.Cloud(hass, cloud.MODE_DEV, None, None)
    cl.iot = MagicMock()
    cl.iot.connect.return_value = mock_coro()

    with patch('homeassistant.components.cloud.open', mopen, create=True), \
            patch('homeassistant.components.cloud.Cloud._decode_claims'):
        yield from cl.async_start(None)

    assert cl.id_token == 'test-id-token'
    assert cl.access_token == 'test-access-token'
    assert cl.refresh_token == 'test-refresh-token'
    assert len(cl.iot.connect.mock_calls) == 1
コード例 #6
0
ファイル: test_init.py プロジェクト: ywhere/home-assistant
def test_subscription_expired(hass):
    """Test subscription being expired after 3 days of expiration."""
    cl = cloud.Cloud(hass, cloud.MODE_DEV, None, None)
    token_val = {'custom:sub-exp': '2017-11-13'}
    with patch.object(cl, '_decode_claims', return_value=token_val), \
            patch('homeassistant.util.dt.utcnow',
                  return_value=utcnow().replace(year=2017, month=11, day=13)):
        assert not cl.subscription_expired

    with patch.object(cl, '_decode_claims', return_value=token_val), \
            patch('homeassistant.util.dt.utcnow',
                  return_value=utcnow().replace(
                      year=2017, month=11, day=15, hour=23, minute=59,
                      second=59)):
        assert not cl.subscription_expired

    with patch.object(cl, '_decode_claims', return_value=token_val), \
            patch('homeassistant.util.dt.utcnow',
                  return_value=utcnow().replace(
                      year=2017, month=11, day=16, hour=0, minute=0,
                      second=0)):
        assert cl.subscription_expired
コード例 #7
0
def test_subscription_not_expired_without_sub_in_claim():
    """Test that we do not enforce subscriptions yet."""
    cl = cloud.Cloud(None, cloud.MODE_DEV)
    cl.id_token = jwt.encode({}, 'test')

    assert not cl.subscription_expired