From 335e0df6791c2afeb911c63f7378882a42f002cd Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Tue, 1 Feb 2022 14:47:20 +0100 Subject: [PATCH] Do not crash if collection has unexpected review status (#953) --- checks/remotesettings/collections_consistency.py | 5 +++++ .../remotesettings/test_collections_consistency.py | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/checks/remotesettings/collections_consistency.py b/checks/remotesettings/collections_consistency.py index 1305294d..d66741de 100644 --- a/checks/remotesettings/collections_consistency.py +++ b/checks/remotesettings/collections_consistency.py @@ -38,6 +38,11 @@ async def has_inconsistencies(server_url, auth, resource): # Collection status is reset on any modification, so if status is ``to-review``, # then records in the source should be exactly the same as the records in the preview if status == "to-review": + if "preview" not in resource: + return "{bucket}/{collection} should not have 'to-review' status".format( + **resource["source"] + ) + source_records = await client.get_records(**source) preview_records = await client.get_records(**resource["preview"]) diff = compare_collections(source_records, preview_records) diff --git a/tests/checks/remotesettings/test_collections_consistency.py b/tests/checks/remotesettings/test_collections_consistency.py index 3dcde202..d1886f9a 100644 --- a/tests/checks/remotesettings/test_collections_consistency.py +++ b/tests/checks/remotesettings/test_collections_consistency.py @@ -77,6 +77,20 @@ async def test_has_inconsistencies_unsupported_status(mock_responses): assert "Unexpected status" in result +async def test_unexpected_review_status(mock_responses): + server_url = "http://fake.local/v1" + collection_url = server_url + COLLECTION_URL.format( + "security-workspace", "blocklist" + ) + mock_responses.get( + collection_url, payload={"data": {"id": "blocklist", "status": "to-review"}} + ) + + result = await has_inconsistencies(server_url, FAKE_AUTH, RESOURCES[1]) + + assert result == "security-workspace/blocklist should not have 'to-review' status" + + async def test_has_inconsistencies_to_review_preview_differs(mock_responses): server_url = "http://fake.local/v1" resource = {