def test_closure_info_visibility(api_client, closure_info_section,
                                 get_sections_url):
    hearing = closure_info_section.hearing

    # hearing closed, closure info section should be in results
    hearing.close_at = now() - datetime.timedelta(days=1)
    hearing.save()

    # check sections field in the hearing
    response = api_client.get(get_hearing_detail_url(hearing.id))
    data = get_data_from_response(response)
    assert_id_in_results(closure_info_section.id, data['sections'])

    # check nested and root level sections endpoint
    response = api_client.get(get_sections_url(hearing))
    data = get_results_from_response(response)
    assert_id_in_results(closure_info_section.id, data)

    # hearing open, closure info section should not be in results
    hearing.close_at = now() + datetime.timedelta(days=1)
    hearing.save()

    # check sections field in the hearing
    response = api_client.get(get_hearing_detail_url(hearing.id))
    data = get_data_from_response(response)
    assert_id_in_results(closure_info_section.id, data['sections'], False)

    # check nested and root level sections endpoint
    response = api_client.get(get_sections_url(hearing))
    data = get_results_from_response(response)
    assert_id_in_results(closure_info_section.id, data, False)
def test_closure_info_visibility(api_client, closure_info_section, get_sections_url):
    hearing = closure_info_section.hearing

    # hearing closed, closure info section should be in results
    hearing.close_at = now() - datetime.timedelta(days=1)
    hearing.save()

    # check sections field in the hearing
    response = api_client.get(get_hearing_detail_url(hearing.id))
    data = get_data_from_response(response)
    assert_id_in_results(closure_info_section.id, data['sections'])

    # check nested and root level sections endpoint
    response = api_client.get(get_sections_url(hearing))
    data = get_results_from_response(response)
    assert_id_in_results(closure_info_section.id, data)

    # hearing open, closure info section should not be in results
    hearing.close_at = now() + datetime.timedelta(days=1)
    hearing.save()

    # check sections field in the hearing
    response = api_client.get(get_hearing_detail_url(hearing.id))
    data = get_data_from_response(response)
    assert_id_in_results(closure_info_section.id, data['sections'], False)

    # check nested and root level sections endpoint
    response = api_client.get(get_sections_url(hearing))
    data = get_results_from_response(response)
    assert_id_in_results(closure_info_section.id, data, False)