mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-09 19:04:05 -04:00
Added job_status to marshmallow
- ensured statues not deleted on test runs - returns in API call Merge branch 'add-new-column-to-jobs-for-delayed-sending' into scheduled-delivery-of-jobs Conflicts: app/models.py
This commit is contained in:
@@ -310,7 +310,7 @@ JOB_STATUS_SENDING_LIMITS_EXCEEDED = 'sending limits exceeded'
|
||||
JOB_STATUS_SCHEDULED = 'scheduled'
|
||||
|
||||
|
||||
class JobStatusTypes(db.Model):
|
||||
class JobStatus(db.Model):
|
||||
__tablename__ = 'job_status'
|
||||
|
||||
name = db.Column(db.String(255), primary_key=True)
|
||||
|
||||
@@ -208,6 +208,8 @@ class JobSchema(BaseSchema):
|
||||
dump_to="created_by", only=["id", "name"], dump_only=True)
|
||||
created_by = field_for(models.Job, 'created_by', required=True, load_only=True)
|
||||
|
||||
job_status = field_for(models.JobStatus, 'name', required=False)
|
||||
|
||||
class Meta:
|
||||
model = models.Job
|
||||
exclude = ('notifications',)
|
||||
|
||||
@@ -20,59 +20,68 @@ from app.models import Job, Template, NotificationHistory
|
||||
|
||||
|
||||
def upgrade():
|
||||
session = Session(bind=op.get_bind())
|
||||
|
||||
go_live = datetime.datetime.strptime('2016-05-18', '%Y-%m-%d')
|
||||
notifications_history_start_date = datetime.datetime.strptime('2016-06-26 23:21:55', '%Y-%m-%d %H:%M:%S')
|
||||
jobs = session.query(Job).join(Template).filter(Job.service_id == '95316ff0-e555-462d-a6e7-95d26fbfd091',
|
||||
Job.created_at >= go_live,
|
||||
Job.created_at < notifications_history_start_date).all()
|
||||
|
||||
for job in jobs:
|
||||
for i in range(0, job.notifications_delivered):
|
||||
notification = NotificationHistory(id=uuid.uuid4(),
|
||||
job_id=job.id,
|
||||
service_id=job.service_id,
|
||||
template_id=job.template.id,
|
||||
template_version=job.template_version,
|
||||
key_type='normal',
|
||||
content_char_count=len(job.template.content),
|
||||
notification_type=job.template.template_type,
|
||||
created_at=job.created_at,
|
||||
sent_at=job.processing_finished,
|
||||
sent_by='ses' if job.template.template_type == 'email' else 'mmg',
|
||||
status='delivered')
|
||||
|
||||
session.add(notification)
|
||||
|
||||
for i in range(0, job.notifications_failed):
|
||||
notification = NotificationHistory(id=uuid.uuid4(),
|
||||
job_id=job.id,
|
||||
service_id=job.service_id,
|
||||
template_id=job.template.id,
|
||||
template_version=job.template_version,
|
||||
key_type='normal',
|
||||
content_char_count=len(job.template.content),
|
||||
notification_type=job.template.template_type,
|
||||
created_at=job.created_at,
|
||||
sent_at=job.processing_finished,
|
||||
sent_by='ses' if job.template.template_type == 'email' else 'mmg',
|
||||
status='permanent-failure')
|
||||
session.add(notification)
|
||||
session.commit()
|
||||
#
|
||||
# REMOVED
|
||||
# This script has been applied and doesn't need to be re-applied
|
||||
# note that by referencing the model objects in migration files, any subsequent alteration of the model and thus
|
||||
# the database causes all previous migration scripts to fail as the model and DB will be inconsistent in this
|
||||
# past state.
|
||||
#
|
||||
# session = Session(bind=op.get_bind())
|
||||
#
|
||||
# go_live = datetime.datetime.strptime('2016-05-18', '%Y-%m-%d')
|
||||
# notifications_history_start_date = datetime.datetime.strptime('2016-06-26 23:21:55', '%Y-%m-%d %H:%M:%S')
|
||||
# jobs = session.query(Job).join(Template).filter(Job.service_id == '95316ff0-e555-462d-a6e7-95d26fbfd091',
|
||||
# Job.created_at >= go_live,
|
||||
# Job.created_at < notifications_history_start_date).all()
|
||||
#
|
||||
# for job in jobs:
|
||||
# for i in range(0, job.notifications_delivered):
|
||||
# notification = NotificationHistory(id=uuid.uuid4(),
|
||||
# job_id=job.id,
|
||||
# service_id=job.service_id,
|
||||
# template_id=job.template.id,
|
||||
# template_version=job.template_version,
|
||||
# key_type='normal',
|
||||
# content_char_count=len(job.template.content),
|
||||
# notification_type=job.template.template_type,
|
||||
# created_at=job.created_at,
|
||||
# sent_at=job.processing_finished,
|
||||
# sent_by='ses' if job.template.template_type == 'email' else 'mmg',
|
||||
# status='delivered')
|
||||
#
|
||||
# session.add(notification)
|
||||
#
|
||||
# for i in range(0, job.notifications_failed):
|
||||
# notification = NotificationHistory(id=uuid.uuid4(),
|
||||
# job_id=job.id,
|
||||
# service_id=job.service_id,
|
||||
# template_id=job.template.id,
|
||||
# template_version=job.template_version,
|
||||
# key_type='normal',
|
||||
# content_char_count=len(job.template.content),
|
||||
# notification_type=job.template.template_type,
|
||||
# created_at=job.created_at,
|
||||
# sent_at=job.processing_finished,
|
||||
# sent_by='ses' if job.template.template_type == 'email' else 'mmg',
|
||||
# status='permanent-failure')
|
||||
# session.add(notification)
|
||||
# session.commit()
|
||||
pass
|
||||
|
||||
|
||||
def downgrade():
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
session = Session(bind=op.get_bind())
|
||||
|
||||
go_live = datetime.datetime.strptime('2016-05-18', '%Y-%m-%d')
|
||||
notifications_history_start_date = datetime.datetime.strptime('2016-06-26 23:21:55', '%Y-%m-%d %H:%M:%S')
|
||||
|
||||
session.query(NotificationHistory).filter(
|
||||
NotificationHistory.created_at >= go_live,
|
||||
NotificationHistory.service_id == '95316ff0-e555-462d-a6e7-95d26fbfd091',
|
||||
NotificationHistory.created_at < notifications_history_start_date).delete()
|
||||
|
||||
session.commit()
|
||||
### end Alembic commands ###
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
# session = Session(bind=op.get_bind())
|
||||
#
|
||||
# go_live = datetime.datetime.strptime('2016-05-18', '%Y-%m-%d')
|
||||
# notifications_history_start_date = datetime.datetime.strptime('2016-06-26 23:21:55', '%Y-%m-%d %H:%M:%S')
|
||||
#
|
||||
# session.query(NotificationHistory).filter(
|
||||
# NotificationHistory.created_at >= go_live,
|
||||
# NotificationHistory.service_id == '95316ff0-e555-462d-a6e7-95d26fbfd091',
|
||||
# NotificationHistory.created_at < notifications_history_start_date).delete()
|
||||
#
|
||||
# session.commit()
|
||||
# ### end Alembic commands ###
|
||||
pass
|
||||
|
||||
@@ -111,8 +111,7 @@ def test_get_job_by_id(notify_api, sample_job):
|
||||
def test_create_job(notify_api, sample_template, mocker, fake_uuid):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
from time import sleep
|
||||
sleep(30)
|
||||
|
||||
mocker.patch('app.celery.tasks.process_job.apply_async')
|
||||
data = {
|
||||
'id': fake_uuid,
|
||||
@@ -125,6 +124,7 @@ def test_create_job(notify_api, sample_template, mocker, fake_uuid):
|
||||
path = '/service/{}/job'.format(sample_template.service.id)
|
||||
auth_header = create_authorization_header(service_id=sample_template.service.id)
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
|
||||
response = client.post(
|
||||
path,
|
||||
data=json.dumps(data),
|
||||
@@ -139,7 +139,8 @@ def test_create_job(notify_api, sample_template, mocker, fake_uuid):
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert resp_json['data']['id'] == fake_uuid
|
||||
assert resp_json['data']['service'] == str(sample_template.service.id)
|
||||
assert resp_json['data']['status'] == 'pending'
|
||||
assert resp_json['data']['job_status'] == 'pending'
|
||||
assert resp_json['data']['template'] == str(sample_template.id)
|
||||
assert resp_json['data']['original_file_name'] == 'thisisatest.csv'
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ def notify_db_session(request, notify_db):
|
||||
def teardown():
|
||||
notify_db.session.remove()
|
||||
for tbl in reversed(notify_db.metadata.sorted_tables):
|
||||
if tbl.name not in ["provider_details", "key_types", "branding_type"]:
|
||||
if tbl.name not in ["provider_details", "key_types", "branding_type", "job_status"]:
|
||||
notify_db.engine.execute(tbl.delete())
|
||||
notify_db.session.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user