Example #1
0
    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
Example #2
0
    def test_update_survey(self):
        survey = SurveyFactory()

        data = {
            'id': survey.id,
            'name': 'rehanrocks',
            'description': survey.description,
            'enabled': survey.enabled
        }

        resp = self.client.post(
            reverse('hb_surveys_update', args=(survey.id,)),
            data
        )
        assert resp.status_code == 403

        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        resp = self.client.post(
            reverse('hb_surveys_update', args=(survey.id,)),
            data
        )
        assert resp.status_code == 302

        # Make sure it's in the survey list
        resp = self.client.get(reverse('hb_surveys'))
        assert resp.status_code == 200
        assert data['name'] in resp.content
Example #3
0
    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),
        ]
        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 = AnalyzerProfileFactory().user
        self.client_login_user(jane)
Example #4
0
    def test_response_id_in_qs_authenticated(self):
        """Verify response_id in querystring overrides session id"""
        # Create analyzer and log in.

        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        # Create some feedback which sets the response_id in the
        # session.
        url = reverse('feedback', args=(u'firefox', ), locale='en-US')
        r = self.client.post(
            url, {
                'happy': 0,
                'description': u'Why Firefox not make me sandwiches!',
            },
            follow=True)

        # Create another piece of feedback which is not the one we
        # just did.
        feedback = ResponseFactory(description=u'purple horseshoes')

        # Fetch the thank you page with the response_id in the
        # querystring.
        url = reverse('thanks') + '?response_id={0}'.format(feedback.id)
        r = self.client.get(url)

        assert r.status_code == 200
        assert r.jinja_context['feedback'].id == feedback.id
        assert r.jinja_context['suggestions'] == []
Example #5
0
    def test_answer_view(self):
        """Verify only analyzers can see hb_data view and view shows answers"""
        answer = AnswerFactory(flow_id='rehanrocks')

        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        resp = self.client.get(reverse('hb_data', args=(answer.id,)))
        assert answer.flow_id in resp.content
Example #6
0
    def test_permissions_and_basic_view(self):
        """Verify only analyzers can see hb_surveys view"""
        resp = self.client.get(reverse('hb_surveys'))
        assert resp.status_code == 403

        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        resp = self.client.get(reverse('hb_surveys'))
        assert resp.status_code == 200
Example #7
0
    def test_invalid_data(self):
        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        resp = self.client.post(
            reverse('triggerrule-match'),
            content_type='application/json',
            data='[}'
        )
        assert resp.status_code == 400
Example #8
0
    def test_permissions_and_basic_view(self):
        resp = self.client.get(reverse('hb_healthcheck'))
        assert resp.status_code == 403

        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        resp = self.client.get(reverse('hb_healthcheck'))
        assert resp.status_code == 200
        assert 'Heartbeat Health Check' in resp.content
Example #9
0
    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
Example #10
0
    def test_versions(self):
        te_resp = ResponseFactory(version=u'38.0')
        teof_resp = ResponseFactory(version=u'38.0.5')
        ResponseFactory(version=u'39.0')

        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        # Test one version
        data = {
            'locales': [],
            'products': [],
            'versions': [u'38.0'],
            'keywords': [],
            'url_exists': None
        }
        resp = self.client.post(
            reverse('triggerrule-match'),
            content_type='application/json',
            data=json.dumps(data)
        )
        assert resp.status_code == 200
        assert (
            [item['id'] for item in json.loads(resp.content)['results']] ==
            [te_resp.id]
        )

        # Test two
        data['versions'] = [u'38.0', u'38.0.5']
        resp = self.client.post(
            reverse('triggerrule-match'),
            content_type='application/json',
            data=json.dumps(data)
        )
        assert resp.status_code == 200
        assert (
            [item['id'] for item in json.loads(resp.content)['results']] ==
            [teof_resp.id, te_resp.id]
        )

        # Test prefix
        data['versions'] = [u'38*']
        resp = self.client.post(
            reverse('triggerrule-match'),
            content_type='application/json',
            data=json.dumps(data)
        )
        assert resp.status_code == 200
        assert (
            [item['id'] for item in json.loads(resp.content)['results']] ==
            [teof_resp.id, te_resp.id]
        )
