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

Apply smart_text on file names in python2.7 [s3boto3] #217

Merged
merged 1 commit into from
Apr 4, 2017
Merged

Apply smart_text on file names in python2.7 [s3boto3] #217

merged 1 commit into from
Apr 4, 2017

Conversation

g-as
Copy link
Contributor

@g-as g-as commented Oct 10, 2016

Not a 100% sure it's the best approach, but there it is: my attempt to address #216.

I feel that _encode_name and _decode_name are starting to lose their naming/meaning values since they now end up doing almost the same thing.

Also, I didn't know what to precisely test. The only thing I know for sure is that the test I added fail without the switch from smart_str to smart_text.

@codecov-io
Copy link

codecov-io commented Oct 10, 2016

Codecov Report

Merging #217 into master will decrease coverage by 13.14%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #217       +/-   ##
===========================================
- Coverage   72.48%   59.33%   -13.15%     
===========================================
  Files          10       17        +7     
  Lines        1381     1692      +311     
===========================================
+ Hits         1001     1004        +3     
- Misses        380      688      +308
Impacted Files Coverage Δ
storages/backends/s3boto3.py 81.92% <100%> (-3.03%) ⬇️
storages/backends/s3boto.py 86.13% <0%> (-0.23%) ⬇️
storages/backends/hashpath.py 85.71% <0%> (ø)
storages/backends/image.py 0% <0%> (ø)
storages/backends/couchdb.py 0% <0%> (ø)
storages/backends/overwrite.py 0% <0%> (ø)
storages/backends/database.py 0% <0%> (ø)
storages/backends/symlinkorcopy.py 0% <0%> (ø)
storages/backends/mogile.py 0% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1ad4890...60d2d51. Read the comment docs.

@belak
Copy link

belak commented Nov 17, 2016

This also fails in the s3boto backend.

@jschneier
Copy link
Owner

Okay, let me add a test and then I'll merge...

@jschneier
Copy link
Owner

Oh you have a test! How awesome.

@jschneier
Copy link
Owner

@belak thanks for pointing that out. As soon as I merge this I will fix it in the Boto backend as well.

@jschneier
Copy link
Owner

I'm happy to merge this but I can't quite get the UnicodeDecodeError to manifest even if I remove the fix and keep the tests. Any pointers on how to get that to happen?

@g-as
Copy link
Contributor Author

g-as commented Jan 12, 2017

Hey,

rolling back my proposed fixed but keeping the added/modified tests, I get this for each python2.7 test suite:

self = <tests.test_s3boto3.S3Boto3StorageTests testMethod=test_special_characters>

    def test_special_characters(self):
        self.storage.custom_domain = "mock.cloudfront.net"

        name = "ãlöhâ.jpg"
        content = ContentFile('new content')
        self.storage.save(name, content)
>       self.storage.bucket.Object.assert_called_once_with(name)

tests/test_s3boto3.py:330:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py27-django18/lib/python2.7/site-packages/mock.py:846: in assert_called_once_with
    return self.assert_called_with(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

_mock_self = <MagicMock name='mock.Bucket().Object' id='139854456779664'>, args = ('ãlöhâ.jpg',), kwargs = {}, self = <MagicMock name='mock.Bucket().Object' id='139854456779664'>
msg = "Expected call: Object(u'\\xe3l\\xf6h\\xe2.jpg')\nActual call: Object('\\xc3\\xa3l\\xc3\\xb6h\\xc3\\xa2.jpg')"

    def assert_called_with(_mock_self, *args, **kwargs):
        """assert that the mock was called with the specified arguments.

            Raises an AssertionError if the args and keyword args passed in are
            different to the last call to the mock."""
        self = _mock_self
        if self.call_args is None:
            expected = self._format_mock_call_signature(args, kwargs)
            raise AssertionError('Expected call: %s\nNot called' % (expected,))

        if self.call_args != (args, kwargs):
            msg = self._format_mock_failure_message(args, kwargs)
>           raise AssertionError(msg)
E           AssertionError: Expected call: Object(u'\xe3l\xf6h\xe2.jpg')
E           Actual call: Object('\xc3\xa3l\xc3\xb6h\xc3\xa2.jpg')

.tox/py27-django18/lib/python2.7/site-packages/mock.py:835: AssertionError
------------------------------------------------------------------------------------------ Captured stderr call -------------------------------------------------------------------------------------------
/home/vagrant/code/django-storages-wam/.tox/py27-django18/lib/python2.7/site-packages/mock.py:2075: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  return (other_args, other_kwargs) == (self_args, self_kwargs)
_______________________________________________________________________________ S3Boto3StorageTests.test_storage_open_write _______________________________________________________________________________

self = <tests.test_s3boto3.S3Boto3StorageTests testMethod=test_storage_open_write>

    def test_storage_open_write(self):
        """
            Test opening a file in write mode
            """
        name = 'test_open_for_writïng.txt'
        content = 'new content'

        # Set the encryption flag used for multipart uploads
        self.storage.encryption = True
        self.storage.reduced_redundancy = True
        self.storage.default_acl = 'public-read'

        file = self.storage.open(name, 'w')
>       self.storage.bucket.Object.assert_called_with(name)

tests/test_s3boto3.py:176:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

_mock_self = <MagicMock name='mock.Bucket().Object' id='139854456294352'>, args = ('test_open_for_writïng.txt',), kwargs = {}, self = <MagicMock name='mock.Bucket().Object' id='139854456294352'>
msg = "Expected call: Object(u'test_open_for_writ\\xefng.txt')\nActual call: Object('test_open_for_writ\\xc3\\xafng.txt')"

    def assert_called_with(_mock_self, *args, **kwargs):
        """assert that the mock was called with the specified arguments.

            Raises an AssertionError if the args and keyword args passed in are
            different to the last call to the mock."""
        self = _mock_self
        if self.call_args is None:
            expected = self._format_mock_call_signature(args, kwargs)
            raise AssertionError('Expected call: %s\nNot called' % (expected,))

        if self.call_args != (args, kwargs):
            msg = self._format_mock_failure_message(args, kwargs)
>           raise AssertionError(msg)
E           AssertionError: Expected call: Object(u'test_open_for_writ\xefng.txt')
E           Actual call: Object('test_open_for_writ\xc3\xafng.txt')

.tox/py27-django18/lib/python2.7/site-packages/mock.py:835: AssertionError

Here is the full tox output:
storages_test_report.txt

@jschneier
Copy link
Owner

@AGASS007 yes I did just that. But I still don't see the UnicodeDecodeError that you mentioned in #216. I understand what the issue between the test diffing (code point/encoded bytes) but would like to see the exception!

@g-as
Copy link
Contributor Author

g-as commented Jan 13, 2017

@jschneier I pasted a stacktrace in the issue #216

@nschlemm
Copy link

@AGASS007 thanks for fixing this!
@jschneier please integrate this into the next release. THX :)

@jschneier
Copy link
Owner

Okay. Interestingly I cannot reproduce this on the non-Boto3 backend. I'm going to then remove _decode_name. This looks good.

@jschneier jschneier merged commit 01f105e into jschneier:master Apr 4, 2017
jschneier added a commit that referenced this pull request Apr 4, 2017
@jschneier
Copy link
Owner

@belak you mentioned this failing for you on the boto backend, i could not reproduce. have a failing test case?

@belak
Copy link

belak commented Apr 4, 2017

I don't unfortunately. If I manage to reproduce it, I'll open an issue.

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 this pull request may close these issues.

5 participants