Skip to content
This repository
Browse code

testsearch added

  • Loading branch information...
commit 7ebd1b87ee1d86407ac11e868c255a7613cedda3 1 parent ec281fa
Vanderson Mota dos Santos vandersonmota authored
3  .gitignore
@@ -5,6 +5,7 @@
5 5 *.sqlite-journal
6 6 settings_local.py
7 7 .*.sw[po]
  8 +*.kpf
8 9 dist/
9 10 *.egg-info
10 11 doc/__build/*
@@ -14,4 +15,4 @@ parts
14 15 eggs
15 16 bin
16 17 developer-eggs
17   -downloads
  18 +downloads
1  TODO
@@ -11,7 +11,6 @@ PyPI feature replication
11 11 I'm not sure what the difference between a co-owner and maintainer is,
12 12 maybe it's just a label.
13 13 * Package author admin interface (submit, edit, view)
14   -* Search
15 14 * Documentation upload
16 15 * Ratings
17 16 * Random Monty Python quotes :-)
2  chishop/templates/djangopypi/search.html
... ... @@ -1,4 +1,4 @@
1 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 3 <input type='submit' value=' Search '/>
4 4 </form>
4 chishop/templates/djangopypi/search_results.html
@@ -3,8 +3,8 @@
3 3 {% block bread_crumbs_1 %}&rsaquo;Search{% endblock %}
4 4
5 5 {% block content %}
6   - {% ifnotequal search_value ''%}
7   - <h1>Index of Packages Matching '{{ search_value }}'</h1>
  6 + {% ifnotequal search_term ''%}
  7 + <h1>Index of Packages Matching '{{ search_term }}'</h1>
8 8 {% else %}
9 9 <h1>You need to supply a search term.</h1>
10 10 {% endifnotequal %}
19 djangopypi/tests.py
... ... @@ -1,6 +1,10 @@
1 1 import unittest
2 2 import StringIO
3 3 from djangopypi.views import parse_distutils_request
  4 +from djangopypi.models import Project, Classifier
  5 +from django.test.client import Client
  6 +from django.core.urlresolvers import reverse
  7 +from django.contrib.auth.models import User
4 8
5 9 def create_post_data(action):
6 10 data = {
@@ -88,3 +92,18 @@ def test_weird_post_data(self):
88 92 self.assertEquals(data[key], post.getlist(key))
89 93 else:
90 94 self.assertEquals(post[key], data[key])
  95 +
  96 +class 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)
14 djangopypi/views.py
@@ -230,27 +230,27 @@ def show_version(request, dist_name, version,
230 230 return render_to_response(template_name, context_instance=context)
231 231
232 232 def search(request):
233   - search_value = ''
  233 + search_term = ''
234 234 if request.method == 'POST':
235   - search_value = request.POST.get('search_value')
236   - if search_value != '':
237   - dists = Project.objects.filter(Q(name__contains=search_value) | Q(summary__contains=search_value))
  235 + search_term = request.POST.get('search_term')
  236 + if search_term != '':
  237 + dists = Project.objects.filter(Q(name__contains=search_term) | Q(summary__contains=search_term))
238 238 return render_to_response(
239 239 'djangopypi/search_results.html',
240   - {'dists':dists,'search_value':search_value},
  240 + {'dists':dists,'search_term':search_term},
241 241 context_instance = RequestContext(request)
242 242 )
243 243 else:
244 244 dists = Project.objects.all()
245 245 return render_to_response(
246 246 'djangopypi/search_results.html',
247   - {'search_value':search_value},
  247 + {'search_term':search_term},
248 248 context_instance = RequestContext(request)
249 249 )
250 250 else:
251 251 dists = Project.objects.all()
252 252 return render_to_response(
253 253 'djangopypi/search_results.html',
254   - {'search_value':search_value},
  254 + {'search_term':search_term},
255 255 context_instance = RequestContext(request)
256 256 )

0 comments on commit 7ebd1b8

Please sign in to comment.
Something went wrong with that request. Please try again.