mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 14:31:57 -05:00
Updated jobs_Dao to make a job stats row when making a job - saves the ambiguity later as to whether the row exists.
This commit is contained in:
@@ -11,7 +11,7 @@ from app.models import (Job,
|
||||
Template,
|
||||
JOB_STATUS_SCHEDULED,
|
||||
JOB_STATUS_PENDING,
|
||||
LETTER_TYPE)
|
||||
LETTER_TYPE, JobStatistics)
|
||||
from app.statsd_decorators import statsd
|
||||
|
||||
|
||||
@@ -109,6 +109,11 @@ def dao_get_future_scheduled_job_by_id_and_service_id(job_id, service_id):
|
||||
|
||||
|
||||
def dao_create_job(job):
|
||||
job_stats = JobStatistics(
|
||||
job_id=job.id,
|
||||
updated_at=datetime.utcnow()
|
||||
)
|
||||
db.session.add(job_stats)
|
||||
db.session.add(job)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ from app.dao.jobs_dao import (
|
||||
dao_update_job_status,
|
||||
dao_get_all_notifications_for_job,
|
||||
dao_get_jobs_older_than_limited_by)
|
||||
from app.models import Job
|
||||
from app.models import Job, JobStatistics
|
||||
|
||||
from tests.app.conftest import sample_notification as create_notification
|
||||
from tests.app.conftest import sample_job as create_job
|
||||
@@ -130,10 +130,23 @@ def test_create_job(sample_template):
|
||||
dao_create_job(job)
|
||||
|
||||
assert Job.query.count() == 1
|
||||
assert JobStatistics.query.count() == 1
|
||||
job_from_db = Job.query.get(job_id)
|
||||
assert job == job_from_db
|
||||
assert job_from_db.notifications_delivered == 0
|
||||
assert job_from_db.notifications_failed == 0
|
||||
job_stats_from_db = JobStatistics.query.filter_by(job_id=job_id).all()
|
||||
assert len(job_stats_from_db) == 1
|
||||
assert job_stats_from_db[0].sms_sent == 0
|
||||
assert job_stats_from_db[0].emails_sent == 0
|
||||
assert job_stats_from_db[0].letters_sent == 0
|
||||
|
||||
assert job_stats_from_db[0].sms_failed == 0
|
||||
assert job_stats_from_db[0].emails_failed == 0
|
||||
assert job_stats_from_db[0].letters_failed == 0
|
||||
|
||||
assert job_stats_from_db[0].sms_delivered == 0
|
||||
assert job_stats_from_db[0].emails_delivered == 0
|
||||
|
||||
|
||||
def test_get_job_by_id(sample_job):
|
||||
|
||||
Reference in New Issue
Block a user