예제 #1
0
def construct_assistance_response(requested_award_dict: dict) -> OrderedDict:
    """Build an Assistance Award summary object to send as an API response"""

    response = OrderedDict()
    award = fetch_award_details(requested_award_dict, FABS_AWARD_FIELDS)
    if not award:
        return None

    response.update(award)

    transaction = fetch_fabs_details_by_pk(award["_trx"], FABS_ASSISTANCE_FIELDS)

    response["record_type"] = transaction["record_type"]
    response["cfda_info"] = fetch_all_cfda_details(award)
    response["transaction_obligated_amount"] = fetch_transaction_obligated_amount_by_internal_award_id(award["id"])
    response["funding_agency"] = fetch_agency_details(response["_funding_agency"])
    if response["funding_agency"]:
        response["funding_agency"]["office_agency_name"] = transaction["_funding_office_name"]
    response["awarding_agency"] = fetch_agency_details(response["_awarding_agency"])
    if response["awarding_agency"]:
        response["awarding_agency"]["office_agency_name"] = transaction["_awarding_office_name"]
    response["period_of_performance"] = OrderedDict(
        [
            ("start_date", award["_start_date"]),
            ("end_date", award["_end_date"]),
            ("last_modified_date", get_date_from_datetime(transaction["_modified_at"])),
        ]
    )
    response["recipient"] = create_recipient_object(transaction)
    response["executive_details"] = create_officers_object(award)
    response["place_of_performance"] = create_place_of_performance_object(transaction)

    return delete_keys_from_dict(response)
def test_get_date_from_datetime():
    from datetime import date, datetime

    assert get_date_from_datetime(1) == 1
    assert get_date_from_datetime(1, default=2) == 2
    assert get_date_from_datetime(1, default=None) is None

    assert get_date_from_datetime('a') == 'a'
    assert get_date_from_datetime('a', default='b') == 'b'

    assert get_date_from_datetime(datetime(2000, 1, 2)) == date(2000, 1, 2)
    assert get_date_from_datetime(datetime(2000, 1, 2), default='no') == date(2000, 1, 2)

    assert get_date_from_datetime(datetime(2000, 1, 2, 3, 4, 5)) == date(2000, 1, 2)
    assert get_date_from_datetime(datetime(2000, 1, 2, 3, 4, 5), default='maybe') == date(2000, 1, 2)
예제 #3
0
def test_get_date_from_datetime():
    from datetime import date, datetime

    assert get_date_from_datetime(1) == 1
    assert get_date_from_datetime(1, default=2) == 2
    assert get_date_from_datetime(1, default=None) is None

    assert get_date_from_datetime("a") == "a"
    assert get_date_from_datetime("a", default="b") == "b"

    assert get_date_from_datetime(datetime(2000, 1, 2)) == date(2000, 1, 2)
    assert get_date_from_datetime(datetime(2000, 1, 2),
                                  default="no") == date(2000, 1, 2)

    assert get_date_from_datetime(datetime(2000, 1, 2, 3, 4,
                                           5)) == date(2000, 1, 2)
    assert get_date_from_datetime(datetime(2000, 1, 2, 3, 4, 5),
                                  default="maybe") == date(2000, 1, 2)
예제 #4
0
def test_get_date_from_datetime():
    from datetime import date, datetime

    assert get_date_from_datetime(1) == 1
    assert get_date_from_datetime(1, default=2) == 2
    assert get_date_from_datetime(1, default=None) is None

    assert get_date_from_datetime('a') == 'a'
    assert get_date_from_datetime('a', default='b') == 'b'

    assert get_date_from_datetime(datetime(2000, 1, 2)) == date(2000, 1, 2)
    assert get_date_from_datetime(datetime(2000, 1, 2),
                                  default='no') == date(2000, 1, 2)

    assert get_date_from_datetime(datetime(2000, 1, 2, 3, 4,
                                           5)) == date(2000, 1, 2)
    assert get_date_from_datetime(datetime(2000, 1, 2, 3, 4, 5),
                                  default='maybe') == date(2000, 1, 2)
예제 #5
0
def construct_assistance_response(requested_award_dict):
    """
        Build the Python object to return FABS Award summary or meta-data via the API

        parameter(s): `requested_award` either award.id (int) or generated_unique_award_id (str)
        returns: an OrderedDict
    """

    response = OrderedDict()
    award = fetch_award_details(requested_award_dict, FABS_AWARD_FIELDS)
    if not award:
        return None
    response.update(award)

    transaction = fetch_fabs_details_by_pk(award["_trx"],
                                           FABS_ASSISTANCE_FIELDS)

    cfda_info = fetch_cfda_details_using_cfda_number(
        transaction["cfda_number"])
    response["cfda_number"] = transaction["cfda_number"]
    response["cfda_title"] = transaction["cfda_title"]
    response["cfda_objectives"] = cfda_info.get("objectives")
    response[
        "transaction_obligated_amount"] = fetch_transaction_obligated_amount_by_internal_award_id(
            award["id"])

    response["funding_agency"] = fetch_agency_details(
        response["_funding_agency"])
    if response["funding_agency"]:
        response["funding_agency"]["office_agency_name"] = transaction[
            "_funding_office_name"]
    response["awarding_agency"] = fetch_agency_details(
        response["_awarding_agency"])
    if response["awarding_agency"]:
        response["awarding_agency"]["office_agency_name"] = transaction[
            "_awarding_office_name"]
    response["period_of_performance"] = OrderedDict([
        ("start_date", award["_start_date"]),
        ("end_date", award["_end_date"]),
        ("last_modified_date",
         get_date_from_datetime(transaction["_modified_at"])),
    ])
    transaction["_lei"] = award["_lei"]
    response["recipient"] = create_recipient_object(transaction)
    response["place_of_performance"] = create_place_of_performance_object(
        transaction)

    return delete_keys_from_dict(response)