From 51af6b27a01125be1e5f32f59b05aa9bc7789c63 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Wed, 25 Apr 2018 17:00:19 +0100 Subject: [PATCH] Update name of method to clarify the meaning. Update group by to use label. Update test. --- app/dao/fact_billing_dao.py | 4 ++-- tests/app/dao/test_ft_billing_dao.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/dao/fact_billing_dao.py b/app/dao/fact_billing_dao.py index 58c62d2a6..bc6f7d357 100644 --- a/app/dao/fact_billing_dao.py +++ b/app/dao/fact_billing_dao.py @@ -20,7 +20,7 @@ from app.models import ( from app.utils import convert_utc_to_bst, convert_bst_to_utc -def fetch_annual_billing_for_year(service_id, year): +def fetch_montly_billing_for_year(service_id, year): year_start_date, year_end_date = get_financial_year(year) utcnow = datetime.utcnow() today = convert_utc_to_bst(utcnow).date() @@ -45,7 +45,7 @@ def fetch_annual_billing_for_year(service_id, year): FactBilling.bst_date >= year_start_date, FactBilling.bst_date <= year_end_date ).group_by( - extract('month', FactBilling.bst_date), + 'Month', FactBilling.service_id, FactBilling.rate, FactBilling.rate_multiplier, diff --git a/tests/app/dao/test_ft_billing_dao.py b/tests/app/dao/test_ft_billing_dao.py index e0a69715a..4ed43ffc5 100644 --- a/tests/app/dao/test_ft_billing_dao.py +++ b/tests/app/dao/test_ft_billing_dao.py @@ -5,7 +5,7 @@ from freezegun import freeze_time from app import db from app.dao.fact_billing_dao import ( - fetch_annual_billing_for_year, fetch_billing_data_for_day, get_rates_for_billing, + fetch_montly_billing_for_year, fetch_billing_data_for_day, get_rates_for_billing, get_rate ) from app.models import FactBilling @@ -23,11 +23,15 @@ from tests.app.db import ( def test_fetch_billing_data_for_today_includes_data_with_the_right_status(notify_db_session): service = create_service() template = create_template(service=service, template_type="email") - for status in ['delivered', 'sending', 'temporary-failure', 'created', 'technical-failure']: + for status in ['created', 'technical-failure']: create_notification(template=template, status=status) today = convert_utc_to_bst(datetime.utcnow()) results = fetch_billing_data_for_day(today) + assert results == [] + for status in ['delivered', 'sending', 'temporary-failure']: + create_notification(template=template, status=status) + results = fetch_billing_data_for_day(today) assert len(results) == 1 assert results[0].notifications_sent == 3 @@ -193,8 +197,7 @@ def test_fetch_annual_billing_for_year(notify_db_session): notification_type='sms', rate=0.158) - results = fetch_annual_billing_for_year(service_id=service.id, - year=2018) + results = fetch_montly_billing_for_year(service_id=service.id, year=2018) assert len(results) == 2 assert results[0][0] == 6.0 @@ -227,7 +230,7 @@ def test_fetch_annual_billing_for_year_adds_data_for_today(notify_db_session): create_notification(template=template, status='delivered') assert db.session.query(FactBilling.bst_date).count() == 31 - results = fetch_annual_billing_for_year(service_id=service.id, + results = fetch_montly_billing_for_year(service_id=service.id, year=2018) assert db.session.query(FactBilling.bst_date).count() == 32 assert len(results) == 2