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 f39e370
Show file tree
Hide file tree
Showing 2 changed files with 34 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
50 changes: 32 additions & 18 deletions src/olympia/blocklist/tests/test_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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
from olympia.blocklist.tasks import upload_filter


STATSD_PREFIX = 'blocklist.cron.upload_mlbf_to_remote_settings.'
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,19 @@ 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 f39e370

Please sign in to comment.