mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-12 09:58:04 -04:00
Return count of live services on organisations too
This makes it consistent, so the admin app can always rely on that property being available.
This commit is contained in:
@@ -367,6 +367,13 @@ class Organisation(db.Model):
|
||||
nullable=True,
|
||||
)
|
||||
|
||||
@property
|
||||
def live_services(self):
|
||||
return [
|
||||
service for service in self.services
|
||||
if service.active and not service.restricted
|
||||
]
|
||||
|
||||
def serialize(self):
|
||||
return {
|
||||
"id": str(self.id),
|
||||
@@ -384,6 +391,7 @@ class Organisation(db.Model):
|
||||
domain.domain for domain in self.domains
|
||||
],
|
||||
"request_to_go_live_notes": self.request_to_go_live_notes,
|
||||
"count_of_live_services": len(self.live_services),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -516,10 +516,7 @@ def get_orgs_and_services(user):
|
||||
for service in org.services
|
||||
if service.active and service in user.services
|
||||
],
|
||||
'count_of_live_services': len([
|
||||
service for service in org.services
|
||||
if service.active and not service.restricted
|
||||
]),
|
||||
'count_of_live_services': len(org.live_services),
|
||||
}
|
||||
for org in user.organisations if org.active
|
||||
],
|
||||
|
||||
@@ -26,8 +26,10 @@ def test_get_all_organisations(admin_request, notify_db_session):
|
||||
assert len(response) == 2
|
||||
assert response[0]['name'] == 'active org'
|
||||
assert response[0]['active'] is True
|
||||
assert response[0]['count_of_live_services'] == 0
|
||||
assert response[1]['name'] == 'inactive org'
|
||||
assert response[1]['active'] is False
|
||||
assert response[1]['count_of_live_services'] == 0
|
||||
|
||||
|
||||
def test_get_organisation_by_id(admin_request, notify_db_session):
|
||||
@@ -53,6 +55,7 @@ def test_get_organisation_by_id(admin_request, notify_db_session):
|
||||
'email_branding_id',
|
||||
'domains',
|
||||
'request_to_go_live_notes',
|
||||
'count_of_live_services',
|
||||
}
|
||||
assert response['id'] == str(org.id)
|
||||
assert response['name'] == 'test_org_1'
|
||||
@@ -66,6 +69,7 @@ def test_get_organisation_by_id(admin_request, notify_db_session):
|
||||
assert response['email_branding_id'] is None
|
||||
assert response['domains'] == []
|
||||
assert response['request_to_go_live_notes'] is None
|
||||
assert response['count_of_live_services'] == 0
|
||||
|
||||
|
||||
def test_get_organisation_by_id_returns_domains(admin_request, notify_db_session):
|
||||
|
||||
Reference in New Issue
Block a user