Skip to content

Commit

Permalink
fix: coherent.awards_status skips if the id isn't set and fails if th…
Browse files Browse the repository at this point in the history
…e id matches an awardID of None
  • Loading branch information
jpmckinney committed Oct 30, 2021
1 parent 3444ed6 commit 79549e8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
20 changes: 15 additions & 5 deletions contracting_process/resource_level/coherent/awards_status.py
@@ -1,3 +1,8 @@
"""
If an award's status is inactive ('pending', 'cancelled', 'unsuccessful'), then no contract's awardID matches the
award's id.
"""

from tools.checks import get_empty_result_resource
from tools.getter import get_values

Expand All @@ -10,23 +15,28 @@ def calculate(item):
awards = [
v
for v in get_values(item, "awards")
if "status" in v["value"] and v["value"]["status"] in ["pending", "cancelled", "unsuccessful"]
if "id" in v["value"]
and "status" in v["value"]
and v["value"]["status"] in ("pending", "cancelled", "unsuccessful")
]

if len(awards) == 0:
result["meta"] = {"reason": "criteria not met"}
if not awards:
result["meta"] = {"reason": "no award with an id is inactive"}
return result

contracts_awardID = [v for v in get_values(item, "contracts.awardID", value_only=True) if v is not None]
contracts_award_ids = [v for v in get_values(item, "contracts.awardID", value_only=True)]

application_count = 0
pass_count = 0
result["meta"] = {"processed_awards": []}
for award in awards:
passed = award["value"]["id"] not in contracts_awardID
# Note: Don't cast IDs to string for comparison. Users should be able to match IDs without doing so.
passed = award["value"]["id"] not in contracts_award_ids

result["meta"]["processed_awards"].append(
{"path": award["path"], "id": award["value"]["id"], "result": passed}
)

application_count += 1
if passed:
pass_count += 1
Expand Down
5 changes: 4 additions & 1 deletion docs/changelog.rst
Expand Up @@ -7,6 +7,9 @@ This changelog only notes major changes, to notify other developers.
----------

- feat: Determine field-level checks based on release schema. :issue:`12`
- fix: ``coherent.tender_status`` now fails on non-zero length arrays (was passing if all entries were blank). :commit:`3444ed6`
- fix: ``coherent.awards_status`` now skips if the ``id`` isn't set (was failing).
- fix: ``coherent.awards_status`` now fails if the ``id`` matches an ``awardID`` of ``None`` (was passing).
- fix: Add missing field-level checks: ``language``, ``contracts.implementation.transactions.amount.amount``, ``contracts.implementation.transactions.amount.currency``. :commit:`2f0fd89`
- fix: Remove extra field-level checks: ``contracts.implementation``, ``contracts.implementation.transactions.currency``. :commit:`2f0fd89`
- refactor: Reduce code duplication in field-level checks. :compare:`2df8f95..7ef148f`
Expand All @@ -15,7 +18,7 @@ This changelog only notes major changes, to notify other developers.
----------

- fix: Refresh and expire external codelists appropriately. :issue:`31` :issue:`33`
- fix: ``coherent.milestone_status`` now works (was always N/A).
- fix: ``coherent.milestone_status`` now works (was always skipping).
- fix: ``coherent/value_realistic`` now uses ``planning.budget.amount`` (was ``planning.budget.value``).
- fix: ``distribution.value_currency`` now uses ``planning.budget.amount.currency`` (was ``planning.budget.value.currency``).
- refactor: Re-do the CLI interface. :commit:`ef8a9bf` :commit:`75a3859` :commit:`160aaa8`
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Expand Up @@ -111,6 +111,7 @@ def test_failing(self):


class CompiledReleaseTests:
maxDiff = None
passing_kwargs = {}
failing_kwargs = {}
method = "calculate"
Expand Down
10 changes: 8 additions & 2 deletions tests/compiled_release/coherent/test_awards_status.py
Expand Up @@ -8,8 +8,8 @@ class TestCase(CompiledReleaseTests, unittest.TestCase):
module = awards_status
skipping = [
(
{"awards": [{}, {"status": None}, {"status": "active"}]},
"criteria not met",
{"awards": [{}, {"status": None}, {"status": "active"}, {"status": "pending"}]},
"no award with an id is inactive",
)
]
passing = [
Expand Down Expand Up @@ -44,6 +44,12 @@ class TestCase(CompiledReleaseTests, unittest.TestCase):
1,
0,
),
(
{"awards": [{"status": "pending", "id": None}], "contracts": [{"awardID": None}]},
{"processed_awards": [{"path": "awards[0]", "id": None, "result": False}]},
1,
0,
),
(
{
"awards": [{"status": "pending", "id": 0}, {"status": "pending", "id": 1}],
Expand Down

0 comments on commit 79549e8

Please sign in to comment.