def test_redirect_to_dashboard_if_anonymous(self): # AnonymousUser shouldn't get to the new-user-view, so make # sure they get redirected to the dashboard. resp = self.client.get(reverse('new-user-view'), follow=True) assert resp.status_code == 200 assert not template_used(resp, 'new_user.html') assert template_used(resp, 'analytics/dashboard.html')
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,))) assert r.status_code == 200 assert template_used(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') assert len(secretarea) == 0 jane = AnalyzerProfileFactory().user self.client_login_user(jane) r = self.client.get(reverse('response_view', args=(resp.id,))) assert r.status_code == 200 assert template_used(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') assert len(secretarea) == 1 # Verify there is an mlt section in the secret area. mlt = pq('dd#mlt') assert len(mlt) == 1
def test_login_failure_view(self): resp = self.client.get(reverse('login-failure')) assert resp.status_code == 200 assert template_used(resp, 'login_failure.html') resp = self.client.get(reverse('login-failure'), {'mobile': 1}) assert resp.status_code == 200 assert template_used(resp, 'mobile/login_failure.html')
def test_firefox_os_view(self): """Firefox OS returns correct view""" # Firefox OS is the user agent url = reverse('feedback') ua = 'Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0' r = self.client.get(url, HTTP_USER_AGENT=ua) assert template_used(r, 'feedback/fxos_feedback.html') # Specifying fxos as the product in the url url = reverse('feedback', args=(u'fxos', )) r = self.client.get(url) assert template_used(r, 'feedback/fxos_feedback.html')
def test_firefox_os_view(self): """Firefox OS returns correct view""" # Firefox OS is the user agent url = reverse("feedback") ua = "Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0" r = self.client.get(url, HTTP_USER_AGENT=ua) assert template_used(r, "feedback/fxos_feedback.html") # Specifying fxos as the product in the url url = reverse("feedback", args=(u"fxos",)) r = self.client.get(url) assert template_used(r, "feedback/fxos_feedback.html")
def test_android_view_redirects_to_android_thanks(self): """Sad feedback in Android redirects to proper thanks template""" url = reverse("feedback", args=(u"android",)) data = {"happy": 0, "description": u"Video plays backwards :(", "url": u"http://mozilla.org/"} r = self.client.post(url, data=data, follow=True) # The below tests whether the feedback view function # register_feedback_config() is working as it should assert template_used(r, "feedback/android_thanks.html")
def test_firefox_os_view_works_for_all_browsers(self): """Firefox OS feedback form should work for all browsers""" # Firefox OS is the user agent url = reverse('feedback', args=(u'fxos', )) ua = ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) ' 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 ' 'Safari/537.36') r = self.client.get(url, HTTP_USER_AGENT=ua) assert template_used(r, 'feedback/fxos_feedback.html')
def test_response_view(self): """Test dashboard link goes to response view""" resp = ResponseFactory(happy=True, description=u'the best!') self.refresh() url = reverse('dashboard') r = self.client.get(url) assert r.status_code == 200 assert template_used(r, 'analytics/dashboard.html') pq = PyQuery(r.content) # Get the permalink permalink = pq('li.opinion a[href*="response"]').attr('href') r = self.client.get(permalink) assert r.status_code == 200 assert template_used(r, 'analytics/response.html') assert str(resp.description) in r.content
def test_front_page(self): url = reverse('dashboard') resp = self.client.get(url) assert resp.status_code == 200 assert template_used(resp, 'analytics/dashboard.html') pq = PyQuery(resp.content) # Make sure that each opinion is shown and that the count is correct. assert pq('.block.count strong').text() == '7' assert len(pq('li.opinion')) == 7
def test_default_next_url(self): self.client_login_user(self.jane) resp = self.client.get(reverse('new-user-view')) assert resp.status_code == 200 assert template_used(resp, 'new_user.html') # Pull out next link pq = PyQuery(resp.content) next_url = pq('#next-url-link') assert next_url.attr['href'] == '/en-US/' # this is the dashboard
def test_response_view_mobile(self): """Test response mobile view doesn't die""" resp = ResponseFactory(happy=True, description=u'the best!') self.refresh() r = self.client.get(reverse('response_view', args=(resp.id,)), {'mobile': 1}) assert r.status_code == 200 assert template_used(r, 'analytics/mobile/response.html') assert str(resp.description) in r.content
def test_firefox_os_view_works_for_all_browsers(self): """Firefox OS feedback form should work for all browsers""" # Firefox OS is the user agent url = reverse("feedback", args=(u"fxos",)) ua = ( "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) " "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 " "Safari/537.36" ) r = self.client.get(url, HTTP_USER_AGENT=ua) assert template_used(r, "feedback/fxos_feedback.html")
def test_android_view_redirects_to_android_thanks(self): """Sad feedback in Android redirects to proper thanks template""" url = reverse('feedback', args=(u'android', )) data = { 'happy': 0, 'description': u'Video plays backwards :(', 'url': u'http://mozilla.org/' } r = self.client.post(url, data=data, follow=True) # The below tests whether the feedback view function # register_feedback_config() is working as it should assert template_used(r, 'feedback/android_thanks.html')
def test_frontpage_es_down(self): """If can't connect to ES, show es_down template.""" # TODO: Rewrite this with Mock. old_counts_to_options = views.counts_to_options try: def mock_counts_to_options(*args, **kwargs): raise ConnectionError() views.counts_to_options = mock_counts_to_options resp = self.client.get(reverse('dashboard')) assert template_used(resp, 'analytics/es_down.html') finally: views.counts_to_options = old_counts_to_options
def test_valid_next_url(self): self.client_login_user(self.jane) url = reverse('new-user-view') resp = self.client.get(url, { 'next': '/ou812' # stretches the meaning of 'valid' }) assert resp.status_code == 200 assert template_used(resp, 'new_user.html') # Pull out next link which is naughty, so it should have been # replaced with a dashboard link. pq = PyQuery(resp.content) next_url = pq('#next-url-link') assert next_url.attr['href'] == '/ou812'
def test_sanitized_next_url(self): self.client_login_user(self.jane) url = reverse('new-user-view') resp = self.client.get(url, { 'next': 'javascript:prompt%28document.cookie%29' }) assert resp.status_code == 200 assert template_used(resp, 'new_user.html') # Pull out next link which is naughty, so it should have been # replaced with a dashboard link. pq = PyQuery(resp.content) next_url = pq('#next-url-link') assert next_url.attr['href'] == '/en-US/' # this is the dashboard
def test_robots(self): resp = self.client.get('/robots.txt') assert resp.status_code == 200 assert template_used(resp, 'robots.txt')
def test_front_page(self): resp = self.client.get(self.url) assert resp.status_code == 200 assert template_used(resp, 'analytics/analyzer/search.html') pq = PyQuery(resp.content) assert len(pq('li.opinion')) == 7
def test_firefox_os_view(self): """Firefox OS returns correct view""" # Specifying fxos as the product in the url url = reverse('feedback', args=(u'fxos',)) r = self.client.get(url) assert template_used(r, 'feedback/fxos_feedback.html')
def test_firefox_os_view(self): """Firefox OS returns correct view""" # Specifying fxos as the product in the url url = reverse('feedback', args=(u'fxos', )) r = self.client.get(url) assert template_used(r, 'feedback/fxos_feedback.html')
def test_about_view(self): resp = self.client.get(reverse('about-view')) assert resp.status_code == 200 assert template_used(resp, 'about.html')
def test_picker_no_products(self): resp = self.client.get(reverse("feedback")) assert resp.status_code == 200 assert template_used(resp, "feedback/picker.html") assert "No products available." in resp.content
def test_contribute(self): resp = self.client.get('/contribute.json') assert resp.status_code == 200 assert template_used(resp, 'contribute.json')
def test_android_view(self): """Android returns correct view""" url = reverse('feedback', args=(u'android', )) r = self.client.get(url) assert template_used(r, 'feedback/android_feedback.html')
def test_picker_no_products(self): resp = self.client.get(reverse('feedback')) assert resp.status_code == 200 assert template_used(resp, 'feedback/picker.html') assert 'No products available.' in resp.content
def test_frontpage_index_missing(self): """If index is missing, show es_down template.""" self.teardown_indexes() resp = self.client.get(reverse('dashboard')) assert template_used(resp, 'analytics/es_down.html')
def test_android_view(self): """Android returns correct view""" url = reverse("feedback", args=(u"android",)) r = self.client.get(url) assert template_used(r, "feedback/android_feedback.html")