Updated the Provider stats and rates DAO objects to query based on the identifier in the ProviderDetails object.

- updated all tests
- changed teardown to leave provider details rows on end of individual tests
This commit is contained in:
Martyn Inglis
2016-05-06 09:09:47 +01:00
parent fedbb27ffd
commit 57e05feafb
15 changed files with 149 additions and 135 deletions

View File

@@ -1,5 +1,5 @@
from sqlalchemy import func
from app.models import (ProviderStatistics, SMS_PROVIDERS, EMAIL_PROVIDERS)
from app.models import (ProviderStatistics, SMS_PROVIDERS, EMAIL_PROVIDERS, ProviderDetails)
def get_provider_statistics(service, **kwargs):
@@ -32,7 +32,9 @@ def get_fragment_count(service, date_from, date_to):
def filter_query(query, service, **kwargs):
query = query.filter_by(service=service)
if 'providers' in kwargs:
query = query.filter(ProviderStatistics.provider.in_(kwargs['providers']))
providers = ProviderDetails.query.filter(ProviderDetails.identifier.in_(kwargs['providers'])).all()
provider_ids = [provider.id for provider in providers]
query = query.filter(ProviderStatistics.provider_id.in_(provider_ids))
if 'date_from' in kwargs:
query.filter(ProviderStatistics.day >= kwargs['date_from'])
if 'date_to' in kwargs: