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:
Chris Hill-Scott
2019-06-12 13:15:25 +01:00
parent b6fdb269e4
commit d974ab3b86
3 changed files with 13 additions and 4 deletions

View File

@@ -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),
}

View File

@@ -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
],

View File

@@ -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):