def test_multiple_filters_returned_from_querydict(self): search_term = "Amet" afrikaans = LanguageFactory(title="Afrikaans") afrikaans.save() thailand = CountryFactory(title="Country") thailand.save() scotus = TopicFactory(title="SCOTUS") scotus.save() querydict = QueryDict( 'search={}&language={}&topic={}&country={}'.format( search_term, afrikaans.id, scotus.id, thailand.id)) filters = self.directory.filters_from_querydict(querydict) self.assertEqual(filters['title__icontains'], search_term) self.assertEqual(filters['topics'], scotus) self.assertEqual(filters['countries'], thailand) self.assertEqual(filters['languages'], afrikaans)
def setUp(self): self.directory = DirectoryPageFactory() # set up languages spanish = LanguageFactory(title='Spanish') chinese = LanguageFactory(title='Chinese') spanish.save() chinese.save() # set up instances that are children of the directory and have those languages self.spanish_instance = DirectoryEntryFactory(parent=self.directory) self.spanish_instance.languages.add(spanish) self.spanish_instance.save() self.chinese_instance = DirectoryEntryFactory(parent=self.directory) self.chinese_instance.languages.add(chinese) self.chinese_instance.save() self.lang_filter = {'languages': spanish}
def setUp(self): self.directory = DirectoryPageFactory() # set up languages spanish = LanguageFactory(title='Spanish') chinese = LanguageFactory(title='Chinese') spanish.save() chinese.save() # set up countries mexico = CountryFactory(title='Mexico') azerbaijan = CountryFactory(title='Azerbaijan') mexico.save() azerbaijan.save() # set up topics pf = TopicFactory(title='Press Freedom') irs = TopicFactory(title='IRS') pf.save() irs.save() # set up instances that are children of the directory and have multiple categories self.sp_mx_instance = DirectoryEntryFactory(parent=self.directory) self.sp_mx_instance.languages.add(spanish) self.sp_mx_instance.countries.add(mexico) self.sp_mx_instance.save() self.az_pf_instance = DirectoryEntryFactory(parent=self.directory) self.az_pf_instance.countries.add(azerbaijan) self.az_pf_instance.topics.add(pf) self.az_pf_instance.save() self.other_instance = DirectoryEntryFactory(parent=self.directory) self.other_instance.languages.add(spanish) self.other_instance.topics.add(pf) self.other_instance.save() # filters self.lang_country_filter = { 'languages': spanish, 'countries': mexico } self.country_topic_filter = { 'countries': azerbaijan, 'topics': pf }
def test_correct_language_returned_from_querydict(self): georgian = LanguageFactory(title="Georgian") georgian.save() querydict = QueryDict('language={}'.format(georgian.id)) filters = self.directory.filters_from_querydict(querydict) self.assertEqual(filters['languages'], georgian)