From c060d05310cbf15b47850b3f2f1c311067225eca Mon Sep 17 00:00:00 2001 From: Ross Jones Date: Sat, 6 Jul 2013 13:57:02 +0100 Subject: [PATCH] Fixes #53 by using a Q obj to query for tag or title, instead of potentially matching both. --- checklisthq/main/tests.py | 38 ++++++++++++++++++++++++++++++++++++++ checklisthq/main/views.py | 12 ++++++++---- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/checklisthq/main/tests.py b/checklisthq/main/tests.py index 9a78599..b699272 100644 --- a/checklisthq/main/tests.py +++ b/checklisthq/main/tests.py @@ -3,6 +3,9 @@ """ import unittest +from django.contrib.auth.models import User +from django.test.client import Client + from forms import ChecklistForm from models import Checklist @@ -18,3 +21,38 @@ def test_META(self): self.assertEqual(Checklist, ChecklistForm.Meta.model) self.assertEqual(('title', 'content', 'tags'), ChecklistForm.Meta.fields) + +class TestSearch(unittest.TestCase): + """ + Ensures the correct behaviour of the form used for editing checklists. + """ + + def setUp(self): + self.user,_ = User.objects.get_or_create(username="test_user") + self.cl1 = Checklist(title='foo', owner=self.user, content='bar') + self.cl1.save() + self.cl1.tags.add("foo") + + self.cl2 = Checklist(title='bar', owner=self.user, content='vavavoom') + self.cl2.save() + self.cl2.tags.add("foo") + + self.cl2 = Checklist(title='bar', owner=self.user, content='vavavoom') + self.cl2.save() + self.cl2.tags.add("bar") + + + def test_duplicates(self): + """ + Test for issue #53. + Search Function returns two instances of the same checklist if + a term is used both in the title and in the tag. + """ + c = Client() + response = c.get('/search', {'query': 'foo'}) + # Just count TRs for now to get the results. + self.assertEqual( response.content.count("