def test_normalize_choices(self): # We shouldn't get links for non-nullable fields when there is only one choice. # Make sure there are no other books in 1975 clark = Author.objects.get(name='Arthur C. Clarke') qs = Book.objects.filter(date_published__year=1861) self.assertEqual(len(qs), 1) filter1 = ChoicesFilter('binding', Book, MultiValueDict()) choices1 = filter1.get_choices(qs) self.assertEqual(len(choices1), 1) self.assertEqual(choices1[0].link_type, FILTER_DISPLAY, choices1) filter2 = ForeignKeyFilter('genre', Book, MultiValueDict()) choices2 = filter2.get_choices(qs) self.assertEqual(len(choices2), 1) self.assertEqual(choices2[0].link_type, FILTER_DISPLAY, choices2)
def test_choices_filter(self): """ Tests for ChoicesFilter """ filter1 = ChoicesFilter('binding', Book, MultiValueDict()) qs = Book.objects.all() choices = filter1.get_choices(qs) # Check: # - order is correct. # - all values present (guaranteed by fixture data) # - choice display value is used. binding_choices_db = [b[0] for b in BINDING_CHOICES] binding_choices_display = [b[1] for b in BINDING_CHOICES] self.assertEqual([c.label for c in choices], binding_choices_display) # Check choice db value in params for c in choices: self.assertTrue(list(c.params.values())[0] in binding_choices_db)
def test_choices_filter(self): """ Tests for ChoicesFilter """ filter1 = ChoicesFilter('binding', Book, MultiValueDict()) qs = Book.objects.all() choices = filter1.get_choices(qs) # Check: # - order is correct. # - all values present (guaranteed by fixture data) # - choice display value is used. binding_choices_db = [b[0] for b in BINDING_CHOICES] binding_choices_display = [b[1] for b in BINDING_CHOICES] self.assertEqual([c.label for c in choices], binding_choices_display) # Check choice db value in params for c in choices: self.assertTrue(c.params.values()[0] in binding_choices_db)