Exemplo n.º 1
0
def test_dao_fetch_live_services_data(sample_user):
    org = create_organisation(organisation_type='other')
    service = create_service(go_live_user=sample_user,
                             go_live_at='2014-04-20T10:00:00')
    template = create_template(service=service)
    service_2 = create_service(service_name='second',
                               go_live_at='2017-04-20T10:00:00',
                               go_live_user=sample_user)
    service_3 = create_service(service_name='third',
                               go_live_at='2016-04-20T10:00:00')
    # below services should be filtered out:
    create_service(service_name='restricted', restricted=True)
    create_service(service_name='not_active', active=False)
    create_service(service_name='not_live', count_as_live=False)
    template2 = create_template(service=service, template_type='email')
    template_letter_1 = create_template(service=service,
                                        template_type='letter')
    template_letter_2 = create_template(service=service_2,
                                        template_type='letter')
    dao_add_service_to_organisation(service=service, organisation_id=org.id)
    # two sms billing records for 1st service within current financial year:
    create_ft_billing(utc_date='2019-04-20',
                      notification_type='sms',
                      template=template,
                      service=service)
    create_ft_billing(utc_date='2019-04-21',
                      notification_type='sms',
                      template=template,
                      service=service)
    # one sms billing record for 1st service from previous financial year, should not appear in the result:
    create_ft_billing(utc_date='2018-04-20',
                      notification_type='sms',
                      template=template,
                      service=service)
    # one email billing record for 1st service within current financial year:
    create_ft_billing(utc_date='2019-04-20',
                      notification_type='email',
                      template=template2,
                      service=service)
    # one letter billing record for 1st service within current financial year:
    create_ft_billing(utc_date='2019-04-15',
                      notification_type='letter',
                      template=template_letter_1,
                      service=service)
    # one letter billing record for 2nd service within current financial year:
    create_ft_billing(utc_date='2019-04-16',
                      notification_type='letter',
                      template=template_letter_2,
                      service=service_2)

    # 1st service: billing from 2018 and 2019
    create_annual_billing(service.id, 500, 2018)
    create_annual_billing(service.id, 100, 2019)
    # 2nd service: billing from 2018
    create_annual_billing(service_2.id, 300, 2018)
    # 3rd service: billing from 2019
    create_annual_billing(service_3.id, 200, 2019)

    results = dao_fetch_live_services_data()
    assert len(results) == 3
Exemplo n.º 2
0
def test_dao_fetch_live_services_data(sample_user):
    org = create_organisation(organisation_type='nhs_central')
    service = create_service(go_live_user=sample_user, go_live_at='2014-04-20T10:00:00')
    sms_template = create_template(service=service)
    service_2 = create_service(service_name='second', go_live_at='2017-04-20T10:00:00', go_live_user=sample_user)
    service_3 = create_service(service_name='third', go_live_at='2016-04-20T10:00:00')
    # below services should be filtered out:
    create_service(service_name='restricted', restricted=True)
    create_service(service_name='not_active', active=False)
    create_service(service_name='not_live', count_as_live=False)
    email_template = create_template(service=service, template_type='email')
    template_letter_1 = create_template(service=service, template_type='letter')
    template_letter_2 = create_template(service=service_2, template_type='letter')
    dao_add_service_to_organisation(service=service, organisation_id=org.id)
    # two sms billing records for 1st service within current financial year:
    create_ft_billing(bst_date='2019-04-20', template=sms_template)
    create_ft_billing(bst_date='2019-04-21', template=sms_template)
    # one sms billing record for 1st service from previous financial year, should not appear in the result:
    create_ft_billing(bst_date='2018-04-20', template=sms_template)
    # one email billing record for 1st service within current financial year:
    create_ft_billing(bst_date='2019-04-20', template=email_template)
    # one letter billing record for 1st service within current financial year:
    create_ft_billing(bst_date='2019-04-15', template=template_letter_1)
    # one letter billing record for 2nd service within current financial year:
    create_ft_billing(bst_date='2019-04-16', template=template_letter_2)

    # 1st service: billing from 2018 and 2019
    create_annual_billing(service.id, 500, 2018)
    create_annual_billing(service.id, 100, 2019)
    # 2nd service: billing from 2018
    create_annual_billing(service_2.id, 300, 2018)
    # 3rd service: billing from 2019
    create_annual_billing(service_3.id, 200, 2019)

    results = dao_fetch_live_services_data()
    assert len(results) == 3
    # checks the results and that they are ordered by date:
    assert results == [
        {'service_id': mock.ANY, 'service_name': 'Sample service', 'organisation_name': 'test_org_1',
            'organisation_type': 'nhs_central', 'consent_to_research': None, 'contact_name': 'Test User',
            'contact_email': '*****@*****.**', 'contact_mobile': '+447700900986',
            'live_date': datetime(2014, 4, 20, 10, 0), 'sms_volume_intent': None, 'email_volume_intent': None,
            'letter_volume_intent': None, 'sms_totals': 2, 'email_totals': 1, 'letter_totals': 1,
            'free_sms_fragment_limit': 100},
        {'service_id': mock.ANY, 'service_name': 'third', 'organisation_name': None, 'consent_to_research': None,
            'organisation_type': None, 'contact_name': None, 'contact_email': None,
            'contact_mobile': None, 'live_date': datetime(2016, 4, 20, 10, 0), 'sms_volume_intent': None,
            'email_volume_intent': None, 'letter_volume_intent': None,
            'sms_totals': 0, 'email_totals': 0, 'letter_totals': 0,
            'free_sms_fragment_limit': 200},
        {'service_id': mock.ANY, 'service_name': 'second', 'organisation_name': None, 'consent_to_research': None,
            'contact_name': 'Test User', 'contact_email': '*****@*****.**',
            'contact_mobile': '+447700900986', 'live_date': datetime(2017, 4, 20, 10, 0), 'sms_volume_intent': None,
            'organisation_type': None, 'email_volume_intent': None, 'letter_volume_intent': None,
            'sms_totals': 0, 'email_totals': 0, 'letter_totals': 1,
            'free_sms_fragment_limit': 300}
    ]
