2016-11-07 17:41:49 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
2016-09-15 15:59:34 +01:00
|
|
|
def test_job_schema_doesnt_return_notifications(sample_notification_with_job):
|
2016-06-10 15:54:21 +01:00
|
|
|
from app.schemas import job_schema
|
|
|
|
|
|
2016-09-15 15:59:34 +01:00
|
|
|
job = sample_notification_with_job.job
|
2016-06-10 15:54:21 +01:00
|
|
|
assert job.notifications.count() == 1
|
|
|
|
|
|
|
|
|
|
data, errors = job_schema.dump(job)
|
|
|
|
|
|
|
|
|
|
assert not errors
|
|
|
|
|
assert 'notifications' not in data
|
2016-09-23 14:44:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_notification_schema_ignores_absent_api_key(sample_notification_with_job):
|
|
|
|
|
from app.schemas import notification_with_template_schema
|
|
|
|
|
|
|
|
|
|
data = notification_with_template_schema.dump(sample_notification_with_job).data
|
|
|
|
|
assert data['key_name'] is None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_notification_schema_adds_api_key_name(sample_notification_with_api_key):
|
|
|
|
|
from app.schemas import notification_with_template_schema
|
|
|
|
|
|
|
|
|
|
data = notification_with_template_schema.dump(sample_notification_with_api_key).data
|
|
|
|
|
assert data['key_name'] == 'Test key'
|
2016-11-07 17:41:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('user_attribute, user_value', [
|
|
|
|
|
('name', 'New User'),
|
|
|
|
|
('email_address', 'newuser@mail.com'),
|
|
|
|
|
('mobile_number', '+4407700900460')
|
|
|
|
|
])
|
|
|
|
|
def test_user_schema_accepts_valid_attributes(user_attribute, user_value):
|
|
|
|
|
update_dict = {
|
|
|
|
|
user_attribute: user_value
|
|
|
|
|
}
|
|
|
|
|
from app.schemas import user_update_schema_load_json
|
|
|
|
|
|
|
|
|
|
data, errors = user_update_schema_load_json.load(update_dict)
|
|
|
|
|
assert not errors
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('user_attribute, user_value', [
|
|
|
|
|
('name', None),
|
|
|
|
|
('name', ''),
|
|
|
|
|
('email_address', 'bademail@...com'),
|
|
|
|
|
('mobile_number', '+44077009')
|
|
|
|
|
])
|
|
|
|
|
def test_user_schema_rejects_invalid_attributes(user_attribute, user_value):
|
|
|
|
|
from app.schemas import user_update_schema_load_json
|
|
|
|
|
update_dict = {
|
|
|
|
|
user_attribute: user_value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with pytest.raises(Exception):
|
|
|
|
|
data, errors = user_update_schema_load_json.load(update_dict)
|