def test_tas_filter_not_object_or_list(client, monkeypatch,
                                       elasticsearch_award_index,
                                       award_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas(client, "This shouldn't be a string")

    assert resp.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY, "Failed to return 422 Response"
def test_tas_unparsable_too_long(client, monkeypatch,
                                 elasticsearch_award_index, subaward_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas_subaward(
        client, {"require": [["011", "011-0990", "3-4-2-5-3/5-6-3-4"]]})

    assert resp.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY, "Failed to return 422 Response"
Beispiel #3
0
def test_match_from_agency(client, monkeypatch, elasticsearch_award_index,
                           subaward_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas_subaward(client,
                                 {"require": [_agency_path(BASIC_TAS)]})

    assert resp.json()["results"] == [_subaward1()]
Beispiel #4
0
def test_match_on_multiple_awards(client, monkeypatch,
                                  elasticsearch_award_index,
                                  subaward_with_no_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas_subaward(client, {"require": [_tas_path(BASIC_TAS)]})

    assert resp.json()["results"] == []
Beispiel #5
0
def test_tas_level_require_non_match(client, monkeypatch,
                                     elasticsearch_award_index,
                                     subaward_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas_subaward(client, {"require": [_tas_path(ATA_TAS)]})

    assert resp.json()["results"] == []
def test_tas_unparsable_no_main(client, monkeypatch, elasticsearch_award_index,
                                award_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas(
        client, {"require": [["011", "011-0990", "011-2000/2000-000"]]})

    assert resp.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY, "Failed to return 422 Response"
def test_tas_filter_inappropriate_characters(client, monkeypatch,
                                             elasticsearch_award_index,
                                             award_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas(client, {"require": [["011", "[abc]"]]})

    assert resp.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY, "Failed to return 422 Response"
Beispiel #8
0
def test_agency_level_exclude_match(client, monkeypatch,
                                    elasticsearch_award_index,
                                    subaward_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas_subaward(client, {"exclude": [_agency_path(ATA_TAS)]})

    assert resp.json()["results"] == [_subaward1()]
def test_treasury_account_component_filter_appropriate_characters(
        client, monkeypatch, elasticsearch_award_index, award_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    # "R" doesn't represent anything special here, it just makes sure the code is ok with any capital letter
    resp = query_by_treasury_account_components(client, [{"a": "R"}], None)

    assert resp.status_code == status.HTTP_200_OK, "Failed to return 422 Response"
Beispiel #10
0
def test_fa_level_exclude_non_match(client, monkeypatch,
                                    elasticsearch_award_index,
                                    subaward_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas_subaward(client, {"exclude": [_fa_path(BASIC_TAS)]})

    assert resp.json()["results"] == []
Beispiel #11
0
def test_double_eclipsing_filters2(client, monkeypatch, elasticsearch_award_index, award_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas(
        client, {"require": [_fa_path(BASIC_TAS)], "exclude": [_agency_path(BASIC_TAS), _tas_path(BASIC_TAS)]}
    )

    assert resp.json()["results"] == []
Beispiel #12
0
def test_sibling_filters_on_one_sibling(
    client, monkeypatch, elasticsearch_award_index, multiple_awards_with_sibling_tas
):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas(client, {"require": [_tas_path(SISTER_TAS[1])]})

    assert resp.json()["results"] == [_award2()]
def test_match_on_multiple_awards(client, monkeypatch, elasticsearch_award_index, multiple_awards_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas(client, {"require": [_tas_path(BASIC_TAS), _tas_path(1)]})

    assert resp.json()["results"].sort(key=lambda elem: elem["internal_id"]) == [_award1(), _award2()].sort(
        key=lambda elem: elem["internal_id"]
    )
def test_non_match_from_component_both_filters(client, monkeypatch, elasticsearch_award_index, subaward_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_treasury_account_components_subaward(
        client, {"require": [_agency_path(ATA_TAS)]}, [component_dictionary(ATA_TAS)]
    )

    assert resp.json()["results"] == []
Beispiel #15
0
def test_match_from_component_filter_only(client, monkeypatch,
                                          elasticsearch_award_index,
                                          award_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_treasury_account_components(
        client, None, [component_dictionary(BASIC_TAS)])

    assert resp.json()["results"] == [_award1()]
Beispiel #16
0
def test_match_from_code_filter_only(client, monkeypatch,
                                     elasticsearch_award_index,
                                     award_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_treasury_account_components(
        client, {"require": [_agency_path(BASIC_TAS)]}, None)

    assert resp.json()["results"] == [_award1()]
Beispiel #17
0
def test_sibling_filters_on_both_siblings(
    client, monkeypatch, elasticsearch_award_index, multiple_awards_with_sibling_tas
):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas(client, {"require": [_tas_path(SISTER_TAS[0]), _tas_path(SISTER_TAS[1])]})

    assert resp.json()["results"].sort(key=lambda elem: elem["internal_id"]) == [_award1(), _award2()].sort(
        key=lambda elem: elem["internal_id"]
    )
def test_tas_filter_is_legacy(client, monkeypatch, elasticsearch_award_index,
                              award_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas(client, [{
        "main": TAS_DICTIONARIES[0]["main"],
        "aid": TAS_DICTIONARIES[0]["aid"]
    }])

    assert len(resp.json()["results"]) == 1
Beispiel #19
0
def test_non_match_from_unintuitive_tas_from_tas(
        client, monkeypatch, elasticsearch_award_index,
        subaward_with_unintuitive_agency):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    # ensure that api CANNOT find a TAS from the agency in the TAS code's aid, because it's actually linked under a
    # different agency
    resp = query_by_tas_subaward(client, {"require": [_tas_path(ATA_TAS)]})

    assert resp.json()["results"] == []
def test_treasury_account_component_filter_inappropriate_characters(
        client, monkeypatch, elasticsearch_award_index, award_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_treasury_account_components(client, {
        "aid": "020",
        "main": "SELECT"
    }, None)

    assert resp.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY, "Failed to return 422 Response"
Beispiel #21
0
def test_exclude_overrides_require(client, monkeypatch,
                                   elasticsearch_award_index,
                                   subaward_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas_subaward(client, {
        "require": [_tas_path(BASIC_TAS)],
        "exclude": [_tas_path(BASIC_TAS)]
    })

    assert resp.json()["results"] == []
Beispiel #22
0
def test_sibling_eclipsing_filters(client, monkeypatch, elasticsearch_award_index, multiple_awards_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas(
        client,
        {
            "require": [_agency_path(BASIC_TAS), _tas_path(ATA_TAS)],
            "exclude": [_agency_path(ATA_TAS), _tas_path(BASIC_TAS)],
        },
    )

    assert resp.json()["results"] == [_award2()]
Beispiel #23
0
def test_match_from_unintuitive_tas(client, monkeypatch,
                                    elasticsearch_award_index,
                                    subaward_with_unintuitive_agency):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas_subaward(
        client,
        {"require": [[UNINTUITIVE_AGENCY,
                      _fa(BASIC_TAS),
                      _tas(BASIC_TAS)]]})

    assert resp.json()["results"] == [_subaward1()]
def test_match_from_component_filter_despite_exclusion(
    client, monkeypatch, elasticsearch_award_index, multiple_subawards_with_tas
):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_treasury_account_components_subaward(
        client,
        {"require": [_agency_path(BASIC_TAS)], "exclude": [_agency_path(BASIC_TAS)]},
        [component_dictionary(BASIC_TAS)],
    )

    assert resp.json()["results"] == [_subaward1()]
def test_different_matches_with_each_filter(
    client, monkeypatch, elasticsearch_award_index, multiple_subawards_with_tas
):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_treasury_account_components_subaward(
        client, {"require": [_agency_path(BASIC_TAS)]}, [component_dictionary(ATA_TAS)]
    )

    assert resp.json()["results"].sort(key=lambda elem: elem["internal_id"]) == [_subaward1(), _subaward2()].sort(
        key=lambda elem: elem["internal_id"]
    )
Beispiel #26
0
def test_sibling_filters_with_fa_excluding_two_siblings(
    client, monkeypatch, elasticsearch_award_index, multiple_awards_with_sibling_tas
):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas(
        client,
        {
            "require": [_fa_path(SISTER_TAS[0]), _tas_path(SISTER_TAS[0]), _tas_path(SISTER_TAS[1])],
            "exclude": [_tas_path(SISTER_TAS[0]), _tas_path(SISTER_TAS[2])],
        },
    )

    assert resp.json()["results"] == [_award2()]
Beispiel #27
0
def test_fa_level_require_match(client, monkeypatch, elasticsearch_award_index, award_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas(client, {"require": [_fa_path(BASIC_TAS)]})

    assert resp.json()["results"] == [_award1()]
def test_non_match_from_tas(client, monkeypatch, elasticsearch_award_index, award_with_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas(client, {"require": [_agency_path(BASIC_TAS) + [TAS_STRINGS[ATA_TAS]]]})

    assert resp.json()["results"] == []
def test_match_from_bpoa_tas(client, monkeypatch, elasticsearch_award_index, award_with_bpoa_tas):
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas(client, {"require": [_tas_path(BPOA_TAS)]})

    assert resp.json()["results"] == [_award1()]
def test_match_unintuitive_tas(client, monkeypatch, elasticsearch_award_index, tas_with_nonintuitive_agency):
    # ensure that api can find a TAS that is under an agency not implied by the tas code
    _setup_es(client, monkeypatch, elasticsearch_award_index)
    resp = query_by_tas(client, {"require": [[UNINTUITIVE_AGENCY, _fa(BASIC_TAS), _tas(BASIC_TAS)]]})

    assert resp.json()["results"] == [_award1()]