Exemplo n.º 1
0
def get_detailed_services(start_date,
                          end_date,
                          only_active=False,
                          include_from_test_key=True):
    if start_date == datetime.utcnow().date():
        stats = dao_fetch_todays_stats_for_all_services(
            include_from_test_key=include_from_test_key,
            only_active=only_active)
    else:

        stats = fetch_stats_for_all_services_by_date_range(
            start_date=start_date,
            end_date=end_date,
            include_from_test_key=include_from_test_key,
        )
    results = []
    for service_id, rows in itertools.groupby(stats, lambda x: x.service_id):
        rows = list(rows)
        s = statistics.format_statistics(rows)
        results.append({
            'id': str(rows[0].service_id),
            'name': rows[0].name,
            'notification_type': rows[0].notification_type,
            'research_mode': rows[0].research_mode,
            'restricted': rows[0].restricted,
            'active': rows[0].active,
            'created_at': rows[0].created_at,
            'statistics': s
        })
    return results
Exemplo n.º 2
0
def test_fetch_stats_for_all_services_by_date_range(notify_db_session):
    service_1, service_2 = set_up_data()
    results = fetch_stats_for_all_services_by_date_range(
        start_date=date(2018, 10, 29), end_date=date(2018, 10, 31))
    assert len(results) == 5

    assert results[0].service_id == service_1.id
    assert results[0].notification_type == 'email'
    assert results[0].status == 'delivered'
    assert results[0].count == 4

    assert results[1].service_id == service_1.id
    assert results[1].notification_type == 'sms'
    assert results[1].status == 'created'
    assert results[1].count == 2

    assert results[2].service_id == service_1.id
    assert results[2].notification_type == 'sms'
    assert results[2].status == 'delivered'
    assert results[2].count == 11

    assert results[3].service_id == service_2.id
    assert results[3].notification_type == 'letter'
    assert results[3].status == 'delivered'
    assert results[3].count == 10

    assert results[4].service_id == service_2.id
    assert not results[4].notification_type
    assert not results[4].status
    assert not results[4].count