Skip to content

Commit

Permalink
Fallback to empty list when block type is not present on cache.json
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed Nov 13, 2024
1 parent 94d9124 commit 9710511
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/olympia/blocklist/mlbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ def __init__(self, storage: SafeStorage):

@cached_property
def blocked_items(self) -> List[str]:
return self._data.get(self.data_type_key(MLBFDataType.BLOCKED))
return self._data.get(self.data_type_key(MLBFDataType.BLOCKED), [])

@cached_property
def soft_blocked_items(self) -> List[str]:
return self._data.get(self.data_type_key(MLBFDataType.SOFT_BLOCKED))
return self._data.get(self.data_type_key(MLBFDataType.SOFT_BLOCKED), [])

@cached_property
def not_blocked_items(self) -> List[str]:
return self._data.get(self.data_type_key(MLBFDataType.NOT_BLOCKED))
return self._data.get(self.data_type_key(MLBFDataType.NOT_BLOCKED), [])


class MLBFDataBaseLoader(BaseMLBFLoader):
Expand Down
10 changes: 10 additions & 0 deletions src/olympia/blocklist/tests/test_mlbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ def test_loads_data_from_file(self):
loader = MLBFStorageLoader(self.storage)
assert loader._raw == self._data

def test_fallback_to_empty_list_for_missing_key(self):
for key in self._data.keys():
new_data = self._data.copy()
new_data.pop(key)
with self.storage.open('cache.json', 'w') as f:
json.dump(new_data, f)
loader = MLBFStorageLoader(self.storage)
assert loader._raw == {**new_data, key: []}



class TestMLBFDataBaseLoader(_MLBFBase):
def test_load_returns_expected_data(self):
Expand Down

0 comments on commit 9710511

Please sign in to comment.