Example #1
0
def test_count_unanswered_questions():
    mock_content_manifest = mock.create_autospec(ContentManifest,
                                                 instance=True)
    mock_content_manifest.__iter__.side_effect = lambda: (mock.create_autospec(
        ContentSection,
        instance=True,
        questions=[
            mock.create_autospec(QuestionSummary,
                                 instance=True,
                                 answer_required=answer_required,
                                 value=value)
            for answer_required, value in questions
        ]) for questions in (
            (
                (True, ""),
                (False, "123"),
                (True, ["321"]),
            ),
            (
                (False, None),
                (False, []),
                (True, "abc"),
                (True, "yes"),
                (True, "no"),
                (True, None),
                (False, "2020-01-01T01:01:01Z"),
            ),
            ((False, []), ),
        ))

    assert count_unanswered_questions(mock_content_manifest) == (6, 3)
Example #2
0
def view_service_submission(framework_slug, lot_slug, service_id):
    framework, lot = get_framework_and_lot_or_404(data_api_client,
                                                  framework_slug, lot_slug)
    update_framework_with_formatted_dates(framework)

    # check if g12 recovery supplier
    g12_recovery = None
    if (framework_slug == "g-cloud-12" and framework["status"] == "live"
            and is_g12_recovery_supplier(current_user.supplier_id)):
        # we want this page to appear as it would if g12 were open
        framework["status"] = "open"
        framework["applicationsCloseAt"] = utctoshorttimelongdateformat(
            G12_RECOVERY_DEADLINE)
        not_submitted_count, submitted_count = count_g12_recovery_drafts_by_status(
            data_api_client, current_user.supplier_id)
        g12_recovery = {
            'time_remaining': g12_recovery_time_remaining(),
            'not_submitted_drafts': not_submitted_count,
            'submitted_drafts': submitted_count
        }

    try:
        data = data_api_client.get_draft_service(service_id)
        draft, last_edit, validation_errors = data['services'], data[
            'auditEvents'], data['validationErrors']
    except HTTPError as e:
        abort(e.status_code)

    if draft['lotSlug'] != lot_slug or draft['frameworkSlug'] != framework_slug:
        abort(404)

    if not is_service_associated_with_supplier(draft):
        abort(404)

    sections = content_loader.get_manifest(
        framework['slug'],
        'edit_submission',
    ).filter(draft, inplace_allowed=True).summary(draft, inplace_allowed=True)

    unanswered_required, unanswered_optional = count_unanswered_questions(
        sections)
    delete_requested = True if request.args.get('delete_requested') else False

    return render_template(
        "services/service_submission.html",
        framework=framework,
        lot=lot,
        confirm_remove=request.args.get("confirm_remove", None),
        service_id=service_id,
        service_data=draft,
        last_edit=last_edit,
        sections=sections,
        unanswered_required=unanswered_required,
        unanswered_optional=unanswered_optional,
        can_mark_complete=not validation_errors,
        delete_requested=delete_requested,
        declaration_status=get_declaration_status(data_api_client,
                                                  framework['slug']),
        g12_recovery=g12_recovery,
    ), 200
def _draft_services_annotated_unanswered_counts(framework_slug, draft_services):
    try:
        manifest = content_loader.get_manifest(framework_slug, "edit_service_as_admin")
    except ContentNotFoundError:
        return None

    return tuple(
        {
            **draft_service,
            "unansweredRequiredCount": count_unanswered_questions(
                manifest.filter(draft_service).summary(draft_service)
            )[0],
        } for draft_service in draft_services
    )
