Added failing tests for #613

pull/621/head
Karl Hobley 2014-09-11 10:10:43 +01:00
rodzic 14173f3647
commit 5328a2d98a
2 zmienionych plików z 202 dodań i 0 usunięć

Wyświetl plik

@ -417,3 +417,107 @@ class TestGetUsage(TestCase, WagtailTestUtils):
args=(1,)))
# There's no usage so there should be no table rows
self.assertRegex(response.content, b'<tbody>(\s|\n)*</tbody>')
class TestIssue613(TestCase, WagtailTestUtils):
def get_elasticsearch_backend(self):
from django.conf import settings
from wagtail.wagtailsearch.backends import get_search_backend
backend_path = 'wagtail.wagtailsearch.backends.elasticsearch.ElasticSearch'
# Search WAGTAILSEARCH_BACKENDS for an entry that uses the given backend path
for backend_name, backend_conf in settings.WAGTAILSEARCH_BACKENDS.items():
if backend_conf['BACKEND'] == backend_path:
return get_search_backend(backend_name)
else:
# no conf entry found - skip tests for this backend
raise unittest.SkipTest("No WAGTAILSEARCH_BACKENDS entry for the backend %s" % self.backend_path)
def setUp(self):
self.search_backend = self.get_elasticsearch_backend()
self.login()
from wagtail.wagtailsearch.signal_handlers import register_signal_handlers
register_signal_handlers()
def add_document(self, **params):
# Build a fake file
fake_file = ContentFile(b("A boring example document"))
fake_file.name = 'test.txt'
# Submit
post_data = {
'title': "Test document",
'file': fake_file,
}
post_data.update(params)
response = self.client.post(reverse('wagtaildocs_add_document'), post_data)
# User should be redirected back to the index
self.assertRedirects(response, reverse('wagtaildocs_index'))
# Document should be created
doc = models.Document.objects.filter(title=post_data['title'])
self.assertTrue(doc.exists())
return doc.first()
def edit_document(self, **params):
# Build a fake file
fake_file = ContentFile(b("A boring example document"))
fake_file.name = 'test.txt'
# Create a document without tags to edit
document = models.Document.objects.create(title="Test document", file=fake_file)
# Build another fake file
another_fake_file = ContentFile(b("A boring example document"))
another_fake_file.name = 'test.txt'
# Submit
post_data = {
'title': "Test document changed!",
'file': another_fake_file,
}
post_data.update(params)
response = self.client.post(reverse('wagtaildocs_edit_document', args=(document.id,)), post_data)
# User should be redirected back to the index
self.assertRedirects(response, reverse('wagtaildocs_index'))
# Document should be changed
doc = models.Document.objects.filter(title=post_data['title'])
self.assertTrue(doc.exists())
return doc.first()
def test_issue_613_on_add(self):
# Reset the search index
self.search_backend.reset_index()
self.search_backend.add_type(Document)
# Add a document with some tags
document = self.add_document(tags="hello")
self.search_backend.refresh_index()
# Search for it by tag
results = self.search_backend.search("hello", Document)
# Check
self.assertEqual(len(results), 1)
self.assertEqual(results[0].id, document.id)
def test_issue_613_on_edit(self):
# Reset the search index
self.search_backend.reset_index()
self.search_backend.add_type(Document)
# Add a document with some tags
document = self.edit_document(tags="hello")
self.search_backend.refresh_index()
# Search for it by tag
results = self.search_backend.search("hello", Document)
# Check
self.assertEqual(len(results), 1)
self.assertEqual(results[0].id, document.id)

Wyświetl plik

@ -1037,3 +1037,101 @@ class TestIssue573(TestCase):
# This would crash if the bug is present
image.get_rendition('fill-800x600')
class TestIssue613(TestCase, WagtailTestUtils):
def get_elasticsearch_backend(self):
from django.conf import settings
from wagtail.wagtailsearch.backends import get_search_backend
backend_path = 'wagtail.wagtailsearch.backends.elasticsearch.ElasticSearch'
# Search WAGTAILSEARCH_BACKENDS for an entry that uses the given backend path
for backend_name, backend_conf in settings.WAGTAILSEARCH_BACKENDS.items():
if backend_conf['BACKEND'] == backend_path:
return get_search_backend(backend_name)
else:
# no conf entry found - skip tests for this backend
raise unittest.SkipTest("No WAGTAILSEARCH_BACKENDS entry for the backend %s" % self.backend_path)
def setUp(self):
self.search_backend = self.get_elasticsearch_backend()
self.login()
from wagtail.wagtailsearch.signal_handlers import register_signal_handlers
register_signal_handlers()
def add_image(self, **params):
post_data = {
'title': "Test image",
'file': SimpleUploadedFile('test.png', get_test_image_file().file.getvalue()),
}
post_data.update(params)
response = self.client.post(reverse('wagtailimages_add_image'), post_data)
# Should redirect back to index
self.assertRedirects(response, reverse('wagtailimages_index'))
# Check that the image was created
images = Image.objects.filter(title="Test image")
self.assertEqual(images.count(), 1)
# Test that size was populated correctly
image = images.first()
self.assertEqual(image.width, 640)
self.assertEqual(image.height, 480)
return image
def edit_image(self, **params):
# Create an image to edit
self.image = Image.objects.create(
title="Test image",
file=get_test_image_file(),
)
# Edit it
post_data = {
'title': "Edited",
}
post_data.update(params)
response = self.client.post(reverse('wagtailimages_edit_image', args=(self.image.id,)), post_data)
# Should redirect back to index
self.assertRedirects(response, reverse('wagtailimages_index'))
# Check that the image was edited
image = Image.objects.get(id=self.image.id)
self.assertEqual(image.title, "Edited")
return image
def test_issue_613_on_add(self):
# Reset the search index
self.search_backend.reset_index()
self.search_backend.add_type(Image)
# Add an image with some tags
image = self.add_image(tags="hello")
self.search_backend.refresh_index()
# Search for it by tag
results = self.search_backend.search("hello", Image)
# Check
self.assertEqual(len(results), 1)
self.assertEqual(results[0].id, image.id)
def test_issue_613_on_edit(self):
# Reset the search index
self.search_backend.reset_index()
self.search_backend.add_type(Image)
# Add an image with some tags
image = self.edit_image(tags="hello")
self.search_backend.refresh_index()
# Search for it by tag
results = self.search_backend.search("hello", Image)
# Check
self.assertEqual(len(results), 1)
self.assertEqual(results[0].id, image.id)