Skip to content

Commit

Permalink
DRY principe for computing the path of media_object on metaweblog
Browse files Browse the repository at this point in the history
  • Loading branch information
Fantomas42 committed Jan 14, 2015
1 parent 2df33af commit 4ef2302
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 3 additions & 2 deletions zinnia/tests/test_metaweblog.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def test_new_media_object(self):
file_ = TemporaryFile()
file_.write('My test content'.encode('utf-8'))
file_.seek(0)
media = {'name': 'zinnia_test_file.txt',
media = {'name': 'test file.txt',
'type': 'text/plain',
'bits': Binary(file_.read())}
file_.close()
Expand All @@ -332,6 +332,7 @@ def test_new_media_object(self):
1, 'contributor', 'password', media)
new_media = self.server.metaWeblog.newMediaObject(
1, 'webmaster', 'password', media)
self.assertTrue('/zinnia_test_file' in new_media['url'])

self.assertTrue('/test-file' in new_media['url'])
default_storage.delete('/'.join([
UPLOAD_TO, new_media['url'].split('/')[-1]]))
4 changes: 1 addition & 3 deletions zinnia/xmlrpc/metaweblog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""XML-RPC methods of Zinnia metaWeblog API"""
import os
from datetime import datetime
try:
from xmlrpc.client import Fault
Expand Down Expand Up @@ -28,7 +27,6 @@
from zinnia.models.author import Author
from zinnia.models.category import Category
from zinnia.settings import PROTOCOL
from zinnia.settings import UPLOAD_TO
from zinnia.managers import DRAFT, PUBLISHED


Expand Down Expand Up @@ -386,6 +384,6 @@ def new_media_object(blog_id, username, password, media):
=> media structure
"""
authenticate(username, password)
path = default_storage.save(os.path.join(UPLOAD_TO, media['name']),
path = default_storage.save(Entry().image_upload_to(media['name']),
ContentFile(media['bits'].data))
return {'url': default_storage.url(path)}

0 comments on commit 4ef2302

Please sign in to comment.