Example #11
0
    def test_url_exists(self):
        fb1 = ResponseFactory(url=u'')
        fb2 = ResponseFactory(url=u'http://example.com')
        fb3 = ResponseFactory(url=u'http://example.com')

        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        # Test don't care
        data = {
            'locales': [],
            'products': [],
            'versions': [],
            'keywords': [],
            'url_exists': None
        }
        resp = self.client.post(
            reverse('triggerrule-match'),
            content_type='application/json',
            data=json.dumps(data)
        )
        assert resp.status_code == 200
        assert (
            [item['id'] for item in json.loads(resp.content)['results']] ==
            [fb3.id, fb2.id, fb1.id]
        )

        # Test has a url
        data['url_exists'] = True
        resp = self.client.post(
            reverse('triggerrule-match'),
            content_type='application/json',
            data=json.dumps(data)
        )
        assert resp.status_code == 200
        assert (
            [item['id'] for item in json.loads(resp.content)['results']] ==
            [fb3.id, fb2.id]
        )

        # Test does not have a url
        data['url_exists'] = False
        resp = self.client.post(
            reverse('triggerrule-match'),
            content_type='application/json',
            data=json.dumps(data)
        )
        assert resp.status_code == 200
        assert (
            [item['id'] for item in json.loads(resp.content)['results']] ==
            [fb1.id]
        )
Example #12
0
    def test_keywords(self):
        rte_resp = ResponseFactory(description=u'Ride the lightning')
        fwtbt_resp = ResponseFactory(description=u'For whom the bell tolls')
        ResponseFactory(description=u'The thing that should not be')

        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        # Test one keyword
        data = {
            'locales': [],
            'products': [],
            'versions': [],
            'keywords': [u'lightning'],
            'url_exists': None
        }
        resp = self.client.post(
            reverse('triggerrule-match'),
            content_type='application/json',
            data=json.dumps(data)
        )
        assert resp.status_code == 200
        assert (
            [item['id'] for item in json.loads(resp.content)['results']] ==
            [rte_resp.id]
        )

        # Test two
        data['keywords'] = [u'lightning', u'tolls']
        resp = self.client.post(
            reverse('triggerrule-match'),
            content_type='application/json',
            data=json.dumps(data)
        )
        assert resp.status_code == 200
        assert (
            [item['id'] for item in json.loads(resp.content)['results']] ==
            [fwtbt_resp.id, rte_resp.id]
        )

        # Test phrase
        data['keywords'] = [u'bell tolls']
        resp = self.client.post(
            reverse('triggerrule-match'),
            content_type='application/json',
            data=json.dumps(data)
        )
        assert resp.status_code == 200
        assert (
            [item['id'] for item in json.loads(resp.content)['results']] ==
            [fwtbt_resp.id]
        )
Example #13
0
    def test_permissions_and_basic_view(self):
        """Verify only analyzers can see hb_errorlog view"""
        log_error({}, {'rehanrocks': 'really'})

        resp = self.client.get(reverse('hb_errorlog'))
        assert resp.status_code == 403

        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        resp = self.client.get(reverse('hb_errorlog'))
        assert resp.status_code == 200
        assert 'rehanrocks' in resp.content
Example #14
0
    def test_permissions_and_basic_view(self):
        """Verify only analyzers can see hb_data view and view shows answers"""
        answer = AnswerFactory(flow_id='rehanrocks')

        resp = self.client.get(reverse('hb_data'))
        assert resp.status_code == 403

        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        resp = self.client.get(reverse('hb_data'))
        assert resp.status_code == 200
        assert answer.flow_id in resp.content
Example #15
0
    def test_create_survey(self):
        # Create a survey and make sure it's there
        data = {
            'name': 'rehanrocks',
            'description': 'foo',
            'enabled': True
        }

        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        resp = self.client.post(reverse('hb_surveys'), data)
        assert resp.status_code == 302

        # Make sure it's in the survey list
        resp = self.client.get(reverse('hb_surveys'))
        assert resp.status_code == 200
        assert data['name'] in resp.content
