Skip to content

Commit

Permalink
Merge pull request #530 from benjaoming/fix-attachment-search
Browse files Browse the repository at this point in the history
Fix 'AttachmentSearchView' object has no attribute 'get_form'
  • Loading branch information
benjaoming committed Jan 25, 2016
2 parents 56abf53 + 80a4334 commit 7806854
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
33 changes: 23 additions & 10 deletions wiki/plugins/attachments/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class AttachmentTests(ArticleWebTestBase):
def setUp(self):
super(AttachmentTests, self).setUp()
self.article = self.root_article
self.test_data = "This is a plain text file"
self.test_description = 'My file'

def _createTxtFilestream(self, strData, **kwargs):
"""
Expand All @@ -37,25 +39,27 @@ def _createTxtFilestream(self, strData, **kwargs):
)
return filestream

def test_upload(self):
"""
Tests that simple file upload uploads correctly
Uploading a file should preserve the original filename.
Uploading should not modify file in any way.
"""
def _create_test_attachment(self):
url = reverse('wiki:attachments_index', kwargs={'path': ''})
data = "This is a plain text file"
filestream = self._createTxtFilestream(data)
filestream = self._createTxtFilestream(self.test_data)
response = self.c.post(url,
{'description': 'My file',
{'description': self.test_description,
'file': filestream,
'save': '1',
})
self.assertRedirects(response, url)

def test_upload(self):
"""
Tests that simple file upload uploads correctly
Uploading a file should preserve the original filename.
Uploading should not modify file in any way.
"""
self._create_test_attachment()
# Check the object was created.
attachment = self.article.shared_plugins_set.all()[0].attachment
self.assertEqual(attachment.original_filename, 'test.txt')
self.assertEqual(attachment.current_revision.file.file.read(), data.encode('utf-8'))
self.assertEqual(attachment.current_revision.file.file.read(), self.test_data.encode('utf-8'))

def test_replace(self):
"""
Expand Down Expand Up @@ -116,3 +120,12 @@ def test_replace(self):
self.assertEqual(attachment.current_revision.file.file.read(), replacement_data2.encode('utf-8'))
# The first replacement should no longer be in the filehistory
self.assertNotIn(first_replacement, attachment.attachmentrevision_set.all())

def test_search(self):
"""
Call the search view
"""
self._create_test_attachment()
url = reverse('wiki:attachments_search', kwargs={'path': ''})
response = self.c.get(url, {'query': self.test_description})
self.assertContains(response, self.test_description)
9 changes: 3 additions & 6 deletions wiki/plugins/attachments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,12 @@ class AttachmentSearchView(ArticleMixin, ListView):

@method_decorator(get_article(can_write=True))
def dispatch(self, request, article, *args, **kwargs):
return super(
AttachmentSearchView,
self).dispatch(
return super(AttachmentSearchView, self).dispatch(
request,
article,
*args,
**kwargs)
**kwargs
)

def get_queryset(self):
self.query = self.request.GET.get('query', None)
Expand All @@ -473,6 +472,4 @@ def get_context_data(self, **kwargs):
kwargs.update(kwargs_article)
kwargs.update(kwargs_listview)
kwargs['selected_tab'] = 'attachments'
if 'form' not in kwargs:
kwargs['form'] = self.get_form()
return kwargs
3 changes: 2 additions & 1 deletion wiki/templatetags/wiki_tags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
# -*- coding: utf-8 -*-

import re

from django.conf import settings as django_settings
Expand Down

0 comments on commit 7806854

Please sign in to comment.