Commit 7087775f by benjaoming

Merge pull request #332 from spookylukey/fix_upload_for_python3_rebased

Fix upload for python3 rebased
parents 1d5c0338 197bd20f
......@@ -61,9 +61,9 @@ argv = [sys.argv[0], "test"]
if len(sys.argv) == 1:
# Nothing following 'runtests.py':
if django.VERSION < (1,6):
argv.append("wiki")
argv.extend(["wiki", "attachments"])
else:
argv.append("wiki.tests")
argv.extend(["wiki.tests", "wiki.plugins.attachments.tests"])
else:
# Allow tests to be specified:
argv.extend(sys.argv[1:])
......
......@@ -11,29 +11,28 @@ deps =
django-mptt==0.6.0
django-sekizai==0.7
git+https://github.com/mariocesar/sorl-thumbnail@007156ba3428ce02a92dcd9cce03a4803225ea66#egg=sorl.thumbnail
wiki==0.0.23
six==1.6.1
[testenv:py27-django14]
basepython = python2.7
deps =
Django==1.4.10
Django==1.4.15
{[testenv]deps}
[testenv:py27-django15]
basepython = python2.7
deps =
Django==1.5.5
Django==1.5.10
{[testenv]deps}
[testenv:py27-django16]
basepython = python2.7
deps =
Django==1.6.1
Django==1.6.7
{[testenv]deps}
[testenv:py33-django16]
basepython = python3.3
deps =
Django==1.6.1
Django==1.6.7
{[testenv]deps}
......@@ -329,7 +329,7 @@ def _clear_ancestor_cache(article):
ancestor.article.clear_cache()
def on_article_save_clear_cache(instance, **kwargs):
_clear_ancestor_cache(instance)
on_article_delete_clear_cache(instance, **kwargs)
post_save.connect(on_article_save_clear_cache, Article)
def on_article_delete_clear_cache(instance, **kwargs):
......
......@@ -130,7 +130,6 @@ class URLPath(MPTTModel):
"""
try:
for descendant in self.get_descendants(include_self=True).order_by("-level"):
print("deleting " , descendant) #space in string -> " "?
descendant.article.delete()
transaction.commit()
......
......@@ -81,7 +81,7 @@ def upload_path(instance, filename):
upload_path = upload_path.replace('%aid', str(instance.attachment.article.id))
if settings.UPLOAD_PATH_OBSCURIFY:
import random, hashlib
m=hashlib.md5(str(random.randint(0,100000000000000)))
m=hashlib.md5(str(random.randint(0,100000000000000)).encode('ascii'))
upload_path = path.join(upload_path, m.hexdigest())
if settings.APPEND_EXTENSION:
......
from __future__ import absolute_import
import django
if django.VERSION < (1, 6):
# New style autodiscovery of tests doesn't work for Django < 1.6
from .test_views import *
from __future__ import print_function, unicode_literals
from io import BytesIO
from django.core.files.uploadedfile import InMemoryUploadedFile
from django.core.urlresolvers import reverse
from wiki.tests.base import ArticleTestBase
class AttachmentTests(ArticleTestBase):
def test_upload(self):
data = "This is a plain text file".encode('utf-8')
filedata = BytesIO(data)
filestream = InMemoryUploadedFile(filedata, None, 'test.txt', 'text', len(data), None)
article = self.root_article
url = reverse('wiki:attachments_index', kwargs={'path': ''})
response = self.c.post(url,
{'description': 'My file',
'file': filestream,
'save': '1',
})
self.assertRedirects(response, url)
# Check the object was created.
attachment = article.shared_plugins_set.all()[0].attachment
self.assertEqual(attachment.original_filename, 'test.txt')
self.assertEqual(attachment.current_revision.file.file.read(),
data)
from .test_basic import *
from __future__ import absolute_import
import django
if django.VERSION < (1, 6):
# New style autodiscovery of tests doesn't work for Django < 1.6,
# and we don't want to duplicate tests for Django >= 1.6
from .test_basic import *
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import Client
from wiki.models import URLPath
class WebTestBase(TestCase):
def setUp(self):
super(TestCase, self).setUp()
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
User.objects.create_superuser('admin', 'nobody@example.com', 'secret')
self.c = c = Client()
c.login(username='admin', password='secret')
class ArticleTestBase(WebTestBase):
"""Base class for web client tests, that sets up initial root article."""
def setUp(self):
super(ArticleTestBase, self).setUp()
response = self.c.post(reverse('wiki:root_create'), {'content': 'root article content', 'title': 'Root Article'}, follow=True)
self.assertEqual(response.status_code, 200) # sanity check
self.root_article = URLPath.root().article
self.example_data = {
'content': 'The modified text',
'current_revision': '1',
'preview': '1',
#'save': '1', # probably not too important
'summary': 'why edited',
'title': 'wiki test'}
def get_by_path(self, path):
"""Get the article response for the path.
Example: self.get_by_path("Level1/Slug2/").title
"""
return self.c.get(reverse('wiki:get', kwargs={'path': path}))
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import absolute_import
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import Client
import pprint
class InitialWebClientTest(TestCase):
"""Tests by the dummy web client, with manual creating the root article."""
from .base import ArticleTestBase, WebTestBase
def setUp(self):
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
User.objects.create_superuser('admin', 'nobody@example.com', 'secret')
self.c = c = Client()
c.login(username='admin', password='secret')
class RootArticleViewTests(WebTestBase):
"""Tests for creating/viewing the root article."""
def test_root_article(self):
"""Test redirecting to /create-root/, creating the root article and a simple markup."""
......@@ -33,37 +23,11 @@ class InitialWebClientTest(TestCase):
self.assertContains(response, 'test heading h1</h1>')
class WebClientTest(TestCase):
"""Tests by the dummy web client."""
def setUp(self):
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
User.objects.create_superuser('admin', 'nobody@example.com', 'secret')
self.c = c = Client()
c.login(username='admin', password='secret')
response = self.c.post(reverse('wiki:root_create'), {'content': 'root article content', 'title': 'Root Article'})
self.example_data = {
'content': 'The modified text',
'current_revision': '1',
'preview': '1',
#'save': '1', # probably not too important
'summary': 'why edited',
'title': 'wiki test'}
def tearDown(self):
# clear Article cache before the next test
from wiki.models import Article
Article.objects.all().delete()
def get_by_path(self, path):
"""Get the article response for the path.
Example: self.get_by_path("Level1/Slug2/").title
"""
return self.c.get(reverse('wiki:get', kwargs={'path': path}))
class ArticleViewTests(ArticleTestBase):
"""
Tests for article views, assuming a root article already created.
"""
def dump_db_status(self, message=''):
"""Debug printing of the complete important database content."""
print('*** db status *** {}'.format(message))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment