self.attrs = attrs or {}
def render(self, value, record, bound_column):
+ if value is None:
+ return self.default
# The following params + if statements create the arguments required to
# pass to Django's reverse() function.
params = {}
# Django's django.utils.module_loading.module_has_submodule is busted
AssertImportHook.disable()
-
from django.conf import settings
# It's important to configure prior to importing the tests, as some of them
ROOT_URLCONF = 'tests.testapp.urls',
)
+from django.test.simple import DjangoTestSuiteRunner
+runner = DjangoTestSuiteRunner()
+runner.setup_databases()
from .core import core
from .templates import templates
from .rows import rows
from .columns import columns
-
everything = Tests([core, templates, models, utils, rows, columns])
# -*- coding: utf-8 -*-
"""Test the core table functionality."""
from attest import Tests, Assert
+from django_attest import TransactionTestContext
from django.test.client import RequestFactory
from django.template import Context, Template
import django_tables as tables
from django_tables import utils, A
+from .testapp.models import Person
-columns = Tests()
+general = Tests()
-
-@columns.test
+@general.test
def sortable():
class SimpleTable(tables.Table):
name = tables.Column()
Assert(SimpleTable([]).columns['name'].sortable) is True
-@columns.test
-def link_column():
+linkcolumn = Tests()
+linkcolumn.context(TransactionTestContext())
+
+@linkcolumn.test
+def unicode():
"""Test LinkColumn"""
# test unicode values + headings
class UnicodeTable(tables.Table):
Assert(u'Chr…s' in html)
Assert(u'DÒble' in html)
+ # Test handling queryset data with a null foreign key
+
+
+@linkcolumn.test
+def null_foreign_key():
+ """
+
+ """
+ class PersonTable(tables.Table):
+ first_name = tables.Column()
+ last_name = tables.Column()
+ occupation = tables.LinkColumn('occupation', args=[A('occupation.pk')])
+
+ Person.objects.create(first_name='bradley', last_name='ayers')
+
+ table = PersonTable(Person.objects.all())
+ table.as_html()
+
+columns = Tests([general, linkcolumn])
+import itertools
from django.conf import settings
-from django.test.simple import DjangoTestSuiteRunner
from django.test.client import RequestFactory
from django.template import Template, Context
-from django.core.paginator import *
import django_tables as tables
-import itertools
-from django_attest import TestContext
+from django_attest import TransactionTestContext
from attest import Tests, Assert
from .testapp.models import Person, Occupation
models = Tests()
-models.context(TestContext())
+models.context(TransactionTestContext())
-runner = DjangoTestSuiteRunner()
-runner.setup_databases()
+class PersonTable(tables.Table):
+ first_name = tables.Column()
+ last_name = tables.Column()
+ occupation = tables.Column()
-@models.context
-def samples():
- class PersonTable(tables.Table):
- first_name = tables.Column()
- last_name = tables.Column()
- occupation = tables.Column()
- # Test data
+@models.test
+def boundrows_iteration():
occupation = Occupation.objects.create(name='Programmer')
Person.objects.create(first_name='Bradley', last_name='Ayers', occupation=occupation)
Person.objects.create(first_name='Chris', last_name='Doble', occupation=occupation)
- yield PersonTable
-
-
-@models.test
-def boundrows_iteration(client, PersonTable):
table = PersonTable(Person.objects.all())
records = [row.record for row in table.rows]
expecteds = Person.objects.all()
class Person(models.Model):
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)
- occupation = models.ForeignKey('Occupation', related_name='people')
+ occupation = models.ForeignKey('Occupation', related_name='people', null=True)
def __unicode__(self):
return self.first_name