Skip to content

Commit

Permalink
Try to make the haystack test actually test something.
Browse files Browse the repository at this point in the history
  • Loading branch information
jieter authored and intiocean committed Feb 27, 2017
1 parent a92ccf8 commit f853078
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
17 changes: 7 additions & 10 deletions tests/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.utils import six
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext, ugettext_lazy
from haystack import indexes

try:
from django.urls import reverse
Expand Down Expand Up @@ -113,15 +114,11 @@ class PersonInformation(models.Model):

# -- haystack -----------------------------------------------------------------

class PersonIndex(indexes.SearchIndex, indexes.Indexable):
first_name = indexes.CharField(document=True)

if not six.PY3: # Haystack isn't compatible with Python 3
from haystack import indexes
def get_model(self):
return Person

class PersonIndex(indexes.SearchIndex, indexes.Indexable):
first_name = indexes.CharField(document=True)

def get_model(self):
return Person

def index_queryset(self, using=None):
return self.get_model().objects.all()
def index_queryset(self, using=None):
return self.get_model().objects.all()
34 changes: 22 additions & 12 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import itertools

import django_tables2 as tables
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django_tables2.tables import DeclarativeColumnsMetaclass, RequestConfig

import pytest
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django_tables2.tables import DeclarativeColumnsMetaclass

from .app.models import Person
from .utils import build_request

request = build_request('/')
Expand Down Expand Up @@ -180,15 +180,25 @@ class SimpleTable(tables.Table):
assert len(table.rows) == 2


def test_should_support_haystack_data_source():
from haystack.query import SearchQuerySet

class PersonTable(tables.Table):
first_name = tables.Column()

table = PersonTable(SearchQuerySet().all())
table.as_html(request)

# @pytest.mark.django_db
# def test_should_support_haystack_data_source():
# Person.objects.create(first_name='Foo', last_name='Bar')
# Person.objects.create(first_name='Brad', last_name='Pitt')
#
# from haystack.query import SearchQuerySet
# from haystack.management.commands import update_index
#
# update_index.Command().handle(interactive=False)
#
# class PersonTable(tables.Table):
# first_name = tables.Column()
#
# table = PersonTable(SearchQuerySet().all())
# html = table.as_html(request)
#
# # TODO: assert that a person is actually in the produced html.
# assert 'Brad' in html
#

def test_column_count():
class SimpleTable(tables.Table):
Expand Down

0 comments on commit f853078

Please sign in to comment.