Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 34 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readme = 'README.md'
license = "CC0-1.0"
license-files = ["LICENSE"]
requires-python = '>=3.10'
classifiers=[
classifiers = [
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
Expand Down Expand Up @@ -137,14 +137,13 @@ DJANGO_SETTINGS_MODULE = "usaspending_api.settings"
addopts = "--cov=usaspending_api"
markers = [
"signal_handling: Mark all tests that import the signal library and invoke signals. This MUST be done on the main thread, and can cause errors if pytest-xdist subordinates parellel test sessions to background threads.",

# These are "auto" marked based on fixture usage. See conftest.py pytest_collection_modifyitems
"spark: Mark all tests using the spark fixture. Can be selected with -m spark or deselected with -m (not spark)",
"database: Mark all integration tests using a database. Can be selected with -m database or deselected with -m (not database)",
"elasticsearch: Mark all integration tests using Elasticsearch. Can be selected with -m database or deselected with -m (not elasticsearch)",
]
pythonpath = [
"."
"."
]

[tool.coverage.run]
Expand Down Expand Up @@ -174,25 +173,25 @@ exclude = [
]

select = [
"PLR0913", # max arguments in function
"PLR0904", # max number of public methods
"PLR0911", # max number of return statements
"PLR0916", # max number of boolean expressions
"PLR0915", # max number of lines in a function
"PLR0912", # max number of logical branches in a function
"PLR1702", # max number of nested blocks
"C901", # cognitive complexity (functions)
"I001", # unsorted imports
"B", # flake8 bugbear
"E", # pycodestyle errors
"F", # pyflakes
"W", # pycodestyle warnings
"ANN001", # missing type annotation for function argument
"ANN201", # missing return type annotation for public function or method
"ANN202", # missing return type annotation for private function or method
"PLR0913", # max arguments in function
"PLR0904", # max number of public methods
"PLR0911", # max number of return statements
"PLR0916", # max number of boolean expressions
"PLR0915", # max number of lines in a function
"PLR0912", # max number of logical branches in a function
"PLR1702", # max number of nested blocks
"C901", # cognitive complexity (functions)
"I001", # unsorted imports
"B", # flake8 bugbear
"E", # pycodestyle errors
"F", # pyflakes
"W", # pycodestyle warnings
"ANN001", # missing type annotation for function argument
"ANN201", # missing return type annotation for public function or method
"ANN202", # missing return type annotation for private function or method
]
ignore = [
"E203", # whitespace before punctuation
"E203", # whitespace before punctuation
]

pylint.max-args = 6
Expand All @@ -207,16 +206,23 @@ pycodestyle.max-line-length = 120

[tool.ruff.lint.per-file-ignores]
"**/tests/**/test*.py" = [
"ANN001", # missing-type-function-argument; avoid conflict with fixtures
"ANN201", # missing-return-type-undocumented-public-function; avoid conflict with test case return values
"ANN202", # missing-return-type-undocumented-private-function; avoid conflict with test case return values
"ANN001", # missing-type-function-argument; avoid conflict with fixtures
"ANN201", # missing-return-type-undocumented-public-function; avoid conflict with test case return values
"ANN202", # missing-return-type-undocumented-private-function; avoid conflict with test case return values
"PLR0913", # too-many-arguments; avoid conflict with too many fixtures
"PLR0915", # too-many-statements; avoid conflict with long fixtures
"PLR0915", # too-many-statements; avoid conflict with long fixtures
]
"**/conftest*.py" = [
"ANN001", # missing-type-function-argument; avoid conflict with fixtures
"ANN201", # missing-return-type-undocumented-public-function; avoid conflict with test case return values
"ANN202", # missing-return-type-undocumented-private-function; avoid conflict with test case return values
"ANN001", # missing-type-function-argument; avoid conflict with fixtures
"ANN201", # missing-return-type-undocumented-public-function; avoid conflict with test case return values
"ANN202", # missing-return-type-undocumented-private-function; avoid conflict with test case return values
"PLR0913", # too-many-arguments; avoid conflict with too many fixtures
"PLR0915", # too-many-statements; avoid conflict with long fixtures
]
"**/tests/**/data/**.py" = [
"ANN001", # missing-type-function-argument; avoid conflict with fixtures
"ANN201", # missing-return-type-undocumented-public-function; avoid conflict with test case return values
"ANN202", # missing-return-type-undocumented-private-function; avoid conflict with test case return values
"PLR0913", # too-many-arguments; avoid conflict with too many fixtures
"PLR0915", # too-many-statements; avoid conflict with long fixtures
"PLR0915", # too-many-statements; avoid conflict with long fixtures
]
72 changes: 62 additions & 10 deletions usaspending_api/awards/v2/lookups/lookups.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@
**direct_payment_award_mapping,
**other_award_mapping,
}
non_loan_assistance_award_mapping = {**grant_award_mapping, **direct_payment_award_mapping, **other_award_mapping}
non_loan_assistance_award_mapping = {
**grant_award_mapping,
**direct_payment_award_mapping,
**other_award_mapping,
}

# TODO: include IDV mappings in the award_type_mapping and update award_filter.py
award_type_mapping = {
Expand Down Expand Up @@ -105,9 +109,24 @@
# 'F': 'Cooperative Agreement',
# 'G': 'Grant for Research',
# 'S': 'Funded Space Act Agreement',
# 'T': 'Training Grant'
# 'T': 'Training Grant',
"F001": "Grant",
"F002": "Cooperative Agreement",
"F003": "Direct Loan",
"F004": "Loan Guarantee",
"F005": "Indemnity / Insurance (non-loan)",
"F006": "Direct Payment for Specified Use",
"F007": "Direct Payment with Unrestricted Use",
"F008": "Asset Forfeiture / Equitable Sharing",
"F009": "Sale, Exchange, or Donation of Property and Goods",
"F010": "Other Financial Assistance",
}
contract_type_mapping = {
"A": "BPA Call",
"B": "Purchase Order",
"C": "Delivery Order",
"D": "Definitive Contract",
}
contract_type_mapping = {"A": "BPA Call", "B": "Purchase Order", "C": "Delivery Order", "D": "Definitive Contract"}
idv_type_mapping = {
"IDV_A": "GWAC Government Wide Acquisition Contract",
"IDV_B": "IDC Multi-Agency Contract, Other Indefinite Delivery Contract",
Expand All @@ -118,18 +137,47 @@
"IDV_D": "BOA Basic Ordering Agreement",
"IDV_E": "BPA Blanket Purchase Agreement",
}
grant_type_mapping = {"02": "Block Grant", "03": "Formula Grant", "04": "Project Grant", "05": "Cooperative Agreement"}
direct_payment_type_mapping = {"06": "Direct Payment for Specified Use", "10": "Direct Payment with Unrestricted Use"}
loan_type_mapping = {"07": "Direct Loan", "08": "Guaranteed/Insured Loan"}
grant_type_mapping = {
"02": "Block Grant",
"03": "Formula Grant",
"04": "Project Grant",
"05": "Cooperative Agreement",
"F001": "Grant",
"F002": "Cooperative Agreement",
}
direct_payment_type_mapping = {
"06": "Direct Payment for Specified Use",
"10": "Direct Payment with Unrestricted Use",
"F006": "Direct Payment for Specified Use",
"F007": "Direct Payment with Unrestricted Use",
}
loan_type_mapping = {
"07": "Direct Loan",
"08": "Guaranteed/Insured Loan",
"F003": "Direct Loan",
"F004": "Loan Guarantee",
}
# -1 is a derived type that we added as a "catch-all" for any invalid `type` values
other_type_mapping = {"09": "Insurance", "11": "Other Financial Assistance", "-1": "Not Specified"}
other_type_mapping = {
"09": "Insurance",
"11": "Other Financial Assistance",
"-1": "Not Specified",
"F005": "Indemnity / Insurance (non-loan)",
"F008": "Asset Forfeiture / Equitable Sharing",
"F009": "Sale, Exchange, or Donation of Property and Goods",
"F010": "Other Financial Assistance",
}
assistance_type_mapping = {
**grant_type_mapping,
**direct_payment_type_mapping,
**loan_type_mapping,
**other_type_mapping,
}
non_loan_assistance_type_mapping = {**grant_type_mapping, **direct_payment_type_mapping, **other_type_mapping}
non_loan_assistance_type_mapping = {
**grant_type_mapping,
**direct_payment_type_mapping,
**other_type_mapping,
}
procurement_type_mapping = {**contract_type_mapping, **idv_type_mapping}
all_award_types_mappings = {
"contracts": list(contract_type_mapping),
Expand All @@ -141,9 +189,13 @@
}

all_awards_types_to_category = {
type_code: category for category, type_codes in all_award_types_mappings.items() for type_code in type_codes
type_code: category
for category, type_codes in all_award_types_mappings.items()
for type_code in type_codes
}

all_subaward_types = ["grant", "procurement"]

SUBAWARD_MAPPING_LOOKUP = {key: value.replace(".keyword", "") for key, value in subaward_mapping.items()}
SUBAWARD_MAPPING_LOOKUP = {
key: value.replace(".keyword", "") for key, value in subaward_mapping.items()
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@ def test_invalid_award_type_codes(
assert resp.status_code == status.HTTP_400_BAD_REQUEST
assert (
resp.data["detail"]
== "Field 'filter|award_type_codes' is outside valid values ['-1', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11']"
== "Field 'filter|award_type_codes' is outside valid values ['-1', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', 'F001', 'F002', 'F003', 'F004', 'F005', 'F006', 'F007', 'F008', 'F009', 'F010']" # noqa: E501
)
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def test_invalid_award_type_codes(

resp = helpers.post_for_spending_endpoint(client, url, award_type_codes=["ZZ", "08"], def_codes=["L", "M"])
assert resp.status_code == status.HTTP_400_BAD_REQUEST
assert resp.data["detail"] == "Field 'filter|award_type_codes' is outside valid values ['07', '08']"
assert resp.data["detail"] == "Field 'filter|award_type_codes' is outside valid values ['07', '08', 'F003', 'F004']"


@pytest.mark.django_db
Expand Down
Loading