コード例 #1
0
    def test_get_result_queryset(self):
        autocomplete = BaseAutocomplete(model=User, search_fields=['username'])
        request = request_factory.get('/')
        autocomplete.request = request
        self.assertEquals(
            unicode(User.objects.none().query),
            unicode(autocomplete.get_result_queryset().query)
        )

        autocomplete = BaseAutocomplete(model=User, search_fields=['username'])
        request = request_factory.get('/', {'q': 'foo'})
        autocomplete.request = request
        qs = User.objects.filter(username__startswith='foo')
        self.assertEquals(
            unicode(qs.query),
            unicode(autocomplete.get_result_queryset().query)
        )

        autocomplete = BaseAutocomplete(model=User, search_fields=['username'], limit=10)
        request = request_factory.get('/', {'q': 'foo'})
        autocomplete.request = request
        qs = User.objects.filter(username__startswith='foo')[:10]
        self.assertEquals(
            unicode(qs.query),
            unicode(autocomplete.get_result_queryset().query)
        )
コード例 #2
0
 def test_get_queryset(self):
     autocomplete = BaseAutocomplete()
     self.assertRaises(ImproperlyConfigured, autocomplete.get_queryset)
     autocomplete = BaseAutocomplete(model=User)
     self.assertEquals(
         unicode(User.objects.all().query),
         unicode(autocomplete.get_queryset().query)
     )
     autocomplete = BaseAutocomplete(queryset=User.objects.filter(is_active=True))
     self.assertEquals(
         unicode(User.objects.filter(is_active=True).query),
         unicode(autocomplete.get_queryset().query)
     )
コード例 #3
0
 def test_get_mimetype(self):
     autocomplete = BaseAutocomplete()
     self.assertEquals('text/javascript', autocomplete.get_mimetype())
     autocomplete = BaseAutocomplete(mimetype='application/json')
     self.assertEquals('application/json', autocomplete.get_mimetype())
     class TestAutocomplete(BaseAutocomplete):
         mimetype = 'application/json'
     autocomplete = TestAutocomplete()
     self.assertEquals('application/json', autocomplete.get_mimetype())
コード例 #4
0
 def test_get_limit(self):
     autocomplete = BaseAutocomplete()
     self.assertEquals(None, autocomplete.get_limit())
     autocomplete = BaseAutocomplete(limit=100)
     self.assertEquals(100, autocomplete.get_limit())
     class TestAutocomplete(BaseAutocomplete):
         limit = 130
     autocomplete = TestAutocomplete()
     self.assertEquals(130, autocomplete.get_limit())
コード例 #5
0
 def test_get_lookup(self):
     autocomplete = BaseAutocomplete()
     self.assertEquals('startswith', autocomplete.get_lookup(None))
     autocomplete = BaseAutocomplete(lookup='istartswith')
     self.assertEquals('istartswith', autocomplete.get_lookup(None))
     class TestAutocomplete(BaseAutocomplete):
         def get_lookup(self, field):
             if field == 'username':
                 return 'icontains'
             return self.lookup
     autocomplete = TestAutocomplete()
     self.assertEquals('icontains', autocomplete.get_lookup('username'))
     self.assertEquals('startswith', autocomplete.get_lookup('email'))
コード例 #6
0
 def test_as_view(self):
     autocomplete = BaseAutocomplete()
     self.assertRaises(AttributeError, getattr, autocomplete, "as_view")
     view = BaseAutocomplete.as_view()
コード例 #7
0
 def test_is_authorized(self):
     autocomplete = BaseAutocomplete()
     self.assertEquals(True, autocomplete.is_authorized())
コード例 #8
0
 def test_get_search_fields(self):
     autocomplete = BaseAutocomplete()
     self.assertRaises(ImproperlyConfigured, autocomplete.get_search_fields)
     autocomplete = BaseAutocomplete(search_fields=['username'])
     self.assertEquals(['username'], autocomplete.get_search_fields())