def test_paginated_search(self): instance = AutocompletePerson(page_size=3) # The raw queryset is not paginated. qs = instance.get_queryset() conditions = instance.get_queryset_filters(query="ali") items = qs.filter(conditions) self.assertEqual(items.count(), 4) # The "items" method returns paginated objects items = instance.items(query="ali") self.assertEqual(len(items), 3)
def test_selected(self): instance = AutocompletePerson() result = instance.selected([]) self.assertEqual(result, []) result = instance.selected([1]) self.assertEqual(result, [ (text('1'), text('Alice Iñtërnâtiônàlizætiøn'))] ) result = instance.selected(['2']) self.assertEqual(result, [(text('2'), text('Alice Inchains'))]) result = instance.selected(['MEUH']) self.assertEqual(result, [])
def test_get_page_size(self): instance = AutocompletePerson() self.assertEqual( instance.get_page_size(), 15) # over the limit params, back to default instance = AutocompletePerson(page_size=1000) self.assertEqual( instance.get_page_size(), 15) instance = AutocompletePerson(page_size=1) self.assertEqual( instance.get_page_size(), 15) # Reasonable overriding instance = AutocompletePerson(page_size=7) self.assertEqual(instance.get_page_size(), 7)
def test_final_queryset_person(self): instance = AutocompletePerson() # No items() called, None self.assertTrue(instance.final_queryset is None) # Called items(), empty queryset items = instance.items() self.assertFalse(instance.final_queryset is None) self.assertEqual(instance.final_queryset.count(), 0) # Regular search, normal queryset items = instance.items(query="ali") self.assertEqual(len(items), 4) self.assertTrue(instance.final_queryset) self.assertEqual(instance.final_queryset.count(), 4) # Paginated queryset instance = AutocompletePerson(page_size=2) items = instance.items(query="ali") self.assertEqual(len(items), 2) self.assertTrue(instance.final_queryset) self.assertEqual(instance.final_queryset.count(), 2) self.assertEqual(instance.final_raw_queryset.count(), 4)
def test_items(self): instance = AutocompletePerson() items = instance.items() self.assertEqual(len(items), 0) # Limit is "2" items = instance.items(query="a") self.assertEqual(len(items), 0) # Should be okay now items = instance.items(query="ali") self.assertEqual(len(items), 4) items = instance.items(query="bob") self.assertEqual(len(items), 1) items = instance.items(query="zzzzz") self.assertEqual(len(items), 0)
def test_selected(self): instance = AutocompletePerson() result = instance.selected([]) self.assertEqual(result, []) result = instance.selected([1]) self.assertEqual(result, [(text('1'), text('Alice Iñtërnâtiônàlizætiøn'))]) result = instance.selected(['2']) self.assertEqual(result, [(text('2'), text('Alice Inchains'))]) result = instance.selected(['MEUH']) self.assertEqual(result, [])
def test_get_model(self): instance = AutocompletePerson() self.assertEqual(Person, instance.get_model()) instance = AutocompletePersonQueryset() self.assertEqual(Person, instance.get_model())
def test_queryset_by_model(self): instance = AutocompletePerson() items = instance.get_queryset() self.assertEqual(items.count(), 6)
def test_does_not_require(self): instance = AutocompletePerson() self.assertTrue(instance.user is None)
def test_get_page_size(self): instance = AutocompletePerson() self.assertEqual(instance.get_page_size(), 15) # over the limit params, back to default instance = AutocompletePerson(page_size=1000) self.assertEqual(instance.get_page_size(), 15) instance = AutocompletePerson(page_size=1) self.assertEqual(instance.get_page_size(), 15) # Reasonable overriding instance = AutocompletePerson(page_size=7) self.assertEqual(instance.get_page_size(), 7)
def test_queryset_by_model(self): instance = AutocompletePerson() items = instance.get_queryset() self.assertEqual(items.count(), 5)