Added test that the token can be signed and retrieved

This commit is contained in:
Rebecca Law
2016-01-13 14:34:45 +00:00
parent 725b976d31
commit a6dda26ba1
2 changed files with 12 additions and 2 deletions

View File

@@ -113,7 +113,8 @@ def delete_token(service_id):
return jsonify(result="error", message="Token not found"), 404
def _generate_token():
def _generate_token(token=None):
if not token:
token = uuid.uuid4()
serializer = URLSafeSerializer(current_app.config.get('SECRET_KEY'))
return serializer.dumps(str(token), current_app.config.get('DANGEROUS_SALT'))

View File

@@ -318,6 +318,15 @@ def test_delete_token(notify_api, notify_db, notify_db_session, sample_service):
assert len(Token.query.all()) == 0
def test_token_generated_can_be_read_again(notify_api):
from app.service.views.rest import (_generate_token, _get_token)
import uuid
with notify_api.test_request_context():
token = str(uuid.uuid4())
signed_token = _generate_token(token=token)
assert token == _get_token(signed_token)
def test_create_template(notify_api, notify_db, notify_db_session, sample_service):
"""
Tests POST endpoint '/<service_id>/template' a template can be created