예제 #1
0
파일: test_utils.py 프로젝트: rlr/fjord
    def test_valid_key(self):
        """Make sure the key is valid"""
        actual_ip_plus_desc = actual_ip_plus_context(
            lambda req: req.POST.get('description', 'no description')
        )

        url = reverse('feedback')
        factory = RequestFactory(HTTP_X_CLUSTER_CLIENT_IP='192.168.100.101')

        # create a request with this as the description
        desc = u'\u5347\u7ea7\u4e86\u65b0\u7248\u672c\u4e4b\u540e' * 16
        req = factory.post(url, {
            'description': desc
        })
        key = actual_ip_plus_desc(req)

        # Key can't exceed memcached 250 character max
        length = len(key)
        ok_(length < 250)

        # Key must be a string
        ok_(isinstance(key, str))

        # create a request with this as the description
        second_desc = u'\u62e9\u201c\u5728\u65b0\u6807\u7b7e\u9875\u4e2d' * 16
        second_req = factory.post(url, {
            'description': second_desc
        })
        second_key = actual_ip_plus_desc(second_req)

        # Two descriptions with the same ip address should produce
        # different keys.
        assert key != second_key
예제 #2
0
파일: test_api.py 프로젝트: rlr/fjord
    def test_invalid_unicode_url(self):
        """Tests an API call with invalid unicode URL"""
        data = {
            'happy': True,
            'description': u'Great!',
            'category': u'ui',
            'product': u'Firefox OS',
            'channel': u'stable',
            'version': u'1.1',
            'platform': u'Firefox OS',
            'locale': 'en-US',
            'email': '*****@*****.**',
            'url': 'தமிழகம்',
            'manufacturer': 'OmniCorp',
            'device': 'OmniCorp',
            'country': 'US',
            'user_agent': (
                'Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0'
            ),
            'source': 'email',
            'campaign': 'email_test',
        }
        r = self.client.post(
            reverse('feedback-api'),
            content_type='application/json',
            data=json.dumps(data))

        eq_(r.status_code, 400)
        content = json.loads(r.content)
        ok_(u'url' in content)
        ok_(content['url'][0].endswith(u'is not a valid url'))
예제 #3
0
파일: test_api.py 프로젝트: TroJan/fjord
    def test_invalid_unicode_url(self):
        """Tests an API call with invalid unicode URL"""
        data = {
            "happy": True,
            "description": u"Great!",
            "category": u"ui",
            "product": u"Firefox OS",
            "channel": u"stable",
            "version": u"1.1",
            "platform": u"Firefox OS",
            "locale": "en-US",
            "email": "*****@*****.**",
            "url": "தமிழகம்",
            "manufacturer": "OmniCorp",
            "device": "OmniCorp",
            "country": "US",
            "user_agent": ("Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0"),
            "source": "email",
            "campaign": "email_test",
        }
        r = self.client.post(reverse("feedback-api"), content_type="application/json", data=json.dumps(data))

        eq_(r.status_code, 400)
        content = json.loads(r.content)
        ok_(u"url" in content)
        ok_(content["url"][0].endswith(u"is not a valid url"))
예제 #4
0
파일: test_api.py 프로젝트: rlr/fjord
    def test_post_invalid_start_time(self):
        token = TokenFactory()
        flavor = AlertFlavorFactory(name='Foo', slug='fooflavor')
        flavor.allowed_tokens.add(token)

        data = {
            'severity': 5,
            'summary': 'test alert',
            'description': (
                'All we ever see of stars are their old photographs.'
            ),
            'flavor': flavor.slug,
            'emitter_name': 'testemitter',
            'emitter_version': 0,
            'start_time': '2015'
        }

        resp = self.client.post(
            reverse('alerts-api'),
            data=json.dumps(data),
            content_type='application/json',
            HTTP_AUTHORIZATION='token ' + token.token
        )
        eq_(resp.status_code, 400)
        content = json.loads(resp.content)
        ok_(content['detail']['start_time'][0].startswith(
            u'Datetime has wrong format.'))
