Your message dated Mon, 24 Aug 2015 18:44:22 +0200 with message-id <20150824164422.ga4...@home.ouaza.com> and subject line Re: Bug#779402: [Patch] vendor/debian: Replace the call to the old PTS cgi script for codesearch has caused the Debian Bug report #779402, regarding tracker.debian.org: code search form uses old PTS codesearch.cgi script to be marked as done.
This means that you claim that the problem has been dealt with. If this is not the case it is now your responsibility to reopen the Bug report if necessary, and/or fix the problem forthwith. (NB: If you are a system administrator and have no idea what this message is talking about, this may indicate a serious mail system misconfiguration somewhere. Please contact ow...@bugs.debian.org immediately.) -- 779402: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=779402 Debian Bug Tracking System Contact ow...@bugs.debian.org with problems
--- Begin Message ---Package: tracker.debian.org Severity: normal Tags: newcomer The code search form uses the old PTS codesearch.cgi script. The old PTS will be deleted at some point so the distro-tracker should not rely on it. The code for the old PTS codesearch script is available at [1] and the reference to it is listed in [2]. The task would be to add a new codesearch page that redirects to the correct codesearch URL. This workaround is needed as codesearch does not yet accept the package name as a separate query parameter. This looks like a fairly easy task for someone new to the tracker who knows a bit of django. 1. https://anonscm.debian.org/viewvc/qa/trunk/pts/www/cgi-bin/codesearch.cgi?view=co 2. $ git grep -hC5 codesearch.cgi 'stable', ) SOURCES_URL_TEMPLATE = 'https://sources.debian.net/src/{package}/latest' SEARCH_FORM_TEMPLATE = ( '<form class="code-search-form"' ' action="https://packages.qa.debian.org/cgi-bin/codesearch.cgi"' ' method="get" target="_blank">' '<input type="hidden" name="package" value="{package}">' '<input type="text" name="q" placeholder="search source code">' '</form>') -- bye, pabs https://wiki.debian.org/PaulWise
signature.asc
Description: This is a digitally signed message part
--- End Message ---
--- Begin Message ---On Mon, 24 Aug 2015, Orestis Ioannou wrote: > Added some tests as well, hope they are what you suggested. > > I attached the new patch as well. Thanks, merged your patch and applied some small changes on top of it: commit b328e6b2c97667d6f3c2faa43a938a75bd232dd8 (HEAD -> master, origin/master, origin/HEAD) Author: Raphaël Hertzog <hert...@debian.org> Date: Mon Aug 24 18:33:10 2015 +0200 vendor/debian: small improvements to codesearch view and tests - Split big test into multiple small individual tests - Do not duplicate the URL of the codesearch service - Do not hardcode the location of the CodeSearchView diff --git a/distro_tracker/vendor/debian/tests.py b/distro_tracker/vendor/debian/tests.py index 55d39da..990aa11 100644 --- a/distro_tracker/vendor/debian/tests.py +++ b/distro_tracker/vendor/debian/tests.py @@ -24,7 +24,6 @@ from django.utils import six from django.utils.six.moves import mock from django.utils.encoding import force_bytes from django.utils.functional import curry -from django.utils.http import urlencode from distro_tracker.mail.tests.tests_dispatch \ import DispatchTestHelperMixin, DispatchBaseTest from distro_tracker.accounts.models import User @@ -83,6 +82,7 @@ from distro_tracker.vendor.debian.management.commands\ .tracker_import_old_tags_dump \ import Command as ImportOldTagsCommand from distro_tracker.vendor.debian.sso_auth import DebianSsoUserBackend +from distro_tracker.vendor.debian.views import CodeSearchView from distro_tracker.mail.mail_news import process from email.message import Message @@ -2714,40 +2714,45 @@ class CodeSearchLinksTest(TestCase): self.assertFalse(self.browse_link_in_content(response_content)) self.assertFalse(self.search_form_in_content(response_content)) - def test_code_search_view(self): - """ - Tests that both required parameters are present and not empty and that - urlencode works properly. - """ + def test_code_search_view_missing_query_parameter(self): + """Test codesearch view with missing query parameter""" # missing query paramter response = self.client.get(reverse('dtracker-code-search'), {'package': self.package.name}) self.assertEqual(response.status_code, 400) self.assertIn('Both package and query are required parameters', response.content.decode('utf-8')) - # missing package parameter + + def test_code_search_view_missing_package_parameter(self): + """Test codesearch view with missing package parameter""" response = self.client.get(reverse('dtracker-code-search'), {'query': 'def'}) self.assertEqual(response.status_code, 400) - # empty query + + def test_code_search_view_empty_query(self): + """Test codesearch view with empty query""" response = self.client.get(reverse('dtracker-code-search'), {'package': self.package.name, 'query': ''}) self.assertEqual(response.status_code, 400) self.assertIn('Empty query is not allowed', response.content.decode('utf-8')) - # redirection to codesearch + + def test_code_search_view_redirect_simple(self): + """Test codesearch view redirects properly""" response = self.client.get(reverse('dtracker-code-search'), {'package': self.package.name, 'query': 'def'}) self.assertEqual(response.status_code, 302) - self.assertIn('codesearch.debian', response['Location']) - # verify url encoding - cs = 'https://codesearch.debian.net/search?' - search = 'def' + ' package:' + self.package.name - url = cs + urlencode({'q': search}) - self.assertEqual('https://codesearch.debian.net/search?q=def+package%3A' - 'dummy', url) + self.assertIn(CodeSearchView.BASE_URL, response['Location']) + + def test_code_search_view_urlencode_where_needed(self): + """Test codesearch view urlencode stuff""" + response = self.client.get(reverse('dtracker-code-search'), + {'package': 'g++', + 'query': 'bépo'}) + self.assertEqual(response.status_code, 302) + self.assertIn("q=b%C3%A9po+package%3Ag%2B%2B", response['Location']) class PopconLinkTest(TestCase): diff --git a/distro_tracker/vendor/debian/tracker_panels.py b/distro_tracker/vendor/debian/tracker_panels.py index cdfb400..49ba680 100644 --- a/distro_tracker/vendor/debian/tracker_panels.py +++ b/distro_tracker/vendor/debian/tracker_panels.py @@ -11,9 +11,12 @@ # except according to the terms contained in the LICENSE file. from __future__ import unicode_literals + +from django.core.urlresolvers import reverse from django.utils.safestring import mark_safe from django.utils.functional import cached_property from django.utils.http import urlencode, urlquote + from distro_tracker.core.utils import get_or_none from distro_tracker.core.models import Repository from distro_tracker.core.models import SourcePackageName @@ -132,7 +135,7 @@ class SourceCodeSearchLinks(LinksPanel.ItemProvider): SOURCES_URL_TEMPLATE = 'https://sources.debian.net/src/{package}/{suite}/' SEARCH_FORM_TEMPLATE = ( '<form class="code-search-form"' - ' action="/codesearch/"' + ' action="' + reverse('dtracker-code-search') + '"' ' method="get" target="_blank">' '<input type="hidden" name="package" value="{package}">' '<input type="text" name="query" placeholder="search source code">' diff --git a/distro_tracker/vendor/debian/views.py b/distro_tracker/vendor/debian/views.py index aed16f2..b662376 100644 --- a/distro_tracker/vendor/debian/views.py +++ b/distro_tracker/vendor/debian/views.py @@ -7,7 +7,7 @@ # distribution and at http://deb.li/DTLicense. No part of Distro Tracker, # including this file, may be copied, modified, propagated, or distributed # except according to the terms contained in the LICENSE file. -"""Views for the :mod:`distro_tracker.vendor` app.""" +"""Views for the :mod:`distro_tracker.vendor.debian` app.""" from __future__ import unicode_literals from django.utils.http import urlencode @@ -18,16 +18,16 @@ from django.shortcuts import redirect class CodeSearchView(View): + BASE_URL = 'https://codesearch.debian.net/search' + def get(self, request): if 'query' not in request.GET or 'package' not in request.GET: return HttpResponseBadRequest('Both package and query are required ' 'parameters') - if request.GET.get('query') == "": - return HttpResponseBadRequest('Empty query is not allowed') q = request.GET.get('query') + if q == "": + return HttpResponseBadRequest('Empty query is not allowed') package = request.GET.get('package') - cs = 'https://codesearch.debian.net/search?' search = q + ' package:' + package - - url = cs + urlencode({'q': search}) + url = self.BASE_URL + '?' + urlencode({'q': search}) return redirect(url) Cheers, -- Raphaël Hertzog ◈ Debian Developer Support Debian LTS: http://www.freexian.com/services/debian-lts.html Learn to master Debian: http://debian-handbook.info/get/
--- End Message ---