Changed the token endpoints so that you can renew a token and revoke a token.

Updated create service so the token is created at that time
This commit is contained in:
Rebecca Law
2016-01-13 16:04:56 +00:00
parent a6dda26ba1
commit 255dddaa27
4 changed files with 85 additions and 52 deletions

View File

@@ -1,10 +1,13 @@
import uuid
from app.dao import tokens_dao
from datetime import datetime
from app.models import Token
from pytest import fail
from sqlalchemy.orm.exc import NoResultFound
def test_should_create_token(notify_api, notify_db, notify_db_session, sample_service):
def test_save_token_should_create_new_token(notify_api, notify_db, notify_db_session, sample_service):
token = uuid.uuid4()
api_token = Token(**{'token': token, 'service_id': sample_service.id})
@@ -15,16 +18,29 @@ def test_should_create_token(notify_api, notify_db, notify_db_session, sample_se
assert all_tokens[0].token == str(token)
def test_should_delete_api_token(notify_api, notify_db, notify_db_session, sample_service):
token = uuid.uuid4()
api_token = Token(**{'token': token, 'service_id': sample_service.id})
def test_save_token_should_update_the_token(notify_api, notify_db, notify_db_session, sample_service):
api_token = Token(**{'token': uuid.uuid4(), 'service_id': sample_service.id})
tokens_dao.save_token_model(api_token)
now = datetime.utcnow()
saved_token = tokens_dao.get_model_tokens(sample_service.id)
tokens_dao.save_token_model(saved_token, update_dict={'id': saved_token.id, 'expiry_date': now})
all_tokens = tokens_dao.get_model_tokens()
assert len(all_tokens) == 1
assert all_tokens[0].expiry_date == now
tokens_dao.delete_model_token(all_tokens[0])
empty_token_list = tokens_dao.get_model_tokens()
assert len(empty_token_list) == 0
def test_get_token_should_raise_exception_when_service_does_not_exist(notify_api, notify_db, notify_db_session,
sample_service):
try:
tokens_dao.get_model_tokens(sample_service.id)
fail()
except NoResultFound:
pass
def test_get_token_should_return_none_when_service_does_not_exist(notify_api, notify_db, notify_db_session,
sample_service):
assert tokens_dao.get_model_tokens(service_id=sample_service.id, raise_=False) is None
def test_should_return_token_for_service(notify_api, notify_db, notify_db_session, sample_service):
@@ -34,12 +50,3 @@ def test_should_return_token_for_service(notify_api, notify_db, notify_db_sessio
token = tokens_dao.get_model_tokens(sample_service.id)
assert token.service_id == sample_service.id
assert token.token == str(the_token)
def test_delete_model_token_should_remove_token(notify_api, notify_db, notify_db_session, sample_service):
api_token = Token(**{'token': str(uuid.uuid4()), 'service_id': sample_service.id})
tokens_dao.save_token_model(api_token)
all_tokens = tokens_dao.get_model_tokens()
assert len(all_tokens) == 1
tokens_dao.delete_model_token(all_tokens[0])
assert len(tokens_dao.get_model_tokens()) == 0