Permalink
Browse files

[bug 966426] Add test for has_email filter

  • Loading branch information...
1 parent 030fe96 commit fe2a687536357b6ce072c0325577b9202555c207 @willkg willkg committed Feb 14, 2014
Showing with 50 additions and 3 deletions.
  1. +35 −2 fjord/analytics/tests/test_analyzer_views.py
  2. +15 −1 fjord/feedback/tests/__init__.py
@@ -2,14 +2,14 @@
import json
import logging
-from nose.tools import eq_
+from nose.tools import eq_, ok_
from pyquery import PyQuery
from django.contrib.auth.models import Group
from django.http import QueryDict
from fjord.base.tests import LocalizingClient, profile, reverse, user
-from fjord.feedback.tests import response
+from fjord.feedback.tests import response, responseemail
from fjord.search.tests import ElasticTestCase
@@ -209,6 +209,39 @@ def test_search(self):
pq = PyQuery(r.content)
eq_(len(pq('li.opinion')), 0)
+ def test_has_email(self):
+ # Test before we create a responsemail
+ r = self.client.get(self.url, {'has_email': '0'})
+ eq_(r.status_code, 200)
+ pq = PyQuery(r.content)
+ eq_(len(pq('li.opinion')), 7)
+
+ r = self.client.get(self.url, {'has_email': '1'})
+ eq_(r.status_code, 200)
+ pq = PyQuery(r.content)
+ eq_(len(pq('li.opinion')), 0)
+
+ resp = response(
+ happy=True, product=u'Firefox', description=u'ou812',
+ created=datetime.now(), save=True)
+ responseemail(opinion=resp, save=True)
+ # Have to reindex everything because unlike in a request
+ # context, what happens here is we index the Response, but
+ # without the ResponseEmail.
+ self.setup_indexes()
+
+ r = self.client.get(self.url, {'has_email': '0'})
+ eq_(r.status_code, 200)
+ pq = PyQuery(r.content)
+ ok_('ou812' not in r.content)
+ eq_(len(pq('li.opinion')), 7)
+
+ r = self.client.get(self.url, {'has_email': '1'})
+ eq_(r.status_code, 200)
+ pq = PyQuery(r.content)
+ ok_('ou812' in r.content)
+ eq_(len(pq('li.opinion')), 1)
+
def test_empty_and_unknown(self):
# Empty value should work
r = self.client.get(self.url, {'platform': ''})
@@ -1,6 +1,6 @@
from fjord.base import browsers
from fjord.base.tests import with_save
-from fjord.feedback.models import Product, Response
+from fjord.feedback.models import Product, Response, ResponseEmail
USER_AGENT = 'Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Firefox/17.0'
@@ -46,3 +46,17 @@ def response(**kwargs):
defaults.update(kwargs)
return Response(**defaults)
+
+
+@with_save
+def responseemail(**kwargs):
+ defaults = {
+ 'email': 'joe@example.com'
+ }
+
+ defaults.update(kwargs)
+ if 'opinion' not in kwargs:
+ resp = response(save=True)
+ defaults['opinion'] = resp
+
+ return ResponseEmail(**defaults)

0 comments on commit fe2a687

Please sign in to comment.