Add basic unit test for the servicekeyworker
This commit is contained in:
parent
3b496e2759
commit
0afc222214
2 changed files with 26 additions and 3 deletions
23
workers/servicekeyworker/test/test_servicekeyworker.py
Normal file
23
workers/servicekeyworker/test/test_servicekeyworker.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
from datetime import datetime, timedelta
|
||||
from mock import patch
|
||||
|
||||
from data import model
|
||||
from workers.servicekeyworker.servicekeyworker import ServiceKeyWorker
|
||||
from util.morecollections import AttrDict
|
||||
|
||||
from test.fixtures import *
|
||||
|
||||
def test_refresh_service_key(initialized_db):
|
||||
# Create a service key for testing.
|
||||
test_key = model.service_keys.create_service_key('test', 'somekid', 'quay', '', {},
|
||||
datetime.now() + timedelta(minutes=10))
|
||||
|
||||
instance_keys = AttrDict(dict(local_key_id=test_key.kid, service_key_expiration=10))
|
||||
|
||||
with patch('workers.servicekeyworker.servicekeyworker.instance_keys', instance_keys):
|
||||
worker = ServiceKeyWorker()
|
||||
worker._refresh_service_key()
|
||||
|
||||
# Ensure the key's expiration was changed.
|
||||
updated_key = model.service_keys.get_service_key(test_key.kid, approved_only=False)
|
||||
assert updated_key.expiration_date > test_key.expiration_date
|
Reference in a new issue