Skip to content

Commit

Permalink
fix test with context change
Browse files Browse the repository at this point in the history
  • Loading branch information
sbusso committed Mar 25, 2024
1 parent efd898b commit 2838f7e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/test_handlers.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import json
from unittest.mock import patch

from scrapework.core.collector import MetadataCollector
from scrapework.core.context import Context
from scrapework.handlers import JsonFileHandler, S3Handler


def build_context():
return Context(collector=MetadataCollector(), variables={})


def test_process_items_with_s3_backend():
items = [{"name": "item1"}, {"name": "item2"}]

pipeline = S3Handler(s3_bucket="my-bucket", filename="example.json")

with patch("boto3.client") as mock_s3_client:
pipeline.process_items(items)
pipeline.process_items(build_context(), items)

mock_s3_client.assert_called_once_with("s3")
mock_s3_client.return_value.put_object.assert_called_once_with(
Expand All @@ -25,6 +31,6 @@ def test_process_items_with_json_file_backend():
pipeline = JsonFileHandler(filename=filename)

with patch("builtins.open") as mock_open:
pipeline.process_items(items)
pipeline.process_items(build_context(), items)
assert mock_open.call_count == 1
assert mock_open.call_args_list[0][0][0] == filename

0 comments on commit 2838f7e

Please sign in to comment.