Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update src/olympia/blocklist/tests/test_cron.py
Browse files Browse the repository at this point in the history
Co-authored-by: William Durand <will+git@drnd.me>

Update src/olympia/blocklist/cron.py

Co-authored-by: William Durand <will+git@drnd.me>

Update src/olympia/blocklist/cron.py

Co-authored-by: William Durand <will+git@drnd.me>

Update src/olympia/blocklist/cron.py

Co-authored-by: William Durand <will+git@drnd.me>

Update src/olympia/blocklist/cron.py

Co-authored-by: William Durand <will+git@drnd.me>

Update src/olympia/blocklist/cron.py

Co-authored-by: William Durand <will+git@drnd.me>

Update src/olympia/blocklist/tests/test_cron.py

Co-authored-by: William Durand <will+git@drnd.me>
KevinMind and willdurand committed Nov 25, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 3032f48 commit 29949e2
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/olympia/blocklist/cron.py
Original file line number Diff line number Diff line change
@@ -77,9 +77,9 @@ def _upload_mlbf_to_remote_settings(*, force_base=False):
create_stash = False

# Determine which base filters need to be re uploaded
# and whether a new stash needs to be created
# and whether a new stash needs to be created.
for block_type in BlockType:
# This prevents us from updating a stash or filter based on new soft blocks
# This prevents us from updating a stash or filter based on new soft blocks.
if block_type == BlockType.SOFT_BLOCKED:
log.info(
'Skipping soft-blocks because enable-soft-blocking switch is inactive'
@@ -88,22 +88,22 @@ def _upload_mlbf_to_remote_settings(*, force_base=False):

base_filter = MLBF.load_from_storage(get_base_generation_time(block_type))

# add this block type to the list of filters to be re-uploaded
# Add this block type to the list of filters to be re-uploaded.
if (
force_base
or base_filter is None
or mlbf.should_upload_filter(block_type, base_filter)
):
base_filters_to_update.append(block_type)
# only update the stash if we should AND if
# we aren't already reuploading the filter for this block type
# Only update the stash if we should AND if we aren't already
# re-uploading the filter for this block type.
elif mlbf.should_upload_stash(block_type, previous_filter or base_filter):
create_stash = True

skip_update = len(base_filters_to_update) == 0 and not create_stash
if skip_update:
log.info('No new/modified/deleted Blocks in database; skipping MLBF generation')
# Delete the locally generated MLBF directory and files as they are not needed
# Delete the locally generated MLBF directory and files as they are not needed.
mlbf.delete()
return

6 changes: 3 additions & 3 deletions src/olympia/blocklist/tests/test_cron.py
Original file line number Diff line number Diff line change
@@ -617,7 +617,7 @@ def test_compares_against_base_filter_if_missing_previous_filter(self):
upload_mlbf_to_remote_settings(force_base=False)
assert not self.mocks['olympia.blocklist.cron.upload_filter.delay'].called

# delete the last filter, now the base filter will be used to compare
# Delete the last filter, now the base filter will be used to compare
MLBF.load_from_storage(self.last_time).delete()
upload_mlbf_to_remote_settings(force_base=False)
# We expect to not upload anything as soft blocking is disabled
@@ -698,8 +698,8 @@ def test_get_last_generation_time(self):
def test_get_base_generation_time(self):
for block_type in BlockType:
assert get_base_generation_time(block_type) is None
set_config(MLBF_BASE_ID_CONFIG_KEY(block_type, compat=True), 1)
assert get_base_generation_time(block_type) == 1
set_config(MLBF_BASE_ID_CONFIG_KEY(block_type, compat=True), 123)
assert get_base_generation_time(block_type) == 123


@pytest.mark.django_db

0 comments on commit 29949e2

Please sign in to comment.