mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-09 11:39:49 -04:00
marshmallow schemas no longer return _status_enum column
now return `status`, as they should
This commit is contained in:
@@ -220,7 +220,9 @@ class NotificationModelSchema(BaseSchema):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = models.Notification
|
model = models.Notification
|
||||||
strict = True
|
strict = True
|
||||||
exclude = ('_personalisation', 'job', 'service', 'template', 'api_key', '')
|
exclude = ('_personalisation', 'job', 'service', 'template', 'api_key', '_status_enum', '_status_fkey')
|
||||||
|
|
||||||
|
status = fields.String(required=False)
|
||||||
|
|
||||||
|
|
||||||
class BaseTemplateSchema(BaseSchema):
|
class BaseTemplateSchema(BaseSchema):
|
||||||
@@ -315,6 +317,7 @@ class NotificationSchema(ma.Schema):
|
|||||||
class Meta:
|
class Meta:
|
||||||
strict = True
|
strict = True
|
||||||
|
|
||||||
|
status = fields.String(required=False)
|
||||||
personalisation = fields.Dict(required=False)
|
personalisation = fields.Dict(required=False)
|
||||||
|
|
||||||
|
|
||||||
@@ -369,7 +372,7 @@ class NotificationWithTemplateSchema(BaseSchema):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = models.Notification
|
model = models.Notification
|
||||||
strict = True
|
strict = True
|
||||||
exclude = ('_personalisation',)
|
exclude = ('_personalisation', '_status_enum', '_status_fkey')
|
||||||
|
|
||||||
template = fields.Nested(
|
template = fields.Nested(
|
||||||
TemplateSchema,
|
TemplateSchema,
|
||||||
@@ -377,6 +380,7 @@ class NotificationWithTemplateSchema(BaseSchema):
|
|||||||
dump_only=True
|
dump_only=True
|
||||||
)
|
)
|
||||||
job = fields.Nested(JobSchema, only=["id", "original_file_name"], dump_only=True)
|
job = fields.Nested(JobSchema, only=["id", "original_file_name"], dump_only=True)
|
||||||
|
status = fields.String(required=False)
|
||||||
personalisation = fields.Dict(required=False)
|
personalisation = fields.Dict(required=False)
|
||||||
key_type = field_for(models.Notification, 'key_type', required=True)
|
key_type = field_for(models.Notification, 'key_type', required=True)
|
||||||
key_name = fields.String()
|
key_name = fields.String()
|
||||||
|
|||||||
@@ -447,6 +447,25 @@ def test_get_all_notifications_for_job_filtered_by_status(
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_all_notifications_for_job_returns_correct_format(
|
||||||
|
client,
|
||||||
|
sample_notification_with_job
|
||||||
|
):
|
||||||
|
service_id = sample_notification_with_job.service_id
|
||||||
|
job_id = sample_notification_with_job.job_id
|
||||||
|
response = client.get(
|
||||||
|
path='/service/{}/job/{}/notifications'.format(service_id, job_id),
|
||||||
|
headers=[create_authorization_header()]
|
||||||
|
)
|
||||||
|
assert response.status_code == 200
|
||||||
|
resp = json.loads(response.get_data(as_text=True))
|
||||||
|
assert len(resp['notifications']) == 1
|
||||||
|
assert resp['notifications'][0]['id'] == str(sample_notification_with_job.id)
|
||||||
|
assert resp['notifications'][0]['status'] == sample_notification_with_job.status
|
||||||
|
assert '_status_fkey' not in resp['notifications'][0]
|
||||||
|
assert '_status_enum' not in resp['notifications'][0]
|
||||||
|
|
||||||
|
|
||||||
def test_get_job_by_id(notify_api, sample_job):
|
def test_get_job_by_id(notify_api, sample_job):
|
||||||
job_id = str(sample_job.id)
|
job_id = str(sample_job.id)
|
||||||
service_id = sample_job.service.id
|
service_id = sample_job.service.id
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from marshmallow import ValidationError
|
from marshmallow import ValidationError
|
||||||
from sqlalchemy import desc
|
from sqlalchemy import desc
|
||||||
|
|
||||||
@@ -33,6 +32,22 @@ def test_notification_schema_adds_api_key_name(sample_notification_with_api_key)
|
|||||||
assert data['key_name'] == 'Test key'
|
assert data['key_name'] == 'Test key'
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('schema_name', [
|
||||||
|
'notification_with_template_schema',
|
||||||
|
'notification_schema',
|
||||||
|
'notification_with_template_schema',
|
||||||
|
'notification_with_personalisation_schema',
|
||||||
|
])
|
||||||
|
def test_notification_schema_has_correct_status(sample_notification, schema_name):
|
||||||
|
from app import schemas
|
||||||
|
|
||||||
|
data = getattr(schemas, schema_name).dump(sample_notification).data
|
||||||
|
|
||||||
|
assert data['status'] == sample_notification.status
|
||||||
|
assert '_status_enum' not in data
|
||||||
|
assert '_status_fkey' not in data
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('user_attribute, user_value', [
|
@pytest.mark.parametrize('user_attribute, user_value', [
|
||||||
('name', 'New User'),
|
('name', 'New User'),
|
||||||
('email_address', 'newuser@mail.com'),
|
('email_address', 'newuser@mail.com'),
|
||||||
|
|||||||
Reference in New Issue
Block a user