mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-05 02:41:14 -05:00
Add convenience fields to job to make processing
easier.
This commit is contained in:
@@ -105,6 +105,8 @@ class Job(db.Model):
|
|||||||
|
|
||||||
id = db.Column(UUID(as_uuid=True), primary_key=True)
|
id = db.Column(UUID(as_uuid=True), primary_key=True)
|
||||||
original_file_name = db.Column(db.String, nullable=False)
|
original_file_name = db.Column(db.String, nullable=False)
|
||||||
|
bucket_name = db.Column(db.String, nullable=False)
|
||||||
|
file_name = db.Column(db.String, nullable=False)
|
||||||
service_id = db.Column(db.BigInteger, db.ForeignKey('services.id'), index=True, unique=False)
|
service_id = db.Column(db.BigInteger, db.ForeignKey('services.id'), index=True, unique=False)
|
||||||
service = db.relationship('Service', backref=db.backref('jobs', lazy='dynamic'))
|
service = db.relationship('Service', backref=db.backref('jobs', lazy='dynamic'))
|
||||||
template_id = db.Column(db.BigInteger, db.ForeignKey('templates.id'), index=True, unique=False)
|
template_id = db.Column(db.BigInteger, db.ForeignKey('templates.id'), index=True, unique=False)
|
||||||
|
|||||||
28
migrations/versions/0005_add_job_details.py
Normal file
28
migrations/versions/0005_add_job_details.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 0005_add_job_details
|
||||||
|
Revises: 0004_create_jobs
|
||||||
|
Create Date: 2016-01-15 15:57:38.022562
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '0005_add_job_details'
|
||||||
|
down_revision = '0004_create_jobs'
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column('jobs', sa.Column('bucket_name', sa.String(), nullable=False))
|
||||||
|
op.add_column('jobs', sa.Column('file_name', sa.String(), nullable=False))
|
||||||
|
### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_column('jobs', 'file_name')
|
||||||
|
op.drop_column('jobs', 'bucket_name')
|
||||||
|
### end Alembic commands ###
|
||||||
@@ -78,10 +78,15 @@ def sample_job(notify_db,
|
|||||||
if template is None:
|
if template is None:
|
||||||
template = sample_template(notify_db, notify_db_session,
|
template = sample_template(notify_db, notify_db_session,
|
||||||
service=service)
|
service=service)
|
||||||
|
job_id = uuid.uuid4()
|
||||||
|
bucket_name = 'service-{}-notify'.format(service.id)
|
||||||
|
file_name = '{}.csv'.format(job_id)
|
||||||
data = {
|
data = {
|
||||||
'id': uuid.uuid4(),
|
'id': uuid.uuid4(),
|
||||||
'service_id': service.id,
|
'service_id': service.id,
|
||||||
'template_id': template.id,
|
'template_id': template.id,
|
||||||
|
'bucket_name': bucket_name,
|
||||||
|
'file_name': file_name,
|
||||||
'original_file_name': 'some.csv'
|
'original_file_name': 'some.csv'
|
||||||
}
|
}
|
||||||
job = Job(**data)
|
job = Job(**data)
|
||||||
|
|||||||
@@ -13,11 +13,16 @@ from app.models import Job
|
|||||||
def test_save_job(notify_db, notify_db_session, sample_template):
|
def test_save_job(notify_db, notify_db_session, sample_template):
|
||||||
|
|
||||||
assert Job.query.count() == 0
|
assert Job.query.count() == 0
|
||||||
|
|
||||||
job_id = uuid.uuid4()
|
job_id = uuid.uuid4()
|
||||||
|
bucket_name = 'service-{}-notify'.format(sample_template.service.id)
|
||||||
|
file_name = '{}.csv'.format(job_id)
|
||||||
data = {
|
data = {
|
||||||
'id': job_id,
|
'id': job_id,
|
||||||
'service_id': sample_template.service_id,
|
'service_id': sample_template.service.id,
|
||||||
'template_id': sample_template.id,
|
'template_id': sample_template.id,
|
||||||
|
'bucket_name': bucket_name,
|
||||||
|
'file_name': file_name,
|
||||||
'original_file_name': 'some.csv'
|
'original_file_name': 'some.csv'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,21 +34,9 @@ def test_save_job(notify_db, notify_db_session, sample_template):
|
|||||||
assert job == job_from_db
|
assert job == job_from_db
|
||||||
|
|
||||||
|
|
||||||
def test_get_job_by_id(notify_db, notify_db_session, sample_template):
|
def test_get_job_by_id(notify_db, notify_db_session, sample_job):
|
||||||
assert Job.query.count() == 0
|
job_from_db = get_job_by_id(sample_job.id)
|
||||||
job_id = uuid.uuid4()
|
assert sample_job == job_from_db
|
||||||
data = {
|
|
||||||
'id': job_id,
|
|
||||||
'service_id': sample_template.service_id,
|
|
||||||
'template_id': sample_template.id,
|
|
||||||
'original_file_name': 'some.csv'
|
|
||||||
}
|
|
||||||
job = Job(**data)
|
|
||||||
save_job(job)
|
|
||||||
|
|
||||||
job_from_db = get_job_by_id(job_id)
|
|
||||||
|
|
||||||
assert job == job_from_db
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_jobs_for_service(notify_db, notify_db_session, sample_job):
|
def test_get_jobs_for_service(notify_db, notify_db_session, sample_job):
|
||||||
|
|||||||
@@ -69,11 +69,15 @@ def test_post_job(notify_api, notify_db, notify_db_session, sample_template):
|
|||||||
template_id = sample_template.id
|
template_id = sample_template.id
|
||||||
service_id = sample_template.service.id
|
service_id = sample_template.service.id
|
||||||
original_file_name = 'thisisatest.csv'
|
original_file_name = 'thisisatest.csv'
|
||||||
|
bucket_name = 'service-{}-notify'.format(service_id)
|
||||||
|
file_name = '{}.csv'.format(job_id)
|
||||||
data = {
|
data = {
|
||||||
'id': str(job_id),
|
'id': str(job_id),
|
||||||
'service': service_id,
|
'service': service_id,
|
||||||
'template': template_id,
|
'template': template_id,
|
||||||
'original_file_name': original_file_name
|
'original_file_name': original_file_name,
|
||||||
|
'bucket_name': bucket_name,
|
||||||
|
'file_name': file_name,
|
||||||
}
|
}
|
||||||
with notify_api.test_request_context():
|
with notify_api.test_request_context():
|
||||||
with notify_api.test_client() as client:
|
with notify_api.test_client() as client:
|
||||||
|
|||||||
Reference in New Issue
Block a user