def test_response_view_analyzer(self): """Test secret section only shows up for analyzers""" resp = ResponseFactory(happy=True, description=u'the bestest best!') self.refresh() r = self.client.get(reverse('response_view', args=(resp.id, ))) eq_(200, r.status_code) self.assertTemplateUsed(r, 'analytics/response.html') assert str(resp.description) in r.content # Verify there is no secret area visible for non-analyzers. pq = PyQuery(r.content) secretarea = pq('dl.secret') eq_(len(secretarea), 0) jane = ProfileFactory(user__email='*****@*****.**').user jane.groups.add(Group.objects.get(name='analyzers')) self.client_login_user(jane) r = self.client.get(reverse('response_view', args=(resp.id, ))) eq_(200, r.status_code) self.assertTemplateUsed(r, 'analytics/response.html') assert str(resp.description) in r.content # Verify the secret area is there. pq = PyQuery(r.content) secretarea = pq('dl.secret') eq_(len(secretarea), 1) # Verify there is an mlt section in the secret area. mlt = pq('dd#mlt') eq_(len(mlt), 1)
def setUp(self): super(TestOccurrencesView, self).setUp() # Set up some sample data items = [ # happy, locale, description (True, 'en-US', 'apple banana orange pear'), (True, 'en-US', 'orange pear kiwi'), (True, 'en-US', 'chocolate chocolate yum'), (False, 'en-US', 'apple banana grapefruit'), # This one doesn't create bigrams because there isn't enough words (False, 'en-US', 'orange'), # This one shouldn't show up (False, 'es', 'apple banana'), ] for happy, locale, description in items: ResponseFactory(happy=happy, locale=locale, description=description) self.refresh() # Create analyzer and log analyzer in jane = ProfileFactory(user__email='*****@*****.**').user jane.groups.add(Group.objects.get(name='analyzers')) self.client_login_user(jane)
def setUp(self): super(TestSearchView, self).setUp() # Set up some sample data # 4 happy, 3 sad. # 2 Windows XP, 2 Linux, 1 OS X, 2 Windows 7 now = datetime.now() # The dashboard by default shows the last week of data, so # these need to be relative to today. The alternative is that # every test gives an explicit date range, and that is # annoying and verbose. items = [ # happy, platform, locale, description, created (True, '', 'en-US', 'apple', now - timedelta(days=6)), (True, 'Windows 7', 'es', 'banana', now - timedelta(days=5)), (True, 'Linux', 'en-US', 'orange', now - timedelta(days=4)), (True, 'Linux', 'en-US', 'apple', now - timedelta(days=3)), (False, 'Windows XP', 'en-US', 'banana', now - timedelta(days=2)), (False, 'Windows 7', 'en-US', 'orange', now - timedelta(days=1)), (False, 'Linux', 'es', u'\u2713 apple', now - timedelta(days=0)), ] for happy, platform, locale, description, created in items: # We don't need to keep this around, just need to create it. ResponseFactory(happy=happy, platform=platform, locale=locale, description=description, created=created) self.refresh() # Create analyzer and log analyzer in jane = ProfileFactory(user__email='*****@*****.**').user jane.groups.add(Group.objects.get(name='analyzers')) self.client_login_user(jane)
def test_existing_user(self): """Tests that existing users get redirected to right place""" new_user = ProfileFactory().user self.client_login_user(new_user) # Now do some ridiculous setup so we can call login_success() # on the Verify and see if it did what it should be doing. # FIXME - this can go away post django-browserid 0.9 new_user.backend = 'django_browserid.auth.BrowserIDBackend' # First, do it RAW! post_request = RequestFactory().post(reverse('browserid.login')) post_request.user = new_user post_request.session = self.client.session fv = FjordVerify() fv.user = new_user fv.request = post_request resp = fv.login_success() eq_(200, resp.status_code) body = json.loads(resp.content) eq_(body['redirect'], '/') # Now do it with next! post_request = RequestFactory().post( reverse('browserid.login'), {'next': '/foo'}) post_request.user = new_user post_request.session = self.client.session fv = FjordVerify() fv.user = new_user fv.request = post_request resp = fv.login_success() eq_(200, resp.status_code) body = json.loads(resp.content) eq_(body['redirect'], '/foo')
def test_existing_user(self): """Tests that existing users get redirected to right place""" new_user = ProfileFactory().user self.client_login_user(new_user) # Now do some ridiculous setup so we can call login_success() # on the Verify and see if it did what it should be doing. # FIXME - this can go away post django-browserid 0.9 new_user.backend = 'django_browserid.auth.BrowserIDBackend' # First, do it RAW! post_request = RequestFactory().post(reverse('browserid.login')) post_request.user = new_user post_request.session = self.client.session fv = FjordVerify() fv.user = new_user fv.request = post_request resp = fv.login_success() assert resp.status_code == 200 body = json.loads(resp.content) assert body['redirect'] == '/' # Now do it with next! post_request = RequestFactory().post(reverse('browserid.login'), {'next': '/foo'}) post_request.user = new_user post_request.session = self.client.session fv = FjordVerify() fv.user = new_user fv.request = post_request resp = fv.login_success() assert resp.status_code == 200 body = json.loads(resp.content) assert body['redirect'] == '/foo'
def test_existing_user(self): """Tests that existing users get redirected to right place""" new_user = ProfileFactory().user self.client_login_user(new_user) # Now do some ridiculous setup so we can call login_success() # on the Verify and see if it did what it should be doing. # FIXME - this can go away post django-browserid 0.9 new_user.backend = "django_browserid.auth.BrowserIDBackend" # First, do it RAW! post_request = RequestFactory().post(reverse("browserid.login")) post_request.user = new_user post_request.session = self.client.session fv = FjordVerify() fv.user = new_user fv.request = post_request resp = fv.login_success() assert resp.status_code == 200 body = json.loads(resp.content) assert body["redirect"] == "/" # Now do it with next! post_request = RequestFactory().post(reverse("browserid.login"), {"next": "/foo"}) post_request.user = new_user post_request.session = self.client.session fv = FjordVerify() fv.user = new_user fv.request = post_request resp = fv.login_success() assert resp.status_code == 200 body = json.loads(resp.content) assert body["redirect"] == "/foo"
def test_existing_user(self): """Tests that existing users get redirected to right place""" new_user = ProfileFactory().user self.client_login_user(new_user) # Now do some ridiculous setup so we can call login_success() # on the Verify and see if it did what it should be doing. # FIXME - this can go away post django-browserid 0.9 new_user.backend = 'django_browserid.auth.BrowserIDBackend' # First, do it RAW! get_request = RequestFactory().get(reverse('dashboard')) get_request.user = new_user get_request.session = self.client.session fv = FjordVerify() fv.user = new_user fv.request = get_request resp = fv.login_success() eq_(302, resp.status_code) eq_(resp.get('location'), '/') # Now do it with next! get_request = RequestFactory().get(reverse('dashboard') + '?next=/foo') get_request.user = new_user get_request.session = self.client.session fv = FjordVerify() fv.user = new_user fv.request = get_request resp = fv.login_success() eq_(302, resp.status_code) eq_(resp.get('location'), '/foo')
def test_permissions(self): # Verifies that only analyzers can see the analytics dashboard # link resp = self.client.get(reverse('dashboard')) eq_(200, resp.status_code) assert 'adashboard' not in resp.content # Verifies that only analyzers can see the analytics dashboard resp = self.client.get(reverse('analytics_dashboard')) eq_(403, resp.status_code) # Verify analyzers can see analytics dashboard link jane = ProfileFactory(user__email='*****@*****.**').user jane.groups.add(Group.objects.get(name='analyzers')) self.client_login_user(jane) resp = self.client.get(reverse('dashboard')) eq_(200, resp.status_code) assert 'adashboard' in resp.content # Verify analyzers can see analytics dashboard resp = self.client.get(reverse('analytics_dashboard')) eq_(200, resp.status_code)
def setUp(self): super(TestNewUserView, self).setUp() jane = ProfileFactory(user__email='*****@*****.**').user jane.groups.add(Group.objects.get(name='analyzers')) self.jane = jane