Permalink
Browse files

testsearch added

  • Loading branch information...
1 parent ec281fa commit 7ebd1b87ee1d86407ac11e868c255a7613cedda3 @vandersonmota vandersonmota committed Dec 18, 2009
Showing with 31 additions and 12 deletions.
  1. +2 −1 .gitignore
  2. +0 −1 TODO
  3. +1 −1 chishop/templates/djangopypi/search.html
  4. +2 −2 chishop/templates/djangopypi/search_results.html
  5. +19 −0 djangopypi/tests.py
  6. +7 −7 djangopypi/views.py
View
3 .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
+downloads
View
1 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 :-)
View
2 chishop/templates/djangopypi/search.html
@@ -1,4 +1,4 @@
<form action='search' method='post'>
- <input type="text" name="search_value" id="search_value">
+ <input type="text" name="search_term" id="search_term">
<input type='submit' value=' Search '/>
</form>
View
4 chishop/templates/djangopypi/search_results.html
@@ -3,8 +3,8 @@
{% block bread_crumbs_1 %}&rsaquo;Search{% endblock %}
{% block content %}
- {% ifnotequal search_value ''%}
- <h1>Index of Packages Matching '{{ search_value }}'</h1>
+ {% ifnotequal search_term ''%}
+ <h1>Index of Packages Matching '{{ search_term }}'</h1>
{% else %}
<h1>You need to supply a search term.</h1>
{% endifnotequal %}
View
19 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 @@ def test_weird_post_data(self):
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)
View
14 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)
)

0 comments on commit 7ebd1b8

Please sign in to comment.