filter revoked api keys older than 7 days

This commit is contained in:
chrisw
2018-03-12 11:55:19 +00:00
parent 40a0b8f03c
commit c98705696a
2 changed files with 27 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timedelta
import pytest
from sqlalchemy.exc import IntegrityError
@@ -95,3 +95,21 @@ def test_save_api_key_should_not_create_new_service_history(sample_service):
save_model_api_key(api_key)
assert Service.get_history_model().query.count() == 1
@pytest.mark.parametrize('days_old, expected_length', [(5, 1), (8, 0)])
def test_should_not_return_revoked_api_keys_older_than_7_days(
sample_service,
days_old,
expected_length
):
expired_api_key = ApiKey(**{'service': sample_service,
'name': sample_service.name,
'created_by': sample_service.created_by,
'key_type': KEY_TYPE_NORMAL,
'expiry_date': datetime.utcnow() - timedelta(days=days_old)})
save_model_api_key(expired_api_key)
all_api_keys = get_model_api_keys(service_id=sample_service.id)
assert len(all_api_keys) == expected_length