예제 #5
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)

        ResponseEmailFactory(
            opinion__happy=True,
            opinion__product=u'Firefox',
            opinion__description=u'ou812',
            opinion__created=datetime.now())

        # 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)
예제 #6
0
    def test_country(self):
        ResponseEmailFactory(
            opinion__happy=True,
            opinion__product=u'Firefox OS',
            opinion__description=u'ou812',
            opinion__country=u'ES',
            opinion__created=datetime.now())
        # 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, {
            'product': 'Firefox OS', 'country': 'ES'})
        eq_(r.status_code, 200)
        pq = PyQuery(r.content)
        ok_('ou812' in r.content)
        eq_(len(pq('li.opinion')), 1)
예제 #7
0
파일: test_utils.py 프로젝트: rlr/fjord
    def test_valid_key_ipv6(self):
        """Make sure ipv6 keys work"""
        actual_ip_plus_desc = actual_ip_plus_context(
            lambda req: req.POST.get('description', 'no description')
        )

        url = reverse('feedback')
        factory = RequestFactory(
            HTTP_X_CLUSTER_CLIENT_IP='0000:0000:0000:0000:0000:0000:0000:0000')

        # create a request with this as the description
        desc = u'\u5347\u7ea7\u4e86\u65b0\u7248\u672c\u4e4b\u540e' * 16
        req = factory.post(url, {
            'description': desc
        })
        key = actual_ip_plus_desc(req)

        # Key can't exceed memcached 250 character max
        length = len(key)
        ok_(length < 250)
예제 #8
0
파일: test_api.py 프로젝트: rlr/fjord
    def test_created_invalid(self):
        token = TokenFactory()
        flavor = AlertFlavorFactory(name='Foo', slug='fooflavor')
        flavor.allowed_tokens.add(token)

        qs = {
            'flavors': flavor.slug,
            'created_start': 'one',
            'created_end': 'one'
        }
        resp = self.client.get(
            reverse('alerts-api') + '?' + urllib.urlencode(qs),
            HTTP_AUTHORIZATION='token ' + token.token
        )

        eq_(resp.status_code, 400)
        data = json.loads(resp.content)
        ok_(data['detail']['created_start'][0]
            .startswith('Datetime has wrong format'))
        ok_(data['detail']['created_end'][0]
            .startswith('Datetime has wrong format'))

        qs = {
            'flavors': flavor.slug,
            'created_start': datetime.datetime.now(),
            'created_end': (
                datetime.datetime.now() - datetime.timedelta(days=1)
            )
        }
        resp = self.client.get(
            reverse('alerts-api') + '?' + urllib.urlencode(qs),
            HTTP_AUTHORIZATION='token ' + token.token
        )

        eq_(resp.status_code, 400)
        data = json.loads(resp.content)
        eq_(data['detail'],
            {'non_field_errors': [
                u'created_start must occur before created_end.'
            ]}
        )
예제 #9
0
    def test_get_suggestions(self):
        url = reverse('feedback', args=(u'firefox',))
        desc = u'slow browser please speed improve i am wait speed improv 2'

        # Post some basic feedback that meets the SUMO Suggest
        # Provider standards and follow through to the Thank You
        # page. This triggers the suggestions and docs should be
        # in the session.
        resp = self.client.post(url, {
            'happy': 0,
            'description': desc,
        }, follow=True)

        feedback_id = self.client.session['response_id']
        session_key = SUMO_SUGGEST_SESSION_KEY.format(feedback_id)

        # Verify we get the right number of docs from the SUMO Suggest
        # API and that the urls start with SUMO_HOST.
        docs = self.client.session[session_key]
        ok_(0 < len(docs) <= 3)
        for doc in docs:
            ok_(doc['url'].startswith(SUMO_HOST))

        # Note: Since SUMO content changes, we can't check specific
        # strings since we don't really know what it's going to
        # return.

        links = resp.context['suggestions']
        eq_(links[0].provider, 'sumosuggest')
        eq_(links[0].provider_version, 1)

        # Verify that the first link has non-empty summary, url and
        # description.
        ok_(links[0].summary)
        ok_(links[0].url)
        ok_(links[0].description)