aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvandersonmota <vanderson.mota@gmail.com>2009-12-18 17:59:57 -0200
committervandersonmota <vanderson.mota@gmail.com>2009-12-18 17:59:57 -0200
commit7ebd1b87ee1d86407ac11e868c255a7613cedda3 (patch)
tree5ea09b14d328d2b668de703e0e4c430f75db344a
parentec281fafcaea5348675a205fbd399ad5b19a2180 (diff)
downloadchishop-7ebd1b87ee1d86407ac11e868c255a7613cedda3.tar.bz2
chishop-7ebd1b87ee1d86407ac11e868c255a7613cedda3.tar.xz
chishop-7ebd1b87ee1d86407ac11e868c255a7613cedda3.zip
testsearch added
-rw-r--r--.gitignore3
-rw-r--r--TODO1
-rw-r--r--chishop/templates/djangopypi/search.html2
-rw-r--r--chishop/templates/djangopypi/search_results.html4
-rw-r--r--djangopypi/tests.py19
-rw-r--r--djangopypi/views.py14
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 @@
5*.sqlite-journal 5*.sqlite-journal
6settings_local.py 6settings_local.py
7.*.sw[po] 7.*.sw[po]
8*.kpf
8dist/ 9dist/
9*.egg-info 10*.egg-info
10doc/__build/* 11doc/__build/*
@@ -14,4 +15,4 @@ parts
14eggs 15eggs
15bin 16bin
16developer-eggs 17developer-eggs
17downloads \ No newline at end of file 18downloads
diff --git a/TODO b/TODO
index 5d57eb7..f8ed064 100644
--- a/TODO
+++ b/TODO
@@ -11,7 +11,6 @@ PyPI feature replication
11 I'm not sure what the difference between a co-owner and maintainer is, 11 I'm not sure what the difference between a co-owner and maintainer is,
12 maybe it's just a label. 12 maybe it's just a label.
13* Package author admin interface (submit, edit, view) 13* Package author admin interface (submit, edit, view)
14* Search
15* Documentation upload 14* Documentation upload
16* Ratings 15* Ratings
17* Random Monty Python quotes :-) 16* 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 @@
1<form action='search' method='post'> 1<form action='search' method='post'>
2 <input type="text" name="search_value" id="search_value"> 2 <input type="text" name="search_term" id="search_term">
3 <input type='submit' value=' Search '/> 3 <input type='submit' value=' Search '/>
4</form> \ No newline at end of file 4</form> \ 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 @@
3{% block bread_crumbs_1 %}&rsaquo;Search{% endblock %} 3{% block bread_crumbs_1 %}&rsaquo;Search{% endblock %}
4 4
5{% block content %} 5{% block content %}
6 {% ifnotequal search_value ''%} 6 {% ifnotequal search_term ''%}
7 <h1>Index of Packages Matching '{{ search_value }}'</h1> 7 <h1>Index of Packages Matching '{{ search_term }}'</h1>
8 {% else %} 8 {% else %}
9 <h1>You need to supply a search term.</h1> 9 <h1>You need to supply a search term.</h1>
10 {% endifnotequal %} 10 {% 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 @@
1import unittest 1import unittest
2import StringIO 2import StringIO
3from djangopypi.views import parse_distutils_request 3from djangopypi.views import parse_distutils_request
4from djangopypi.models import Project, Classifier
5from django.test.client import Client
6from django.core.urlresolvers import reverse
7from django.contrib.auth.models import User
4 8
5def create_post_data(action): 9def create_post_data(action):
6 data = { 10 data = {
@@ -88,3 +92,18 @@ class TestParseWeirdPostData(unittest.TestCase):
88 self.assertEquals(data[key], post.getlist(key)) 92 self.assertEquals(data[key], post.getlist(key))
89 else: 93 else:
90 self.assertEquals(post[key], data[key]) 94 self.assertEquals(post[key], data[key])
95
96class TestSearch(unittest.TestCase):
97
98 def setUp(self):
99 data = create_post_data("submit")
100 dummy_user = User.objects.create(username='krill', password='12345',
101 email='krill@opera.com')
102 Project.objects.create(name=data['name'], license=data['license'],
103 summary=data["summary"], owner=dummy_user)
104
105
106 def testSearchForPackage(self):
107 client = Client()
108 response = client.post(reverse('djangopypi-search'), {'search_term': 'foo'})
109 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,
230 return render_to_response(template_name, context_instance=context) 230 return render_to_response(template_name, context_instance=context)
231 231
232def search(request): 232def search(request):
233 search_value = '' 233 search_term = ''
234 if request.method == 'POST': 234 if request.method == 'POST':
235 search_value = request.POST.get('search_value') 235 search_term = request.POST.get('search_term')
236 if search_value != '': 236 if search_term != '':
237 dists = Project.objects.filter(Q(name__contains=search_value) | Q(summary__contains=search_value)) 237 dists = Project.objects.filter(Q(name__contains=search_term) | Q(summary__contains=search_term))
238 return render_to_response( 238 return render_to_response(
239 'djangopypi/search_results.html', 239 'djangopypi/search_results.html',
240 {'dists':dists,'search_value':search_value}, 240 {'dists':dists,'search_term':search_term},
241 context_instance = RequestContext(request) 241 context_instance = RequestContext(request)
242 ) 242 )
243 else: 243 else:
244 dists = Project.objects.all() 244 dists = Project.objects.all()
245 return render_to_response( 245 return render_to_response(
246 'djangopypi/search_results.html', 246 'djangopypi/search_results.html',
247 {'search_value':search_value}, 247 {'search_term':search_term},
248 context_instance = RequestContext(request) 248 context_instance = RequestContext(request)
249 ) 249 )
250 else: 250 else:
251 dists = Project.objects.all() 251 dists = Project.objects.all()
252 return render_to_response( 252 return render_to_response(
253 'djangopypi/search_results.html', 253 'djangopypi/search_results.html',
254 {'search_value':search_value}, 254 {'search_term':search_term},
255 context_instance = RequestContext(request) 255 context_instance = RequestContext(request)
256 ) \ No newline at end of file 256 ) \ No newline at end of file