def test_picker_with_products(self): ProductFactory(display_name=u'ProductFoo', slug=u'productfoo') ProductFactory(display_name=u'ProductBar', slug=u'productbar') cache.clear() resp = self.client.get(reverse('feedback')) assert resp.status_code == 200 assert 'ProductFoo' in resp.content assert 'productfoo' in resp.content assert 'ProductBar' in resp.content assert 'productbar' in resp.content
def test_picker_with_products(self): ProductFactory(display_name=u'ProductFoo', slug=u'productfoo') ProductFactory(display_name=u'ProductBar', slug=u'productbar') cache.clear() resp = self.client.get(reverse('feedback')) eq_(resp.status_code, 200) self.assertContains(resp, 'ProductFoo') self.assertContains(resp, 'productfoo') self.assertContains(resp, 'ProductBar') self.assertContains(resp, 'productbar')
def test_urls_product_no_inferred_platform(self): """Test setting product from the url and platform non-inference""" prod = ProductFactory( display_name=u'Someprod', db_name=u'Someprod', slug=u'someprod', enabled=True, ) amount = models.Response.objects.count() # The UA is for a different browser than what the user is # leaving feedback for, so we should not infer the platform. ua = 'Mozilla/5.0 (Windows NT 6.0; rv:14.0) Gecko/20100101 Firefox/14.0.1' # noqa url = reverse('feedback', args=(prod.slug, )) resp = self.client.post(url, { 'happy': 1, 'description': u'Firefox rocks FFA!', 'url': u'http://mozilla.org/' }, HTTP_USER_AGENT=ua) self.assertRedirects(resp, reverse('thanks')) assert amount + 1 == models.Response.objects.count() feedback = models.Response.objects.latest(field_name='id') assert u'en-US' == feedback.locale assert u'Someprod' == feedback.product assert u'' == feedback.platform
def test_urls_product_inferred_platform_fxios(self): """Test firefoxdev platform gets inferred""" ProductFactory( enabled=True, display_name=u'Firefox for iOS', db_name=u'Firefox for iOS', slug=u'fxios', on_dashboard=False, on_picker=False, browser=u'Firefox for iOS', ) # Test that we infer the platform if the products are the # same. ua = ('Mozilla/5.0 (iPod touch; CPU iPhone OS 8_4 like Mac OS X) ' 'AppleWebKit/600.1.4 (KHTML, like Gecko) FxiOS/1.0 ' 'Mobile/12H143 Safari/600.1.4') url = reverse('feedback', args=('fxios', )) resp = self.client.post(url, { 'happy': 1, 'description': u'Firefox for iOS rocks!', 'url': u'http://mozilla.org/' }, HTTP_USER_AGENT=ua) self.assertRedirects(resp, reverse('thanks')) assert models.Response.objects.count() == 1 feedback = models.Response.objects.latest(field_name='id') assert feedback.locale == 'en-US' assert feedback.product == 'Firefox for iOS' assert feedback.platform == 'iPhone OS 8.4' assert feedback.browser == 'Firefox for iOS' assert feedback.browser_version == '1.0' assert feedback.browser_platform == 'iPhone OS'
def test_match(self): # Note: This isn't an exhaustive test. Just a rough cursory check. # TriggerRule that matches everything matches everything. tr = TriggerRuleFactory( versions=[], locales=[], keywords=[], products=[], ) trm = tr.get_matcher() resp = ResponseFactory() assert trm.match(resp) is True tr = TriggerRuleFactory( versions=[u'38*'], locales=[u'en-US', u'fr'], keywords=[u'rc4'], url_exists=True ) prod = ProductFactory() tr.products.add(prod) trm = tr.get_matcher() resp = ResponseFactory( version=u'38.0.5', locale=u'en-US', product=prod.db_name, description=u'rc4 is awesome', url=u'https://example.com/' ) assert trm.match(resp) is True resp.locale = 'es' assert trm.match(resp) is False
def test_update_product(self): prod = ProductFactory(display_name='Rehan') jane = AnalyzerProfileFactory().user self.client_login_user(jane) data = { 'id': prod.id, 'enabled': prod.enabled, 'display_name': 'Rehan v2', 'display_description': prod.display_description, 'db_name': prod.db_name, 'slug': prod.slug, 'on_dashboard': prod.on_dashboard, 'on_picker': prod.on_picker, 'borwser': '', 'browser_data_browser': '', 'notes': '' } resp = self.client.post(reverse('analytics_products'), data, follow=True) assert resp.status_code == 200 assert data['display_name'] in resp.content
def test_permissions_and_basic_view(self): prod = ProductFactory(display_name='Rehan') resp = self.client.get(reverse('analytics_products')) assert resp.status_code == 403 jane = AnalyzerProfileFactory().user self.client_login_user(jane) resp = self.client.get(reverse('analytics_products')) assert resp.status_code == 200 assert prod.display_name in resp.content
def test_browser_data_there_for_product_as_firefox(self): # Feedback for ProductFoo should collect browser data if the browser # being used is "Firefox". prod = ProductFactory(display_name=u'ProductFoo', slug=u'productfoo', enabled=True, browser_data_browser=u'Firefox') ua = 'Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Firefox/17.0' resp = self.client.get(reverse('feedback', args=(prod.slug, )), HTTP_USER_AGENT=ua) assert 'browser-ask' in resp.content
def test_picker_with_not_on_picker_products(self): ProductFactory(display_name=u'ProductFoo', slug=u'productfoo', on_picker=True) ProductFactory(display_name=u'ProductBar', slug=u'productbar', on_picker=False) cache.clear() resp = self.client.get(reverse('feedback')) assert resp.status_code == 200 # This is on the picker assert 'ProductFoo' in resp.content assert 'productfoo' in resp.content # This is not on the picker assert 'ProductBar' not in resp.content assert 'productbar' not in resp.content
def test_picker_with_not_on_picker_products(self): ProductFactory(display_name=u'ProductFoo', slug=u'productfoo', on_picker=True) ProductFactory(display_name=u'ProductBar', slug=u'productbar', on_picker=False) cache.clear() resp = self.client.get(reverse('feedback')) eq_(resp.status_code, 200) # This is on the picker self.assertContains(resp, 'ProductFoo') self.assertContains(resp, 'productfoo') # This is not on the picker self.assertNotContains(resp, 'ProductBar') self.assertNotContains(resp, 'productbar')
def test_browser_data_not_there_for_product_wrong_browser(self): # Feedback for ProductFoo should not collect browser data if # the browser being used doesn't match the browser it should # collect browser data for. prod = ProductFactory(display_name=u'ProductFoo', slug=u'productfoo', enabled=True, browser_data_browser=u'Android') ua = 'Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Firefox/17.0' resp = self.client.get(reverse('feedback', args=(prod.slug, )), HTTP_USER_AGENT=ua) assert 'browser-ask' not in resp.content
def test_browser_data_not_there_for_product_no_collection(self): # Feedback for ProductFoo should not collect browser data # because the product doesn't collect browser data for any # browser since the default for browser_data_browser is empty # string. prod = ProductFactory(display_name=u'ProductFoo', slug=u'productfoo', enabled=True) ua = 'Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Firefox/17.0' resp = self.client.get(reverse('feedback', args=(prod.slug, )), HTTP_USER_AGENT=ua) assert 'browser-ask' not in resp.content
def test_hidden_products_dont_show_up(self): # Create a hidden product and one response for it prod = ProductFactory(display_name=u'HiddenProduct', db_name='HiddenProduct', on_dashboard=False) ResponseFactory(product=prod.db_name) self.refresh() url = reverse('dashboard') resp = self.client.get(url) eq_(resp.status_code, 200) assert 'HiddenProduct' not in resp.content
def test_match_product(self): # Test match all products tr = TriggerRuleFactory() trm = tr.get_matcher() assert trm.match_product_name('') is True assert trm.match_product_name('sprocket') is True # Test match specific product prod = ProductFactory() tr = TriggerRuleFactory() tr.products.add(prod) trm = tr.get_matcher() assert trm.match_product_name('') is False assert trm.match_product_name('sprocket') is False assert trm.match_product_name(prod.db_name) is True