Exemplo n.º 1
0
def autocomplete(request):
    """Return results for the autocomplete feature on the search page."""
    query = request.GET.get('query', None)
    if not query:
        return HttpResponseBadRequest()

    results = {
        'by_title': autocomplete_suggestion(query, 'title'),
        'by_description': autocomplete_suggestion(query, 'description'),
        'by_author': autocomplete_suggestion(query,
                                             'user__userprofile__full_name'),
    }
    return JSONResponse(results)
Exemplo n.º 2
0
 def test_result_found(self):
     """
     If a video is found matching the query, return the value of the field
     we searched for on that video.
     """
     suggestion = autocomplete_suggestion("fo", "title")
     eq_(suggestion, "foo")  # Title of the first result.
     self.mock_search_videos.assert_called_with(query="fo", fields=("title",))
Exemplo n.º 3
0
 def test_result_found(self):
     """
     If a video is found matching the query, return the value of the field
     we searched for on that video.
     """
     suggestion = autocomplete_suggestion('fo', 'title')
     eq_(suggestion, 'foo')  # Title of the first result.
     self.mock_search_videos.assert_called_with(query='fo',
                                                fields=('title', ))
Exemplo n.º 4
0
def autocomplete(request):
    """Return results for the autocomplete feature on the search page."""
    query = request.GET.get('query', '').strip()
    if not query:
        return HttpResponseBadRequest()

    results = {}
    for key, fields in AUTOCOMPLETE_FIELDS.items():
        results['by_{0}'.format(key)] = autocomplete_suggestion(query, fields)

    return JSONResponse(results)
Exemplo n.º 5
0
def autocomplete(request):
    """Return results for the autocomplete feature on the search page."""
    query = request.GET.get('query', '').strip()
    if not query:
        return HttpResponseBadRequest()

    results = {}
    for key, fields in AUTOCOMPLETE_FIELDS.items():
        results['by_{0}'.format(key)] = autocomplete_suggestion(query, fields)

    return JSONResponse(results)
Exemplo n.º 6
0
    def test_result_found(self):
        """
        If a video is found matching the query, return the value of the field
        we searched for on that video.
        """
        self.mock_search_videos.return_value = Video.objects.filter(
            id__in=[self.v1.id, self.v2.id]).order_by('id')

        suggestion = autocomplete_suggestion('fo', ('title',))
        eq_(suggestion, 'foo')  # Title of the first result.
        self.mock_search_videos.assert_called_with(query='fo',
                                                   fields=('title',))
Exemplo n.º 7
0
    def test_multiple_fields(self):
        """
        If multiple fields are given, search them in order until a match is
        found.
        """
        def func(*args, **kwargs):
            """Returns None once, then returns a queryset with v1."""
            if func.return_none:
                func.return_none = False
                return None
            return Video.objects.filter(id=self.v1.id)
        func.return_none = True
        self.mock_search_videos.side_effect = func

        # Ensure that it returns the value of description, as the first search
        # for title should fail.
        suggestion = autocomplete_suggestion('fo', ('title', 'description'))
        eq_(suggestion, 'bar')
Exemplo n.º 8
0
 def test_no_results(self):
     """If no videos are matched, return None."""
     self.mock_search_videos.return_value = Video.objects.filter(id=9999999)
     eq_(autocomplete_suggestion("fo", "title"), None)
Exemplo n.º 9
0
 def test_no_results(self):
     """If no videos are matched, return None."""
     self.mock_search_videos.return_value = Video.objects.filter(id=9999999)
     eq_(autocomplete_suggestion('fo', 'title'), None)