Add another 3 days leeway to give time for payment processing times (#17542)

This commit is contained in:
Paulus Schoutsen 2018-10-17 10:45:01 +02:00 committed by Pascal Vizeli
parent 15f4ed74ac
commit 326787ef1a
2 changed files with 18 additions and 4 deletions

View file

@ -5,7 +5,7 @@ For more details about this component, please refer to the documentation at
https://home-assistant.io/components/cloud/ https://home-assistant.io/components/cloud/
""" """
import asyncio import asyncio
from datetime import datetime from datetime import datetime, timedelta
import json import json
import logging import logging
import os import os
@ -162,7 +162,7 @@ class Cloud:
@property @property
def subscription_expired(self): def subscription_expired(self):
"""Return a boolean if the subscription has expired.""" """Return a boolean if the subscription has expired."""
return dt_util.utcnow() > self.expiration_date return dt_util.utcnow() > self.expiration_date + timedelta(days=3)
@property @property
def expiration_date(self): def expiration_date(self):

View file

@ -142,14 +142,28 @@ def test_write_user_info():
@asyncio.coroutine @asyncio.coroutine
def test_subscription_expired(hass): def test_subscription_expired(hass):
"""Test subscription being expired.""" """Test subscription being expired after 3 days of expiration."""
cl = cloud.Cloud(hass, cloud.MODE_DEV, None, None) cl = cloud.Cloud(hass, cloud.MODE_DEV, None, None)
token_val = { token_val = {
'custom:sub-exp': '2017-11-13' 'custom:sub-exp': '2017-11-13'
} }
with patch.object(cl, '_decode_claims', return_value=token_val), \ with patch.object(cl, '_decode_claims', return_value=token_val), \
patch('homeassistant.util.dt.utcnow', patch('homeassistant.util.dt.utcnow',
return_value=utcnow().replace(year=2018)): 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 assert cl.subscription_expired