Merge branch 'master' into notification-created-status

Conflicts:
	app/dao/notifications_dao.py
This commit is contained in:
Rebecca Law
2016-06-22 16:15:56 +01:00
8 changed files with 50 additions and 46 deletions

View File

@@ -8,17 +8,16 @@ from app.dao.api_key_dao import (save_model_api_key,
get_unsigned_secrets,
get_unsigned_secret,
_generate_secret,
_get_secret)
_get_secret, expire_api_key)
from app.models import ApiKey
def test_secret_is_signed_and_can_be_read_again(notify_api):
import uuid
def test_secret_is_signed_and_can_be_read_again(notify_api, mocker):
with notify_api.test_request_context():
token = str(uuid.uuid4())
signed_secret = _generate_secret(token=token)
assert token == _get_secret(signed_secret)
assert signed_secret != token
mocker.patch("uuid.uuid4", return_value='some_uuid')
signed_secret = _generate_secret()
assert 'some_uuid' == _get_secret(signed_secret)
assert signed_secret != 'some_uuid'
def test_save_api_key_should_create_new_api_key_and_history(notify_api,
@@ -45,20 +44,18 @@ def test_expire_api_key_should_update_the_api_key_and_create_history_record(noti
notify_db,
notify_db_session,
sample_api_key):
now = datetime.utcnow()
saved_api_key = get_model_api_keys(service_id=sample_api_key.service_id, id=sample_api_key.id)
save_model_api_key(saved_api_key, update_dict={'id': saved_api_key.id, 'expiry_date': now})
expire_api_key(service_id=sample_api_key.service_id, api_key_id=sample_api_key.id)
all_api_keys = get_model_api_keys(service_id=sample_api_key.service_id)
assert len(all_api_keys) == 1
assert all_api_keys[0].expiry_date == now
assert all_api_keys[0].secret == saved_api_key.secret
assert all_api_keys[0].id == saved_api_key.id
assert all_api_keys[0].service_id == saved_api_key.service_id
assert all_api_keys[0].expiry_date <= datetime.utcnow()
assert all_api_keys[0].secret == sample_api_key.secret
assert all_api_keys[0].id == sample_api_key.id
assert all_api_keys[0].service_id == sample_api_key.service_id
all_history = saved_api_key.get_history_model().query.all()
all_history = sample_api_key.get_history_model().query.all()
assert len(all_history) == 2
assert all_history[0].id == saved_api_key.id
assert all_history[1].id == saved_api_key.id
assert all_history[0].id == sample_api_key.id
assert all_history[1].id == sample_api_key.id
sorted_all_history = sorted(all_history, key=lambda hist: hist.version)
sorted_all_history[0].version = 1
sorted_all_history[1].version = 2

View File

@@ -75,6 +75,12 @@ def test_should_not_update_status_by_id_if_not_sending_and_does_not_update_job(n
assert job == Job.query.get(notification.job_id)
def test_should_update_status_if_created(notify_db, notify_db_session):
notification = sample_notification(notify_db, notify_db_session, status='created')
assert Notification.query.get(notification.id).status == 'created'
assert update_notification_status_by_id(notification.id, 'failed', 'failure')
def test_should_by_able_to_update_status_by_id_from_pending_to_delivered(sample_template, sample_job):
data = _notification_json(sample_template, job_id=sample_job.id, status='sending')
notification = Notification(**data)