Extracted serialiser for encryption into a flask module

- allows mocking easier
- shared across methods
- not built everytime
This commit is contained in:
Martyn Inglis
2016-02-16 15:28:30 +00:00
parent e42da7dd54
commit 18d63e241b
7 changed files with 46 additions and 16 deletions

View File

@@ -200,6 +200,7 @@ def test_should_allow_valid_sms_notification(notify_api, sample_template, mocker
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.tasks.send_sms.apply_async')
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
data = {
'to': '+441234123123',
@@ -222,9 +223,7 @@ def test_should_allow_valid_sms_notification(notify_api, sample_template, mocker
app.celery.tasks.send_sms.apply_async.assert_called_once_with(
(str(sample_template.service_id),
notification_id,
ANY,
notify_api.config['SECRET_KEY'],
notify_api.config['DANGEROUS_SALT'])
"something_encrypted")
)
assert response.status_code == 201
assert notification_id

View File

@@ -0,0 +1,20 @@
from app.encryption import Encryption
encryption = Encryption()
def test_should_encrypt_content(notify_api):
encryption.init_app(notify_api)
assert encryption.encrypt("this") != "this"
def test_should_decrypt_content(notify_api):
encryption.init_app(notify_api)
encrypted = encryption.encrypt("this")
assert encryption.decrypt(encrypted) == "this"
def test_should_encrypt_json(notify_api):
encryption.init_app(notify_api)
encrypted = encryption.encrypt({"this": "that"})
assert encryption.decrypt(encrypted) == {"this": "that"}