Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_storage_save_gzipped test fail: AssertionError in content_type #1463

Closed
onny opened this issue Oct 28, 2024 · 0 comments · Fixed by #1476
Closed

test_storage_save_gzipped test fail: AssertionError in content_type #1463

onny opened this issue Oct 28, 2024 · 0 comments · Fixed by #1476

Comments

@onny
Copy link

onny commented Oct 28, 2024

Actual AssertionError in content_type

E           AssertionError: expected call not found.
E           Expected: upload_from_file(<ANY>, rewind=True, retry=<google.api_core.retry.retry_unary.Retry object at 0x7ffff399e120>, size=11, predefined_acl=None, content_type='application/javascript')
E             Actual: upload_from_file(<ContentFile: Raw content>, rewind=True, retry=<google.api_core.retry.retry_unary.Retry object at 0x7ffff399e120>, size=11, predefined_acl=None, content_type='text/javascript')

Full log:

_____________ GoogleCloudGzipClientTests.test_storage_save_gzipped _____________
self = <tests.test_gcloud.GoogleCloudGzipClientTests testMethod=test_storage_save_gzipped>
args = (<MagicMock name='_do_upload' id='140737256238128'>,)
name = 'test_storage_save.js.gz', content = <ContentFile: Raw content>
blob = <Blob: None, x, None>
    @mock.patch("google.cloud.storage.blob.Blob._do_upload")
    def test_storage_save_gzipped(self, *args):
        """
        Test saving a gzipped file
        """
        name = "test_storage_save.js.gz"
        content = ContentFile("I am gzip'd", name=name)
        blob = Blob("x", None)
        blob.upload_from_file = mock.MagicMock(side_effect=blob.upload_from_file)
        patcher = mock.patch("google.cloud.storage.Bucket.get_blob", return_value=blob)
        try:
            patcher.start()
            self.storage.save(name, content)
            obj = self.storage._bucket.get_blob()
>           obj.upload_from_file.assert_called_with(
                mock.ANY,
                rewind=True,
                retry=DEFAULT_RETRY,
                size=11,
                predefined_acl=None,
                content_type="application/javascript",
            )
tests/test_gcloud.py:533:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <MagicMock name='Client().bucket().get_blob().upload_from_file' id='140737256396064'>
args = (<ANY>,)
kwargs = {'content_type': 'application/javascript', 'predefined_acl': None, 'retry': <google.api_core.retry.retry_unary.Retry object at 0x7ffff399e120>, 'rewind': True, ...}
expected = call(<ANY>, rewind=True, retry=<google.api_core.retry.retry_unary.Retry object at 0x7ffff399e120>, size=11, predefined_acl=None, content_type='application/javascript')
actual = call(<ContentFile: Raw content>, rewind=True, retry=<google.api_core.retry.retry_unary.Retry object at 0x7ffff399e120>, size=11, predefined_acl=None, content_type='text/javascript')
_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x7ffff2328d60>
cause = None
    def assert_called_with(self, /, *args, **kwargs):
        """assert that the last call was made with the specified arguments.
        Raises an AssertionError if the args and keyword args passed in are
        different to the last call to the mock."""
        if self.call_args is None:
            expected = self._format_mock_call_signature(args, kwargs)
            actual = 'not called.'
            error_message = ('expected call not found.\nExpected: %s\n  Actual: %s'
                    % (expected, actual))
            raise AssertionError(error_message)
        def _error_message():
            msg = self._format_mock_failure_message(args, kwargs)
            return msg
        expected = self._call_matcher(_Call((args, kwargs), two=True))
        actual = self._call_matcher(self.call_args)
        if actual != expected:
            cause = expected if isinstance(expected, Exception) else None
>           raise AssertionError(_error_message()) from cause
E           AssertionError: expected call not found.
E           Expected: upload_from_file(<ANY>, rewind=True, retry=<google.api_core.retry.retry_unary.Retry object at 0x7ffff399e120>, size=11, predefined_acl=None, content_type='application/javascript')
E             Actual: upload_from_file(<ContentFile: Raw content>, rewind=True, retry=<google.api_core.retry.retry_unary.Retry object at 0x7ffff399e120>, size=11, predefined_acl=None, content_type='text/javascript')
/nix/store/wfbjq35kxs6x83c3ncpfxdyl5gbhdx4h-python3-3.12.6/lib/python3.12/unittest/mock.py:947: AssertionError

Could be missing support for the latest version of Mock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant