Skip to content

Commit

Permalink
Verify cron passes correct args to task
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed Nov 12, 2024
1 parent 89554c1 commit 08d3851
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/olympia/blocklist/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ def _upload_mlbf_to_remote_settings(*, force_base=False):

upload_filter.delay(
generation_time,
filters_to_update=[key.name for key in base_filters_to_update],
update_stash=update_stash,
filter_list=[key.name for key in base_filters_to_update],
upload_stash=update_stash,
)


Expand Down
2 changes: 2 additions & 0 deletions src/olympia/blocklist/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
bracket_open_regex = re.compile(r'(?<!\\){')
bracket_close_regex = re.compile(r'(?<!\\)}')


def BLOCKLIST_RECORD_MLBF_BASE(block_type: BlockType):
match block_type:
case BlockType.SOFT_BLOCKED:
Expand All @@ -45,6 +46,7 @@ def BLOCKLIST_RECORD_MLBF_BASE(block_type: BlockType):
case _:
raise ValueError(f'Unknown block type: {block_type}')


@task
@use_primary_db
def process_blocklistsubmission(multi_block_submit_id, **kw):
Expand Down
49 changes: 31 additions & 18 deletions src/olympia/blocklist/tests/test_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
)
from olympia.blocklist.mlbf import MLBF
from olympia.blocklist.models import Block, BlocklistSubmission, BlockType, BlockVersion
from olympia.blocklist.tasks import upload_filter
from olympia.blocklist.utils import datetime_to_ts
from olympia.constants.blocklist import MLBF_BASE_ID_CONFIG_KEY, MLBF_TIME_CONFIG_KEY
from olympia.zadmin.models import set_config
Expand Down Expand Up @@ -144,8 +145,8 @@ def test_missing_last_filter_uses_base_filter(self):
assert (
mock.call(
self.current_time,
filters_to_update=[],
update_stash=True,
filter_list=[],
upload_stash=True,
)
) in self.mocks['olympia.blocklist.cron.upload_filter.delay'].call_args_list

Expand Down Expand Up @@ -222,15 +223,15 @@ def test_upload_stash_unless_force_base(self):
].call_args_list == [
mock.call(
self.current_time,
filters_to_update=[],
update_stash=True,
filter_list=[],
upload_stash=True,
)
]
assert (
mock.call(
self.current_time,
filters_to_update=[],
update_stash=True,
filter_list=[],
upload_stash=True,
)
) in self.mocks['olympia.blocklist.cron.upload_filter.delay'].call_args_list

Expand All @@ -243,8 +244,8 @@ def test_upload_stash_unless_force_base(self):
assert (
mock.call(
self.current_time,
filters_to_update=[BlockType.BLOCKED.name, BlockType.SOFT_BLOCKED.name],
update_stash=False,
filter_list=[BlockType.BLOCKED.name, BlockType.SOFT_BLOCKED.name],
upload_stash=False,
)
) in self.mocks['olympia.blocklist.cron.upload_filter.delay'].call_args_list

Expand All @@ -259,8 +260,8 @@ def test_upload_stash_unless_missing_base_filter(self):
].call_args_list == [
mock.call(
self.current_time,
filters_to_update=[],
update_stash=True,
filter_list=[],
upload_stash=True,
)
]
mlbf = MLBF.load_from_storage(self.current_time)
Expand All @@ -275,8 +276,8 @@ def test_upload_stash_unless_missing_base_filter(self):
assert (
mock.call(
self.current_time,
filters_to_update=[BlockType.BLOCKED.name, BlockType.SOFT_BLOCKED.name],
update_stash=False,
filter_list=[BlockType.BLOCKED.name, BlockType.SOFT_BLOCKED.name],
upload_stash=False,
)
in self.mocks['olympia.blocklist.cron.upload_filter.delay'].call_args_list
)
Expand All @@ -296,8 +297,8 @@ def test_upload_stash_unless_enough_changes(self):
].call_args_list == [
mock.call(
self.current_time,
filters_to_update=[],
update_stash=True,
filter_list=[],
upload_stash=True,
)
]
mlbf = MLBF.load_from_storage(self.current_time)
Expand All @@ -314,8 +315,8 @@ def test_upload_stash_unless_enough_changes(self):
assert (
mock.call(
self.current_time,
filters_to_update=[BlockType.BLOCKED.name],
update_stash=False,
filter_list=[BlockType.BLOCKED.name],
upload_stash=False,
)
in self.mocks['olympia.blocklist.cron.upload_filter.delay'].call_args_list
)
Expand All @@ -338,8 +339,8 @@ def test_upload_stash_even_if_filter_is_updated(self):
].call_args_list == [
mock.call(
self.current_time,
filters_to_update=[BlockType.BLOCKED.name],
update_stash=True,
filter_list=[BlockType.BLOCKED.name],
upload_stash=True,
)
]

Expand Down Expand Up @@ -380,6 +381,18 @@ def test_dont_skip_update_if_all_blocked_or_not_blocked(self):
upload_mlbf_to_remote_settings(force_base=True)
assert self.mocks['olympia.blocklist.cron.upload_filter.delay'].called

def test_pass_correct_arguments_to_upload_filter(self):
self.mocks['olympia.blocklist.cron.upload_filter.delay'].stop()
with mock.patch(
'olympia.blocklist.cron.upload_filter.delay', wraps=upload_filter.delay
) as spy_delay:
upload_mlbf_to_remote_settings(force_base=True)
spy_delay.assert_called_with(
self.current_time,
filter_list=[block_type.name for block_type in BlockType],
upload_stash=False,
)


class TestTimeMethods(TestCase):
@freeze_time('2024-10-10 12:34:56')
Expand Down

0 comments on commit 08d3851

Please sign in to comment.