mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 15:15:38 -05:00
Refactor reporting task so that methods can be used for the annual usage page.
Still a work in progress, tests are coming.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from freezegun import freeze_time
|
||||
|
||||
from app.dao.date_util import get_month_start_and_end_date_in_utc
|
||||
from app.dao.fact_billing_dao import fetch_annual_billing_by_month, need_deltas
|
||||
from tests.app.db import create_ft_billing, create_service, create_template, create_notification
|
||||
from app.dao.fact_billing_dao import fetch_annual_billing_by_month, fetch_annual_billing_for_year
|
||||
from tests.app.db import (
|
||||
create_ft_billing,
|
||||
create_service,
|
||||
create_template
|
||||
)
|
||||
|
||||
|
||||
def test_fetch_annual_billing_by_month(notify_db_session):
|
||||
@@ -20,23 +21,20 @@ def test_fetch_annual_billing_by_month(notify_db_session):
|
||||
results, month = fetch_annual_billing_by_month(service_id=record.service_id,
|
||||
billing_month=datetime(2018, 1, 1),
|
||||
notification_type='email')
|
||||
|
||||
assert len(results) == 1
|
||||
assert results[0] == (31, Decimal('31'), service.id, 'email', Decimal('0'), Decimal('1'), False)
|
||||
assert month == datetime(2018, 1, 1)
|
||||
|
||||
|
||||
@freeze_time("2018-01-21 13:00:00")
|
||||
def test_need_deltas(notify_db_session):
|
||||
def test_fetch_annual_billing_for_year(notify_db_session):
|
||||
service = create_service()
|
||||
template = create_template(service=service, template_type="email")
|
||||
for i in range(1, 21):
|
||||
record = create_ft_billing(bst_date='2018-01-{}'.format(i),
|
||||
service=service,
|
||||
template=template,
|
||||
notification_type='email')
|
||||
start_date, end_date = get_month_start_and_end_date_in_utc(datetime.utcnow())
|
||||
for i in range(1, 31):
|
||||
create_ft_billing(bst_date='2018-06-{}'.format(i),
|
||||
service=service,
|
||||
template=template,
|
||||
notification_type='email')
|
||||
results = fetch_annual_billing_for_year(service_id=service.id,
|
||||
year=2018)
|
||||
|
||||
result = need_deltas(start_date=start_date, end_date=end_date,
|
||||
service_id=service.id, notification_type='email')
|
||||
assert result
|
||||
assert results
|
||||
|
||||
Reference in New Issue
Block a user