From 7ebd1b87ee1d86407ac11e868c255a7613cedda3 Mon Sep 17 00:00:00 2001 From: vandersonmota Date: Fri, 18 Dec 2009 17:59:57 -0200 Subject: testsearch added --- .gitignore | 3 ++- TODO | 1 - chishop/templates/djangopypi/search.html | 2 +- chishop/templates/djangopypi/search_results.html | 4 ++-- djangopypi/tests.py | 19 +++++++++++++++++++ djangopypi/views.py | 14 +++++++------- 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index d8e3b0d..b0a673f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.sqlite-journal settings_local.py .*.sw[po] +*.kpf dist/ *.egg-info doc/__build/* @@ -14,4 +15,4 @@ parts eggs bin developer-eggs -downloads \ No newline at end of file +downloads diff --git a/TODO b/TODO index 5d57eb7..f8ed064 100644 --- a/TODO +++ b/TODO @@ -11,7 +11,6 @@ PyPI feature replication I'm not sure what the difference between a co-owner and maintainer is, maybe it's just a label. * Package author admin interface (submit, edit, view) -* Search * Documentation upload * Ratings * Random Monty Python quotes :-) diff --git a/chishop/templates/djangopypi/search.html b/chishop/templates/djangopypi/search.html index a5c882c..8269508 100644 --- a/chishop/templates/djangopypi/search.html +++ b/chishop/templates/djangopypi/search.html @@ -1,4 +1,4 @@
- +
\ No newline at end of file diff --git a/chishop/templates/djangopypi/search_results.html b/chishop/templates/djangopypi/search_results.html index c2139ad..dccf61f 100644 --- a/chishop/templates/djangopypi/search_results.html +++ b/chishop/templates/djangopypi/search_results.html @@ -3,8 +3,8 @@ {% block bread_crumbs_1 %}›Search{% endblock %} {% block content %} - {% ifnotequal search_value ''%} -

Index of Packages Matching '{{ search_value }}'

+ {% ifnotequal search_term ''%} +

Index of Packages Matching '{{ search_term }}'

{% else %}

You need to supply a search term.

{% endifnotequal %} diff --git a/djangopypi/tests.py b/djangopypi/tests.py index 2d8c305..4da4122 100644 --- a/djangopypi/tests.py +++ b/djangopypi/tests.py @@ -1,6 +1,10 @@ import unittest import StringIO from djangopypi.views import parse_distutils_request +from djangopypi.models import Project, Classifier +from django.test.client import Client +from django.core.urlresolvers import reverse +from django.contrib.auth.models import User def create_post_data(action): data = { @@ -88,3 +92,18 @@ class TestParseWeirdPostData(unittest.TestCase): self.assertEquals(data[key], post.getlist(key)) else: self.assertEquals(post[key], data[key]) + +class TestSearch(unittest.TestCase): + + def setUp(self): + data = create_post_data("submit") + dummy_user = User.objects.create(username='krill', password='12345', + email='krill@opera.com') + Project.objects.create(name=data['name'], license=data['license'], + summary=data["summary"], owner=dummy_user) + + + def testSearchForPackage(self): + client = Client() + response = client.post(reverse('djangopypi-search'), {'search_term': 'foo'}) + self.assertTrue("The quick brown fox jumps over the lazy dog." in response.content) diff --git a/djangopypi/views.py b/djangopypi/views.py index 0ac6dbc..7e2d0dc 100644 --- a/djangopypi/views.py +++ b/djangopypi/views.py @@ -230,27 +230,27 @@ def show_version(request, dist_name, version, return render_to_response(template_name, context_instance=context) def search(request): - search_value = '' + search_term = '' if request.method == 'POST': - search_value = request.POST.get('search_value') - if search_value != '': - dists = Project.objects.filter(Q(name__contains=search_value) | Q(summary__contains=search_value)) + search_term = request.POST.get('search_term') + if search_term != '': + dists = Project.objects.filter(Q(name__contains=search_term) | Q(summary__contains=search_term)) return render_to_response( 'djangopypi/search_results.html', - {'dists':dists,'search_value':search_value}, + {'dists':dists,'search_term':search_term}, context_instance = RequestContext(request) ) else: dists = Project.objects.all() return render_to_response( 'djangopypi/search_results.html', - {'search_value':search_value}, + {'search_term':search_term}, context_instance = RequestContext(request) ) else: dists = Project.objects.all() return render_to_response( 'djangopypi/search_results.html', - {'search_value':search_value}, + {'search_term':search_term}, context_instance = RequestContext(request) ) \ No newline at end of file -- cgit v1.2.3