Fix DB query for cert count for authority

This commit is contained in:
Jasmine Schladen 2020-12-03 17:56:39 -08:00
parent 42957cffc7
commit 576c69c8e5
2 changed files with 13 additions and 2 deletions

View File

@ -872,5 +872,4 @@ def get_issued_cert_count_for_authority(authority):
:return: :return:
""" """
query = database.session_query(Certificate.id).filter(Authority.id == authority.id) return database.db.session.query(Certificate).filter(Certificate.authority_id == authority.id).count()
return database.get_count(query)

View File

@ -1377,3 +1377,15 @@ def test_boolean_filter(client):
headers=VALID_ADMIN_HEADER_TOKEN, headers=VALID_ADMIN_HEADER_TOKEN,
) )
assert resp.status_code == 200 assert resp.status_code == 200
def test_issued_cert_count_for_authority(authority):
from lemur.tests.factories import CertificateFactory
from lemur.certificates.service import get_issued_cert_count_for_authority
# create a few certs issued by the authority
CertificateFactory(authority=authority, name="test_issued_cert_count_for_authority1")
CertificateFactory(authority=authority, name="test_issued_cert_count_for_authority2")
CertificateFactory(authority=authority, name="test_issued_cert_count_for_authority3")
assert get_issued_cert_count_for_authority(authority) == 3