зеркало из https://github.com/mozilla/FlightDeck.git
failing tests added
* adding xml and json to the editable files * try to save attachment, on failure encode and try to save again
This commit is contained in:
Родитель
68987e7baa
Коммит
ad33de2c65
|
@ -59,7 +59,7 @@ from elasticutils.utils import retry_on_timeout
|
|||
|
||||
log = commonware.log.getLogger('f.jetpack')
|
||||
|
||||
EDITABLE_EXTENSIONS = ("html", "css", "js", "txt")
|
||||
EDITABLE_EXTENSIONS = ("html", "css", "js", "txt", "xml", "json")
|
||||
|
||||
def make_name(value=None):
|
||||
" wrap for slugify "
|
||||
|
@ -2376,6 +2376,11 @@ class Attachment(BaseModel):
|
|||
kwargs['encoding'] = 'utf-8'
|
||||
kwargs['mode'] = 'w'
|
||||
|
||||
try:
|
||||
with codecs.open(self.get_file_path(), **kwargs) as f:
|
||||
f.write(data)
|
||||
except UnicodeDecodeError, UnicodeEncodeError:
|
||||
data = unicode(data, 'utf-8')
|
||||
try:
|
||||
with codecs.open(self.get_file_path(), **kwargs) as f:
|
||||
f.write(data)
|
||||
|
|
|
@ -125,6 +125,27 @@ class AttachmentTest(TestCase):
|
|||
assert os.path.isfile(attachment.get_file_path())
|
||||
assert attachment.read()
|
||||
|
||||
def test_attachment_with_kanji_from_web(self):
|
||||
url = ("file://%s/apps/jetpack/tests/"
|
||||
"sample_attachment_kanji_UTF8_without_BOM.json") % settings.ROOT
|
||||
URLField.clean = Mock(return_value=url)
|
||||
addon = Package.objects.create(
|
||||
type='a',
|
||||
author=self.author)
|
||||
self.author.set_password('secure')
|
||||
self.author.save()
|
||||
self.client.login(username=self.author.username, password='secure')
|
||||
response = self.client.post(addon.latest.get_add_attachment_url(), {
|
||||
'url': url,
|
||||
'filename': 'sample_attachment_kanji_UTF8_without_BOM.json',
|
||||
'force_contenttype': 'utf-8'})
|
||||
eq_(response.status_code, 200)
|
||||
addon = Package.objects.get(author=self.author)
|
||||
eq_(addon.latest.revision_number, 1)
|
||||
attachment = addon.latest.attachments.get()
|
||||
eq_('sample_attachment_kanji_UTF8_without_BOM', attachment.filename)
|
||||
assert os.path.isfile(attachment.get_file_path())
|
||||
assert attachment.read()
|
||||
|
||||
def test_create_image_attachment(self):
|
||||
" test simply shouldn't raise any errors "
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{ "test": [
|
||||
{"country":"日本"}
|
||||
]}
|
|
@ -0,0 +1,3 @@
|
|||
{ "test": [
|
||||
{"country":"日本"}
|
||||
]}
|
Загрузка…
Ссылка в новой задаче