make job.created_by nullable

Since letter jobs from the API aren't created by any single individual,
lets make created_by nullable. Note: We'll have to make sure that we
update the admin app to handle these jobs nicely
This commit is contained in:
Leo Hemsted
2017-07-27 12:58:13 +01:00
parent 11458c421b
commit f528236eda
4 changed files with 27 additions and 7 deletions

View File

@@ -654,7 +654,7 @@ class Job(db.Model):
unique=False, unique=False,
nullable=True) nullable=True)
created_by = db.relationship('User') created_by = db.relationship('User')
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False) created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=True)
scheduled_for = db.Column( scheduled_for = db.Column(
db.DateTime, db.DateTime,
index=True, index=True,

View File

@@ -144,7 +144,7 @@ def process_sms_or_email_notification(*, form, notification_type, api_key, templ
return notification return notification
def process_letter_notification(*, letter_data, api_key, template, service): def process_letter_notification(*, letter_data, api_key, template):
job = create_letter_api_job(template) job = create_letter_api_job(template)
notification = create_letter_notification(letter_data, job, api_key) notification = create_letter_notification(letter_data, job, api_key)
build_dvla_file.apply_async([str(job.id)], queue=QueueNames.JOBS) build_dvla_file.apply_async([str(job.id)], queue=QueueNames.JOBS)

View File

@@ -0,0 +1,24 @@
"""empty message
Revision ID: 0113_job_created_by_nullable
Revises: 0112_add_start_end_dates
Create Date: 2017-07-27 11:12:34.938086
"""
# revision identifiers, used by Alembic.
revision = '0113_job_created_by_nullable'
down_revision = '0112_add_start_end_dates'
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.alter_column('job', 'created_by', nullable=True)
def downgrade():
# This will error if there are any jobs with no created_by - we'll have to decide how to handle those as and when
# we downgrade
op.alter_column('job', 'created_by', nullable=False)

View File

@@ -1,4 +1,3 @@
import uuid import uuid
from flask import url_for, json from flask import url_for, json
@@ -11,9 +10,6 @@ from tests import create_authorization_header
from tests.app.db import create_service, create_template from tests.app.db import create_service, create_template
pytestmark = pytest.mark.skip('Leters not currently implemented')
def letter_request(client, data, service_id, _expected_status=201): def letter_request(client, data, service_id, _expected_status=201):
resp = client.post( resp = client.post(
url_for('v2_notifications.post_notification', notification_type='letter'), url_for('v2_notifications.post_notification', notification_type='letter'),
@@ -160,7 +156,7 @@ def test_post_letter_notification_returns_403_if_not_allowed_to_send_notificatio
} }
error_json = letter_request(client, data, service_id=service.id, _expected_status=400) error_json = letter_request(client, data, service_id=service.id, _expected_status=400)
assert error_json['status_code'] == 403 assert error_json['status_code'] == 400
assert error_json['errors'] == [ assert error_json['errors'] == [
{'error': 'BadRequestError', 'message': 'Cannot send letters'} {'error': 'BadRequestError', 'message': 'Cannot send letters'}
] ]