def get_yearly_billing_usage_summary_from_ft_billing(service_id): try: year = int(request.args.get('year')) except TypeError: return jsonify(result='error', message='No valid year provided'), 400 billing_data = fetch_billing_totals_for_year(service_id, year) data = serialize_ft_billing_yearly_totals(billing_data) return jsonify(data)
def test_fetch_billing_totals_for_year(notify_db_session): service = set_up_yearly_data() results = fetch_billing_totals_for_year(service_id=service.id, year=2016) assert len(results) == 4 assert results[0].notification_type == 'email' assert results[0].notifications_sent == 365 assert results[0].billable_units == 365 assert results[0].rate == Decimal('0') assert results[1].notification_type == 'letter' assert results[1].notifications_sent == 365 assert results[1].billable_units == 365 assert results[1].rate == Decimal('0.3') assert results[2].notification_type == 'letter' assert results[2].notifications_sent == 365 assert results[2].billable_units == 365 assert results[2].rate == Decimal('0.33') assert results[3].notification_type == 'sms' assert results[3].notifications_sent == 365 assert results[3].billable_units == 365 assert results[3].rate == Decimal('0.162')