Example #16
0
    def test_permissions(self):
        # Verifies that only analyzers can see the analytics dashboard
        # link
        resp = self.client.get(reverse('dashboard'))
        assert resp.status_code == 200
        assert 'adashboard' not in resp.content

        # Verifies that only analyzers can see the analytics dashboard
        resp = self.client.get(reverse('analytics_dashboard'))
        assert resp.status_code == 403

        # Verify analyzers can see analytics dashboard link
        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        resp = self.client.get(reverse('dashboard'))
        assert resp.status_code == 200
        assert 'adashboard' in resp.content

        # Verify analyzers can see analytics dashboard
        resp = self.client.get(reverse('analytics_dashboard'))
        assert resp.status_code == 200
Example #17
0
    def test_locales(self):
        ResponseFactory(locale=u'fr')
        es_resp = ResponseFactory(locale=u'es')
        enus_resp = ResponseFactory(locale=u'en-US')

        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        # Test one locale
        data = {
            'locales': [u'en-US'],
            'products': [],
            'versions': [],
            'keywords': [],
            'url_exists': None
        }
        resp = self.client.post(
            reverse('triggerrule-match'),
            content_type='application/json',
            data=json.dumps(data)
        )
        assert resp.status_code == 200
        assert (
            [item['id'] for item in json.loads(resp.content)['results']] ==
            [enus_resp.id]
        )

        # Test two
        data['locales'] = [u'en-US', u'es']
        resp = self.client.post(
            reverse('triggerrule-match'),
            content_type='application/json',
            data=json.dumps(data)
        )
        assert resp.status_code == 200
        assert (
            [item['id'] for item in json.loads(resp.content)['results']] ==
            [enus_resp.id, es_resp.id]
        )
Example #18
0
    def test_add_product(self):
        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        data = {
            'enabled': True,
            'display_name': 'Rehan',
            'display_description': '*the* Rehan',
            'db_name': 'rehan',
            'slug': 'rehan',
            'on_dashboard': True,
            'on_picker': True,
            'browser': '',
            '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
Example #19
0
    def test_products(self):
        fx_resp = ResponseFactory(product=u'Firefox')
        fxa_resp = ResponseFactory(product=u'Firefox for Android')
        ResponseFactory(product=u'Loop')

        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        # Test one product
        data = {
            'locales': [],
            'products': [u'Firefox'],
            'versions': [],
            'keywords': [],
            'url_exists': None
        }
        resp = self.client.post(
            reverse('triggerrule-match'),
            content_type='application/json',
            data=json.dumps(data)
        )
        assert resp.status_code == 200
        assert (
            [item['id'] for item in json.loads(resp.content)['results']] ==
            [fx_resp.id]
        )

        # Test two
        data['products'] = [u'Firefox', u'Firefox for Android']
        resp = self.client.post(
            reverse('triggerrule-match'),
            content_type='application/json',
            data=json.dumps(data)
        )
        assert resp.status_code == 200
        assert (
            [item['id'] for item in json.loads(resp.content)['results']] ==
            [fxa_resp.id, fx_resp.id]
        )
Example #20
0
    def test_empty_tr(self):
        feedback_responses = ResponseFactory.create_batch(5)

        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        data = {
            'locales': [],
            'products': [],
            'versions': [],
            'keywords': [],
            'url_exists': None
        }
        resp = self.client.post(
            reverse('triggerrule-match'),
            content_type='application/json',
            data=json.dumps(data)
        )
        assert resp.status_code == 200
        # Note: This matches everything because it's an empty rule.
        assert (
            [item['id'] for item in json.loads(resp.content)['results']] ==
            [fr.id for fr in reversed(feedback_responses)]
        )
Example #21
0
    def test_contents(self):
        fr = ResponseFactory()

        jane = AnalyzerProfileFactory().user
        self.client_login_user(jane)

        data = {
            'locales': [],
            'products': [],
            'versions': [],
            'keywords': [],
            'url_exists': None
        }
        resp = self.client.post(
            reverse('triggerrule-match'),
            content_type='application/json',
            data=json.dumps(data)
        )
        assert resp.status_code == 200
        content = json.loads(resp.content)
        assert (
            content['results'] ==
            [
                {
                    u'id': int(fr.id),
                    u'created': fr.created.strftime(u'%Y-%m-%dT%H:%M:%S'),
                    u'description': fr.description,
                    u'happy': fr.happy,
                    u'locale': fr.locale,
                    u'product': fr.product,
                    u'platform': fr.platform,
                    u'url': fr.url,
                    u'version': fr.version
                }
            ]
        )