mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
change update_provider_stats to use billable_units
updated tests etc, and removed some old tests that are no longer relevant
This commit is contained in:
@@ -82,7 +82,7 @@ def send_sms_to_provider(self, service_id, notification_id):
|
||||
notification_id,
|
||||
SMS_TYPE,
|
||||
provider.get_name(),
|
||||
content_char_count=template.replaced_content_count
|
||||
billable_units=notification.billable_units
|
||||
)
|
||||
|
||||
notification.sent_at = datetime.utcnow()
|
||||
@@ -164,7 +164,8 @@ def send_email_to_provider(self, service_id, notification_id):
|
||||
update_provider_stats(
|
||||
notification_id,
|
||||
EMAIL_TYPE,
|
||||
provider.get_name()
|
||||
provider.get_name(),
|
||||
billable_units=1
|
||||
)
|
||||
notification.reference = reference
|
||||
notification.sent_at = datetime.utcnow()
|
||||
|
||||
@@ -299,30 +299,22 @@ def update_provider_stats(
|
||||
id_,
|
||||
notification_type,
|
||||
provider_name,
|
||||
content_char_count=None):
|
||||
billable_units=1):
|
||||
notification = Notification.query.filter(Notification.id == id_).one()
|
||||
provider = ProviderDetails.query.filter_by(identifier=provider_name).one()
|
||||
|
||||
def unit_count():
|
||||
if notification_type == EMAIL_TYPE:
|
||||
return 1
|
||||
else:
|
||||
if (content_char_count):
|
||||
return get_sms_fragment_count(content_char_count)
|
||||
return get_sms_fragment_count(notification.content_char_count)
|
||||
|
||||
update_count = db.session.query(ProviderStatistics).filter_by(
|
||||
day=date.today(),
|
||||
service_id=notification.service_id,
|
||||
provider_id=provider.id
|
||||
).update({'unit_count': ProviderStatistics.unit_count + unit_count()})
|
||||
).update({'unit_count': ProviderStatistics.unit_count + billable_units})
|
||||
|
||||
if update_count == 0:
|
||||
provider_stats = ProviderStatistics(
|
||||
day=notification.created_at.date(),
|
||||
service_id=notification.service_id,
|
||||
provider_id=provider.id,
|
||||
unit_count=unit_count()
|
||||
unit_count=billable_units
|
||||
)
|
||||
|
||||
db.session.add(provider_stats)
|
||||
|
||||
Reference in New Issue
Block a user