Fixup tests to include Meta.fields

This commit is contained in:
Ryan P Kilby 2016-11-06 19:24:52 -05:00
parent 490aa93548
commit 4b5bc1ad78
3 changed files with 19 additions and 11 deletions

View File

@ -39,6 +39,7 @@ class StrictnessTests(TestCase):
class F(FilterSet):
class Meta:
model = User
fields = []
def test_settings_default(self):
self.assertEqual(self.F().strict, STRICTNESS.RETURN_NO_RESULTS)

View File

@ -208,6 +208,7 @@ class ChoiceFilterTests(TestCase):
class Meta:
model = Article
fields = ['author']
# sanity check to make sure the filter is setup correctly
f = F({'author': '1'})

View File

@ -322,20 +322,21 @@ class FilterSetClassCreationTests(TestCase):
['title', 'price', 'average_rating'])
def test_model_no_fields_or_exclude(self):
with self.assertRaises(AssertionError) as excinfo:
class F(FilterSet):
class Meta:
model = Book
self.assertIn(
"Setting 'Meta.model' without either 'Meta.fields' or 'Meta.exclude'",
str(excinfo.exception)
)
def test_model_fields_empty(self):
class F(FilterSet):
class Meta:
model = Book
self.assertEqual(len(F.declared_filters), 0)
self.assertEqual(len(F.base_filters), 0)
self.assertListEqual(list(F.base_filters), [])
def test_model_exclude_is_none(self):
# equivalent to unset fields/exclude
class F(FilterSet):
class Meta:
model = Book
exclude = None
fields = []
self.assertEqual(len(F.declared_filters), 0)
self.assertEqual(len(F.base_filters), 0)
@ -612,6 +613,7 @@ class FilterSetStrictnessTests(TestCase):
class F(FilterSet):
class Meta:
model = User
fields = []
# Ensure default is not IGNORE
self.assertEqual(F().strict, STRICTNESS.RETURN_NO_RESULTS)
@ -624,6 +626,7 @@ class FilterSetStrictnessTests(TestCase):
class F(FilterSet):
class Meta:
model = User
fields = []
strict = STRICTNESS.IGNORE
self.assertEqual(F().strict, STRICTNESS.IGNORE)
@ -632,6 +635,7 @@ class FilterSetStrictnessTests(TestCase):
class F(FilterSet):
class Meta:
model = User
fields = []
strict = STRICTNESS.IGNORE
strict = STRICTNESS.RAISE_VALIDATION_ERROR
@ -641,6 +645,7 @@ class FilterSetStrictnessTests(TestCase):
class F(FilterSet):
class Meta:
model = User
fields = []
self.assertEqual(F(strict=False).strict, STRICTNESS.IGNORE)
@ -770,6 +775,7 @@ class FilterMethodTests(TestCase):
class Meta:
model = User
fields = []
def filter_f(inner_self, qs, name, value):
self.assertIsInstance(inner_self, F)