Exemplo n.º 3
0
def get_live_services_data():
    data = dao_fetch_live_services_data()
    return jsonify(data=data)
Exemplo n.º 4
0
def get_live_services_data():
    data = dao_fetch_live_services_data()
    for i, row in enumerate(data):
        data[i]["domains"] = get_service_domains(row["service_id"])
    return jsonify(data=data)
Exemplo n.º 5
0
def test_dao_fetch_live_services_data(sample_user):
    org = create_organisation(organisation_type="nhs_central")
    service = create_service(go_live_user=sample_user,
                             go_live_at="2014-04-20T10:00:00")
    template = create_template(service=service)
    service_2 = create_service(
        service_name="second",
        go_live_at="2017-04-20T10:00:00",
        go_live_user=sample_user,
    )
    service_3 = create_service(service_name="third",
                               go_live_at="2016-04-20T10:00:00")
    # below services should be filtered out:
    create_service(service_name="restricted", restricted=True)
    create_service(service_name="not_active", active=False)
    create_service(service_name="not_live", count_as_live=False)
    template2 = create_template(service=service, template_type="email")
    template_letter_1 = create_template(service=service,
                                        template_type="letter")
    template_letter_2 = create_template(service=service_2,
                                        template_type="letter")
    dao_add_service_to_organisation(service=service, organisation_id=org.id)
    # two sms billing records for 1st service within current financial year:
    create_ft_billing(
        utc_date="2019-04-20",
        notification_type="sms",
        template=template,
        service=service,
    )
    create_ft_billing(
        utc_date="2019-04-21",
        notification_type="sms",
        template=template,
        service=service,
    )
    # one sms billing record for 1st service from previous financial year, should not appear in the result:
    create_ft_billing(
        utc_date="2018-04-20",
        notification_type="sms",
        template=template,
        service=service,
    )
    # one email billing record for 1st service within current financial year:
    create_ft_billing(
        utc_date="2019-04-20",
        notification_type="email",
        template=template2,
        service=service,
    )
    # one letter billing record for 1st service within current financial year:
    create_ft_billing(
        utc_date="2019-04-15",
        notification_type="letter",
        template=template_letter_1,
        service=service,
    )
    # one letter billing record for 2nd service within current financial year:
    create_ft_billing(
        utc_date="2019-04-16",
        notification_type="letter",
        template=template_letter_2,
        service=service_2,
    )

    # 1st service: billing from 2018 and 2019
    create_annual_billing(service.id, 500, 2018)
    create_annual_billing(service.id, 100, 2019)
    # 2nd service: billing from 2018
    create_annual_billing(service_2.id, 300, 2018)
    # 3rd service: billing from 2019
    create_annual_billing(service_3.id, 200, 2019)

    results = dao_fetch_live_services_data()
    assert len(results) == 3