Skip to content

Commit

Permalink
Add test trying to reproduce #361: duplicate rows after sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
jieter committed Feb 27, 2017
1 parent 0d30058 commit 3d07c24
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
8 changes: 8 additions & 0 deletions tests/app/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding: utf-8
from __future__ import unicode_literals

from django.conf import settings
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
Expand Down Expand Up @@ -111,8 +112,15 @@ class PersonInformation(models.Model):
)


class Player(models.Model):
person = models.ForeignKey(Person)
created = models.DateTimeField(auto_now_add=True)
score = models.PositiveIntegerField()


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


if not six.PY3: # Haystack isn't compatible with Python 3
from haystack import indexes

Expand Down
33 changes: 32 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# coding: utf-8
from random import randint

import django_tables2 as tables
import pytest
from django.db.models.functions import Length
from django.utils import six
from django_tables2 import RequestConfig

from .app.models import Occupation, Person, PersonProxy
from .app.models import Occupation, Person, PersonProxy, Player
from .utils import build_request

pytestmark = pytest.mark.django_db
Expand Down Expand Up @@ -401,3 +404,31 @@ class Meta:

assert Person.objects.get(pk=person1.pk) == person1
assert Person.objects.get(pk=person2.pk) == person2


def test_issue_361(per_page=5):

bob = Person.objects.create(first_name='Bob', last_name='Builder')
eve = Person.objects.create(first_name='Eve', last_name='Dropper')

for i in range(10):
Player.objects.create(person=bob, score=randint(0, 200))
Player.objects.create(person=eve, score=randint(200, 400))
Player.objects.create(person=bob, score=5)
Player.objects.create(person=eve, score=5)

class UserPlayerTable(tables.Table):
class Meta:
model = Player
fields = ('person.name', 'score',)
order_by = ['score', 'person.first_name']
orderable = False

queryset = Player.objects.filter(score=5)

table = UserPlayerTable(queryset)
RequestConfig(request, paginate={'per_page': per_page}).configure(table)
html = table.as_html(request)

# count the number of rows, subtract one for the header
assert (html.count('<tr') - 1) == per_page

0 comments on commit 3d07c24

Please sign in to comment.