mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-18 21:48:49 -04:00
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:
@@ -1,4 +1,3 @@
|
||||
import math
|
||||
from sqlalchemy import desc, func
|
||||
|
||||
from datetime import (
|
||||
@@ -19,8 +18,8 @@ from app.models import (
|
||||
TEMPLATE_TYPE_SMS,
|
||||
TEMPLATE_TYPE_EMAIL,
|
||||
Template,
|
||||
ProviderStatistics
|
||||
)
|
||||
ProviderStatistics,
|
||||
ProviderDetails)
|
||||
|
||||
from notifications_utils.template import get_sms_fragment_count
|
||||
|
||||
@@ -60,7 +59,9 @@ def dao_get_template_statistics_for_service(service_id, limit_days=None):
|
||||
|
||||
|
||||
@transactional
|
||||
def dao_create_notification(notification, notification_type, provider):
|
||||
def dao_create_notification(notification, notification_type, provider_identifier):
|
||||
provider = ProviderDetails.query.filter_by(identifier=provider_identifier).one()
|
||||
|
||||
if notification.job_id:
|
||||
db.session.query(Job).filter_by(
|
||||
id=notification.job_id
|
||||
@@ -97,7 +98,7 @@ def dao_create_notification(notification, notification_type, provider):
|
||||
update_count = db.session.query(ProviderStatistics).filter_by(
|
||||
day=date.today(),
|
||||
service_id=notification.service_id,
|
||||
provider=provider
|
||||
provider_id=provider.id
|
||||
).update({'unit_count': ProviderStatistics.unit_count + (
|
||||
1 if notification_type == TEMPLATE_TYPE_EMAIL else get_sms_fragment_count(notification.content_char_count))})
|
||||
|
||||
@@ -105,7 +106,7 @@ def dao_create_notification(notification, notification_type, provider):
|
||||
provider_stats = ProviderStatistics(
|
||||
day=notification.created_at.date(),
|
||||
service_id=notification.service_id,
|
||||
provider=provider,
|
||||
provider_id=provider.id,
|
||||
unit_count=1 if notification_type == TEMPLATE_TYPE_EMAIL else get_sms_fragment_count(
|
||||
notification.content_char_count))
|
||||
db.session.add(provider_stats)
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from app.models import ProviderRates
|
||||
from app.models import ProviderRates, ProviderDetails
|
||||
from app import db
|
||||
from app.dao.dao_utils import transactional
|
||||
|
||||
|
||||
@transactional
|
||||
def create_provider_rates(provider, valid_from, rate):
|
||||
provider_rates = ProviderRates(provider=provider, valid_from=valid_from, rate=rate)
|
||||
def create_provider_rates(provider_identifier, valid_from, rate):
|
||||
provider = ProviderDetails.query.filter_by(identifier=provider_identifier).one()
|
||||
|
||||
provider_rates = ProviderRates(provider_id=provider.id, valid_from=valid_from, rate=rate)
|
||||
db.session.add(provider_rates)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user