def list_all_services(framework_slug):
    if not (is_g12_recovery_supplier(current_user.supplier_id)
            and framework_slug == "g-cloud-12"):
        abort(404)

    framework = get_framework_or_404(data_api_client,
                                     framework_slug,
                                     allowed_statuses=['live'])

    suppliers_services = data_api_client.find_services(
        supplier_id=current_user.supplier_id,
        framework=framework_slug,
    )["services"]

    drafts, complete_drafts = get_drafts(data_api_client, framework_slug)

    service_sections = content_loader.get_manifest(
        framework_slug,
        'edit_submission',
    )

    for draft in drafts:
        sections = service_sections.filter(context={
            'lot': draft["lotSlug"]
        }).summary(draft, inplace_allowed=True)

        unanswered_required, unanswered_optional = count_unanswered_questions(
            sections)
        draft.update({
            'unanswered_required': unanswered_required,
            'unanswered_optional': unanswered_optional,
        })

    # Only G12 recovery suppliers can access this route, so always show the banner
    g12_recovery = {'time_remaining': g12_recovery_time_remaining()}

    return render_template("services/list_all_services.html",
                           framework=framework,
                           drafts=drafts,
                           complete_drafts=complete_drafts,
                           services=suppliers_services,
                           g12_recovery=g12_recovery), 200
def view_service_submission(framework_slug, lot_slug, service_id):
    framework, lot = get_framework_and_lot_or_404(data_api_client, framework_slug, lot_slug)
    update_framework_with_formatted_dates(framework)

    try:
        data = data_api_client.get_draft_service(service_id)
        draft, last_edit, validation_errors = data['services'], data['auditEvents'], data['validationErrors']
    except HTTPError as e:
        abort(e.status_code)

    if draft['lotSlug'] != lot_slug or draft['frameworkSlug'] != framework_slug:
        abort(404)

    if not is_service_associated_with_supplier(draft):
        abort(404)

    sections = content_loader.get_manifest(
        framework['slug'],
        'edit_submission',
    ).filter(draft, inplace_allowed=True).summary(draft, inplace_allowed=True)

    unanswered_required, unanswered_optional = count_unanswered_questions(sections)
    delete_requested = True if request.args.get('delete_requested') else False

    return render_template(
        "services/service_submission.html",
        framework=framework,
        lot=lot,
        confirm_remove=request.args.get("confirm_remove", None),
        service_id=service_id,
        service_data=draft,
        last_edit=last_edit,
        sections=sections,
        unanswered_required=unanswered_required,
        unanswered_optional=unanswered_optional,
        can_mark_complete=not validation_errors,
        delete_requested=delete_requested,
        declaration_status=get_declaration_status(data_api_client, framework['slug'])
    ), 200
Example #6
0
def list_all_services(framework_slug):
    if not (is_g12_recovery_supplier(current_user.supplier_id)
            and framework_slug == "g-cloud-12"):
        abort(404)

    framework = get_framework_or_404(data_api_client,
                                     framework_slug,
                                     allowed_statuses=['live'])

    suppliers_services = data_api_client.find_services(
        supplier_id=current_user.supplier_id,
        framework=framework_slug,
    )["services"]

    drafts, complete_drafts = get_drafts(data_api_client, framework_slug)

    g12_draft_allow_list = get_g12_recovery_draft_ids()
    drafts = [draft for draft in drafts if draft["id"] in g12_draft_allow_list]
    complete_drafts = [
        draft for draft in complete_drafts
        if draft["id"] in g12_draft_allow_list
    ]

    service_sections = content_loader.get_manifest(
        framework_slug,
        'edit_submission',
    )

    for draft in drafts:
        sections = service_sections.filter(context={
            'lot': draft["lotSlug"]
        }).summary(draft, inplace_allowed=True)

        unanswered_required, unanswered_optional = count_unanswered_questions(
            sections)
        draft.update({
            'unanswered_required': unanswered_required,
            'unanswered_optional': unanswered_optional,
        })

    # We only want drafts that they have completed as part of G12 recovery to
    # show up in "Complete services" table (live services go in a separate table)
    complete_drafts = [
        draft for draft in complete_drafts if "serviceId" not in draft
    ]

    # Only G12 recovery suppliers can access this route, so always show the banner
    not_submitted_count, submitted_count = count_g12_recovery_drafts_by_status(
        data_api_client, current_user.supplier_id)
    g12_recovery = {
        'time_remaining': g12_recovery_time_remaining(),
        'not_submitted_drafts': not_submitted_count,
        'submitted_drafts': submitted_count
    }

    return render_template("services/list_all_services.html",
                           framework=framework,
                           drafts=drafts,
                           complete_drafts=complete_drafts,
                           services=suppliers_services,
                           g12_recovery=g12_recovery), 200