mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
Merge pull request #2855 from alphagov/contact-list-used-property
Add property to contact lists to say if they’ve ever been used
This commit is contained in:
@@ -2123,7 +2123,8 @@ class ServiceContactList(db.Model):
|
|||||||
updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow)
|
updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow)
|
||||||
archived = db.Column(db.Boolean, nullable=False, default=False)
|
archived = db.Column(db.Boolean, nullable=False, default=False)
|
||||||
|
|
||||||
def get_job_count(self):
|
@property
|
||||||
|
def job_count(self):
|
||||||
today = datetime.datetime.utcnow().date()
|
today = datetime.datetime.utcnow().date()
|
||||||
return Job.query.filter(
|
return Job.query.filter(
|
||||||
Job.contact_list_id == self.id,
|
Job.contact_list_id == self.id,
|
||||||
@@ -2137,13 +2138,20 @@ class ServiceContactList(db.Model):
|
|||||||
)
|
)
|
||||||
).count()
|
).count()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def has_jobs(self):
|
||||||
|
return bool(Job.query.filter(
|
||||||
|
Job.contact_list_id == self.id,
|
||||||
|
).first())
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
created_at_in_bst = convert_utc_to_bst(self.created_at)
|
created_at_in_bst = convert_utc_to_bst(self.created_at)
|
||||||
contact_list = {
|
contact_list = {
|
||||||
"id": str(self.id),
|
"id": str(self.id),
|
||||||
"original_file_name": self.original_file_name,
|
"original_file_name": self.original_file_name,
|
||||||
"row_count": self.row_count,
|
"row_count": self.row_count,
|
||||||
"job_count": self.get_job_count(),
|
"recent_job_count": self.job_count,
|
||||||
|
"has_jobs": self.has_jobs,
|
||||||
"template_type": self.template_type,
|
"template_type": self.template_type,
|
||||||
"service_id": str(self.service_id),
|
"service_id": str(self.service_id),
|
||||||
"created_by": self.created_by.name,
|
"created_by": self.created_by.name,
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ def test_get_contact_list(admin_request, notify_db_session):
|
|||||||
|
|
||||||
assert len(response) == 1
|
assert len(response) == 1
|
||||||
assert response[0] == contact_list.serialize()
|
assert response[0] == contact_list.serialize()
|
||||||
assert response[0]['job_count'] == 0
|
assert response[0]['recent_job_count'] == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('days_of_email_retention, expected_job_count', (
|
@pytest.mark.parametrize('days_of_email_retention, expected_job_count', (
|
||||||
@@ -107,10 +107,12 @@ def test_get_contact_list_counts_jobs(
|
|||||||
assert len(response) == 2
|
assert len(response) == 2
|
||||||
|
|
||||||
assert response[0]['id'] == str(contact_list_2.id)
|
assert response[0]['id'] == str(contact_list_2.id)
|
||||||
assert response[0]['job_count'] == expected_job_count
|
assert response[0]['recent_job_count'] == expected_job_count
|
||||||
|
assert response[0]['has_jobs'] is True
|
||||||
|
|
||||||
assert response[1]['id'] == str(contact_list_1.id)
|
assert response[1]['id'] == str(contact_list_1.id)
|
||||||
assert response[1]['job_count'] == 0
|
assert response[1]['recent_job_count'] == 0
|
||||||
|
assert response[1]['has_jobs'] is False
|
||||||
|
|
||||||
|
|
||||||
def test_get_contact_list_returns_for_service(admin_request, notify_db_session):
|
def test_get_contact_list_returns_for_service(admin_request, notify_db_session):
|
||||||
|
|||||||
Reference in New Issue
Block a user