kopia lustrzana https://github.com/wagtail/wagtail
Search: Frontend tests
rodzic
cb76b0d2ad
commit
56222f9259
|
@ -1,5 +1,68 @@
|
|||
from django.test import TestCase
|
||||
from .utils import get_default_host, login
|
||||
from wagtail.wagtailsearch import models
|
||||
|
||||
|
||||
class TestEditorsPicks(TestCase):
|
||||
pass
|
||||
|
||||
|
||||
class TestEditorsPicksIndexView(TestCase):
|
||||
def setUp(self):
|
||||
login(self.client)
|
||||
|
||||
def get(self, params={}):
|
||||
return self.client.get('/admin/search/editorspicks/', params, HTTP_HOST=get_default_host())
|
||||
|
||||
def test_status_code(self):
|
||||
self.assertEqual(self.get().status_code, 200)
|
||||
|
||||
def test_search_status_code(self):
|
||||
self.assertEqual(self.get({'q': "Hello"}).status_code, 200)
|
||||
|
||||
def test_search_template_context(self):
|
||||
self.assertEqual(self.get({'q': "Hello"}).context['search_query'], "Hello")
|
||||
|
||||
def test_page_status_code(self):
|
||||
self.assertEqual(self.get({'p': '1'}).status_code, 200)
|
||||
|
||||
|
||||
class TestEditorsPicksAddView(TestCase):
|
||||
def setUp(self):
|
||||
login(self.client)
|
||||
|
||||
def get(self, params={}):
|
||||
return self.client.get('/admin/search/editorspicks/add/', params, HTTP_HOST=get_default_host())
|
||||
|
||||
def test_status_code(self):
|
||||
self.assertEqual(self.get().status_code, 200)
|
||||
|
||||
|
||||
class TestEditorsPicksEditView(TestCase):
|
||||
def setUp(self):
|
||||
login(self.client)
|
||||
|
||||
# Create an editors pick to edit
|
||||
self.query = models.Query.get("Hello")
|
||||
self.query.editors_picks.create(page_id=1, description="Root page")
|
||||
|
||||
def get(self, params={}):
|
||||
return self.client.get('/admin/search/editorspicks/' + str(self.query.id) + '/', params, HTTP_HOST=get_default_host())
|
||||
|
||||
def test_status_code(self):
|
||||
self.assertEqual(self.get().status_code, 200)
|
||||
|
||||
|
||||
class TestEditorsPicksDeleteView(TestCase):
|
||||
def setUp(self):
|
||||
login(self.client)
|
||||
|
||||
# Create an editors pick to delete
|
||||
self.query = models.Query.get("Hello")
|
||||
self.query.editors_picks.create(page_id=1, description="Root page")
|
||||
|
||||
def get(self, params={}):
|
||||
return self.client.get('/admin/search/editorspicks/' + str(self.query.id) + '/delete/', params, HTTP_HOST=get_default_host())
|
||||
|
||||
def test_status_code(self):
|
||||
self.assertEqual(self.get().status_code, 200)
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
from django.test import TestCase
|
||||
from .utils import get_default_host
|
||||
|
||||
|
||||
class TestSearchView(TestCase):
|
||||
def get(self, params={}):
|
||||
return self.client.get('/search/', params, HTTP_HOST=get_default_host())
|
||||
|
||||
def test_status_code(self):
|
||||
self.assertEqual(self.get().status_code, 200)
|
||||
|
||||
def test_search_status_code(self):
|
||||
self.assertEqual(self.get({'q': "Hello"}).status_code, 200)
|
||||
|
||||
def test_search_template_context(self):
|
||||
self.assertEqual(self.get({'q': "Hello"}).context['query_string'], "Hello")
|
||||
|
||||
def test_page_status_code(self):
|
||||
self.assertEqual(self.get({'p': '1'}).status_code, 200)
|
||||
|
||||
|
||||
class TestSuggestionsView(TestCase):
|
||||
def get(self, params={}):
|
||||
return self.client.get('/search/suggest/', params, HTTP_HOST=get_default_host())
|
||||
|
||||
def test_status_code(self):
|
||||
self.assertEqual(self.get().status_code, 200)
|
||||
|
||||
def test_search_status_code(self):
|
||||
self.assertEqual(self.get({'q': "Hello"}).status_code, 200)
|
|
@ -1,6 +1,7 @@
|
|||
from django.test import TestCase
|
||||
from django.core import management
|
||||
from wagtail.wagtailsearch import models
|
||||
from .utils import get_default_host, login
|
||||
from StringIO import StringIO
|
||||
import unittest
|
||||
|
||||
|
@ -137,3 +138,14 @@ class TestGarbageCollectCommand(TestCase):
|
|||
management.call_command('search_garbage_collect', interactive=False, stdout=StringIO())
|
||||
|
||||
# TODO: Test that this command is acctually doing its job
|
||||
|
||||
|
||||
class TestQueryChooserView(TestCase):
|
||||
def setUp(self):
|
||||
login(self.client)
|
||||
|
||||
def get(self, params={}):
|
||||
return self.client.get('/admin/search/queries/chooser/', params, HTTP_HOST=get_default_host())
|
||||
|
||||
def test_status_code(self):
|
||||
self.assertEqual(self.get().status_code, 200)
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
from wagtail.wagtailcore.models import Site
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
def get_default_host():
|
||||
return Site.objects.filter(is_default_site=True).first().root_url.split('://')[1]
|
||||
|
||||
|
||||
def login(client):
|
||||
# Create a user
|
||||
User.objects.create_superuser(username='test', email='test@email.com', password='password')
|
||||
|
||||
# Login
|
||||
client.login(username='test', password='password')
|
Ładowanie…
Reference in New Issue