Hack around text problem in unit tests.
Now that payloads are not allowed to be text, some unit tests will cause crashes on Python 3 because the payload sent by requests gets passed to FakeKey as a string instead of raw bytes. I haven't been able to figure out a way around the issue that doesn't get super messy inside s3/responses.py so I'm just converting the value to bytes using the system's default encoding.
This commit is contained in:
parent
2cc8784e5c
commit
f15f006f78
@ -9,6 +9,7 @@ import codecs
|
|||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import sys
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ UPLOAD_ID_BYTES = 43
|
|||||||
UPLOAD_PART_MIN_SIZE = 5242880
|
UPLOAD_PART_MIN_SIZE = 5242880
|
||||||
STORAGE_CLASS = ["STANDARD", "REDUCED_REDUNDANCY", "STANDARD_IA", "ONEZONE_IA"]
|
STORAGE_CLASS = ["STANDARD", "REDUCED_REDUNDANCY", "STANDARD_IA", "ONEZONE_IA"]
|
||||||
DEFAULT_KEY_BUFFER_SIZE = 2 ** 24
|
DEFAULT_KEY_BUFFER_SIZE = 2 ** 24
|
||||||
|
DEFAULT_TEXT_ENCODING = sys.getdefaultencoding()
|
||||||
|
|
||||||
|
|
||||||
class FakeDeleteMarker(BaseModel):
|
class FakeDeleteMarker(BaseModel):
|
||||||
@ -74,6 +76,11 @@ class FakeKey(BaseModel):
|
|||||||
def value(self, new_value):
|
def value(self, new_value):
|
||||||
self.value_buffer.seek(0)
|
self.value_buffer.seek(0)
|
||||||
self.value_buffer.truncate()
|
self.value_buffer.truncate()
|
||||||
|
|
||||||
|
# Hack for working around moto's own unit tests; this probably won't
|
||||||
|
# actually get hit in normal use.
|
||||||
|
if isinstance(new_value, six.text_type):
|
||||||
|
new_value = new_value.encode(DEFAULT_TEXT_ENCODING)
|
||||||
self.value_buffer.write(new_value)
|
self.value_buffer.write(new_value)
|
||||||
|
|
||||||
def copy(self, new_name=None):
|
def copy(self, new_name=None):
|
||||||
|
4
tox.ini
4
tox.ini
@ -2,6 +2,10 @@
|
|||||||
envlist = py27, py36
|
envlist = py27, py36
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
|
setenv =
|
||||||
|
BOTO_CONFIG=/dev/null
|
||||||
|
AWS_SECRET_ACCESS_KEY=foobar_secret
|
||||||
|
AWS_ACCESS_KEY_ID=foobar_key
|
||||||
deps =
|
deps =
|
||||||
-r{toxinidir}/requirements.txt
|
-r{toxinidir}/requirements.txt
|
||||||
-r{toxinidir}/requirements-dev.txt
|
-r{toxinidir}/requirements-dev.txt
|
||||||
|
Loading…
Reference in New Issue
Block a user