예제 #1
0
    def test_post_ajax(self):
        """
        POSTing with AJAX should return success/error JSON.
        """

        with self.activate("en-US"):
            # test AJAX POST with valid form data
            request = self.factory.post(self.url, self.post_data, HTTP_X_REQUESTED_WITH="XMLHttpRequest")

            response = views.process_partnership_form(request, self.template, self.view)

            # decode JSON response
            resp_data = simplejson.loads(response.content)

            self.assertEqual(resp_data["msg"], "ok")
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response._headers["content-type"][1], "application/json")

            # test AJAX POST with invalid form data
            request = self.factory.post(self.url, self.invalid_post_data, HTTP_X_REQUESTED_WITH="XMLHttpRequest")

            response = views.process_partnership_form(request, self.template, self.view)

            # decode JSON response
            resp_data = simplejson.loads(response.content)

            self.assertEqual(resp_data["msg"], "Form invalid")
            self.assertEqual(response.status_code, 400)
            self.assertTrue("email" in resp_data["errors"])
            self.assertEqual(response._headers["content-type"][1], "application/json")
예제 #2
0
    def test_post(self):
        """
        POSTing without AJAX should redirect to self.url on success and
        render self.template on error.
        """

        with self.activate('en-US'):
            # test non-AJAX POST with valid form data
            request = self.factory.post(self.url, self.post_data)

            response = views.process_partnership_form(request, self.template,
                                                      self.view)

            # should redirect to success URL
            self.assertEqual(response.status_code, 302)
            self.assertIn(self.url, response._headers['location'][1])
            self.assertIn('text/html', response._headers['content-type'][1])

            # test non-AJAX POST with invalid form data
            request = self.factory.post(self.url, self.invalid_post_data)

            # locale is not getting set via self.activate above...?
            request.locale = 'en-US'

            response = views.process_partnership_form(request, self.template,
                                                      self.view)

            self.assertEqual(response.status_code, 200)
            self.assertIn('text/html', response._headers['content-type'][1])
예제 #3
0
    def test_post(self):
        """
        POSTing without AJAX should redirect to self.url on success and
        render self.template on error.
        """

        with self.activate('en-US'):
            # test non-AJAX POST with valid form data
            request = self.factory.post(self.url, self.post_data)

            response = views.process_partnership_form(request, self.template,
                                                      self.view)

            # should redirect to success URL
            self.assertEqual(response.status_code, 302)
            self.assertIn(self.url, response._headers['location'][1])
            self.assertIn('text/html', response._headers['content-type'][1])

            # test non-AJAX POST with invalid form data
            request = self.factory.post(self.url, self.invalid_post_data)

            # locale is not getting set via self.activate above...?
            request.locale = 'en-US'

            response = views.process_partnership_form(request, self.template,
                                                      self.view)

            self.assertEqual(response.status_code, 200)
            self.assertIn('text/html', response._headers['content-type'][1])
예제 #4
0
    def test_post_ajax_error_xss(self):
        """
        POSTing with AJAX should return sanitized error messages.
        Bug 945845.
        """
        with self.activate('en-US'):
            # test AJAX POST with valid form data
            post_data = self.post_data.copy()
            post_data['interest'] = '"><img src=x onerror=alert(1);>'
            escaped_data = '"&gt;&lt;img src=x onerror=alert(1);&gt;'
            request = self.factory.post(self.url, post_data,
                                        HTTP_X_REQUESTED_WITH='XMLHttpRequest')

            response = views.process_partnership_form(request, self.template,
                                                      self.view)

            # decode JSON response
            resp_data = json.loads(response.content)

            self.assertEqual(resp_data['msg'], 'Form invalid')
            self.assertEqual(response.status_code, 400)
            self.assertTrue(post_data['interest'] not in resp_data['errors']['interest'][0])
            self.assertTrue(escaped_data in resp_data['errors']['interest'][0])
            self.assertEqual(response._headers['content-type'][1],
                             'application/json')
예제 #5
0
    def test_post_ajax_error_xss(self):
        """
        POSTing with AJAX should return sanitized error messages.
        Bug 945845.
        """
        with self.activate('en-US'):
            # test AJAX POST with valid form data
            post_data = self.post_data.copy()
            post_data['interest'] = '"><img src=x onerror=alert(1);>'
            escaped_data = '"&gt;&lt;img src=x onerror=alert(1);&gt;'
            request = self.factory.post(self.url, post_data,
                                        HTTP_X_REQUESTED_WITH='XMLHttpRequest')

            response = views.process_partnership_form(request, self.template,
                                                      self.view)

            # decode JSON response
            resp_data = json.loads(response.content)

            self.assertEqual(resp_data['msg'], 'Form invalid')
            self.assertEqual(response.status_code, 400)
            self.assertTrue(post_data['interest'] not in resp_data['errors']['interest'][0])
            self.assertTrue(escaped_data in resp_data['errors']['interest'][0])
            self.assertEqual(response._headers['content-type'][1],
                             'application/json')
예제 #6
0
    def test_post_ajax(self, mock_email_message, mock_render_to_string):
        """
        POSTing with AJAX should return success/error JSON.
        """

        with self.activate('en-US'):
            mock_send = mock_email_message.return_value.send

            # test AJAX POST with valid form data
            request = self.factory.post(self.url, self.post_data,
                                        HTTP_X_REQUESTED_WITH='XMLHttpRequest')

            response = views.process_partnership_form(request, self.template,
                                                      self.view)

            # decode JSON response
            resp_data = json.loads(response.content)

            self.assertEqual(response.status_code, 200)
            self.assertEqual(response._headers['content-type'][1],
                             'application/json')

            # make sure email was sent
            mock_send.assert_called_once_with()

            # make sure email values are correct
            mock_email_message.assert_called_once_with(
                views.PARTNERSHIPS_EMAIL_SUBJECT,
                'rendered',
                views.PARTNERSHIPS_EMAIL_FROM,
                views.PARTNERSHIPS_EMAIL_TO)

            # test AJAX POST with invalid form data
            request = self.factory.post(self.url, self.invalid_post_data,
                                        HTTP_X_REQUESTED_WITH='XMLHttpRequest')

            response = views.process_partnership_form(request, self.template,
                                                      self.view)

            # decode JSON response
            resp_data = json.loads(response.content)

            self.assertEqual(resp_data['msg'], 'Form invalid')
            self.assertEqual(response.status_code, 400)
            self.assertTrue('email' in resp_data['errors'])
            self.assertEqual(response._headers['content-type'][1],
                             'application/json')
예제 #7
0
    def test_post_ajax(self, mock_email_message, mock_render_to_string):
        """
        POSTing with AJAX should return success/error JSON.
        """

        with self.activate('en-US'):
            mock_send = mock_email_message.return_value.send

            # test AJAX POST with valid form data
            request = self.factory.post(self.url, self.post_data,
                                        HTTP_X_REQUESTED_WITH='XMLHttpRequest')

            response = views.process_partnership_form(request, self.template,
                                                      self.view)

            # decode JSON response
            resp_data = json.loads(response.content)

            self.assertEqual(response.status_code, 200)
            self.assertEqual(response._headers['content-type'][1],
                             'application/json')

            # make sure email was sent
            mock_send.assert_called_once_with()

            # make sure email values are correct
            mock_email_message.assert_called_once_with(
                views.PARTNERSHIPS_EMAIL_SUBJECT,
                'rendered',
                views.PARTNERSHIPS_EMAIL_FROM,
                views.PARTNERSHIPS_EMAIL_TO)

            # test AJAX POST with invalid form data
            request = self.factory.post(self.url, self.invalid_post_data,
                                        HTTP_X_REQUESTED_WITH='XMLHttpRequest')

            response = views.process_partnership_form(request, self.template,
                                                      self.view)

            # decode JSON response
            resp_data = json.loads(response.content)

            self.assertEqual(resp_data['msg'], 'Form invalid')
            self.assertEqual(response.status_code, 400)
            self.assertTrue('email' in resp_data['errors'])
            self.assertEqual(response._headers['content-type'][1],
                             'application/json')
예제 #8
0
    def test_get(self):
        """
        A GET request should simply return a 200.
        """

        request = self.factory.get(self.url)
        request.locale = "en-US"
        response = views.process_partnership_form(request, self.template, self.view)
        self.assertEqual(response.status_code, 200)
예제 #9
0
    def test_get(self):
        """
        A GET request should simply return a 200.
        """

        request = self.factory.get(self.url)
        request.locale = 'en-US'
        response = views.process_partnership_form(request, self.template,
                                                  self.view)
        self.assertEqual(response.status_code, 200)
예제 #10
0
    def test_post_ajax(self):
        """
        POSTing with AJAX should return success/error JSON.
        """

        with self.activate('en-US'):
            # test AJAX POST with valid form data
            request = self.factory.post(self.url,
                                        self.post_data,
                                        HTTP_X_REQUESTED_WITH='XMLHttpRequest')

            response = views.process_partnership_form(request, self.template,
                                                      self.view)

            # decode JSON response
            resp_data = json.loads(response.content)

            self.assertEqual(resp_data['msg'], 'ok')
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response._headers['content-type'][1],
                             'application/json')
            ok_(self.requests_mock.called)

            # test AJAX POST with invalid form data
            request = self.factory.post(self.url,
                                        self.invalid_post_data,
                                        HTTP_X_REQUESTED_WITH='XMLHttpRequest')

            response = views.process_partnership_form(request, self.template,
                                                      self.view)

            # decode JSON response
            resp_data = json.loads(response.content)

            self.assertEqual(resp_data['msg'], 'Form invalid')
            self.assertEqual(response.status_code, 400)
            self.assertTrue('email' in resp_data['errors'])
            self.assertEqual(response._headers['content-type'][1],
                             'application/json')
예제 #11
0
    def test_post_ajax(self):
        """
        POSTing with AJAX should return success/error JSON.
        """

        with self.activate('en-US'):
            # test AJAX POST with valid form data
            request = self.factory.post(self.url, self.post_data,
                                        HTTP_X_REQUESTED_WITH='XMLHttpRequest')

            response = views.process_partnership_form(request, self.template,
                                                      self.view)

            # decode JSON response
            resp_data = json.loads(response.content)

            self.assertEqual(resp_data['msg'], 'ok')
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response._headers['content-type'][1],
                             'application/json')
            ok_(self.requests_mock.called)

            # test AJAX POST with invalid form data
            request = self.factory.post(self.url, self.invalid_post_data,
                                        HTTP_X_REQUESTED_WITH='XMLHttpRequest')

            response = views.process_partnership_form(request, self.template,
                                                      self.view)

            # decode JSON response
            resp_data = json.loads(response.content)

            self.assertEqual(resp_data['msg'], 'Form invalid')
            self.assertEqual(response.status_code, 400)
            self.assertTrue('email' in resp_data['errors'])
            self.assertEqual(response._headers['content-type'][1],
                             'application/json')
예제 #12
0
파일: views.py 프로젝트: imclab/bedrock
def firefox_partners(request):
    # If the current locale isn't in our list, return the en-US value
    press_locale = request.locale if (request.locale in LOCALE_FXOS_HEADLINES) else 'en-US'

    template_vars = {
        'locale_headline_url': LOCALE_FXOS_HEADLINES[press_locale]['url'],
        'locale_headline_title': LOCALE_FXOS_HEADLINES[press_locale]['title'],
        'js_common': JS_COMMON,
        'js_mobile': JS_MOBILE,
        'js_desktop': JS_DESKTOP,
    }

    form_kwargs = {'interest_set': 'fx'}

    return process_partnership_form(request, 'firefox/partners/index.html', 'firefox.partners.index', template_vars, form_kwargs)
예제 #13
0
def firefox_partners(request):
    # If the current locale isn't in our list, return the en-US value
    press_locale = request.locale if (request.locale in LOCALE_FXOS_HEADLINES) else 'en-US'

    template_vars = {
        'locale_headline_url': LOCALE_FXOS_HEADLINES[press_locale]['url'],
        'locale_headline_title': LOCALE_FXOS_HEADLINES[press_locale]['title'],
        'js_common': JS_COMMON,
        'js_mobile': JS_MOBILE,
        'js_desktop': JS_DESKTOP,
    }

    form_kwargs = {'interest_set': 'fx', 'lead_source': 'www.mozilla.org/firefox/partners/'}

    return process_partnership_form(request, 'firefox/partners/index.html', 'firefox.partners.index', template_vars, form_kwargs)
예제 #14
0
def firefox_partners(request):
    # If the current locale isn't in our list, return the en-US value
    press_locale = request.locale if (request.locale in LOCALE_FXOS_HEADLINES) else "en-US"

    template_vars = {
        "locale_headline_url": LOCALE_FXOS_HEADLINES[press_locale]["url"],
        "locale_headline_title": LOCALE_FXOS_HEADLINES[press_locale]["title"],
        "js_common": JS_COMMON,
        "js_mobile": JS_MOBILE,
        "js_desktop": JS_DESKTOP,
    }

    form_kwargs = {"interest_set": "fx", "lead_source": "www.mozilla.org/firefox/partners/"}

    return process_partnership_form(
        request, "firefox/partners/index.html", "firefox.partners.index", template_vars, form_kwargs
    )
예제 #15
0
파일: views.py 프로젝트: elin-moco/bedrock
def firefox_partners(request):
    # If the current locale isn't in our list, return the en-US value
    # MWC announcement
    locale_os_url = LOCALE_OS_URLS.get(request.locale, LOCALE_OS_URLS['en-US'])
    # Firefox OS 1.0 release
    locale_os_release_url = LOCALE_OS_RELEASE_URLS.get(request.locale, LOCALE_OS_RELEASE_URLS['en-US'])

    template_vars = {
        'locale_headline_url': LOCALE_FXOS_HEADLINES['zh-TW']['url'],
        'locale_headline_title': LOCALE_FXOS_HEADLINES['zh-TW']['title'],
        'js_common': JS_COMMON,
        'js_mobile': JS_MOBILE,
        'js_desktop': JS_DESKTOP,
    }

    form_kwargs = {'interest_set': 'fx'}

    return process_partnership_form(request, 'firefox/partners/index.html', 'firefox.partners.index', template_vars, form_kwargs)
예제 #16
0
    def test_post_ajax_honeypot(self):
        """
        POSTing with AJAX and honeypot should return success JSON.
        """
        with self.activate('en-US'):
            self.post_data['office_fax'] = 'what is this?'
            request = self.factory.post(self.url, self.post_data,
                                        HTTP_X_REQUESTED_WITH='XMLHttpRequest')

            response = views.process_partnership_form(request, self.template,
                                                      self.view)

            # decode JSON response
            resp_data = json.loads(response.content)

            self.assertEqual(resp_data['msg'], 'ok')
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response._headers['content-type'][1],
                             'application/json')
            ok_(not self.requests_mock.called)
예제 #17
0
    def test_post_ajax_honeypot(self):
        """
        POSTing with AJAX and honeypot should return success JSON.
        """
        with self.activate('en-US'):
            self.post_data['office_fax'] = 'what is this?'
            request = self.factory.post(self.url, self.post_data,
                                        HTTP_X_REQUESTED_WITH='XMLHttpRequest')

            response = views.process_partnership_form(request, self.template,
                                                      self.view)

            # decode JSON response
            resp_data = json.loads(response.content)

            self.assertEqual(resp_data['msg'], 'ok')
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response._headers['content-type'][1],
                             'application/json')
            ok_(not self.requests_mock.called)
예제 #18
0
파일: views.py 프로젝트: 6a68/bedrock
def firefox_partners(request):
    # If the current locale isn't in our list, return the en-US value
    # MWC announcement
    locale_os_url = LOCALE_OS_URLS.get(request.locale, LOCALE_OS_URLS["en-US"])
    # Firefox OS 1.0 release
    locale_os_release_url = LOCALE_OS_RELEASE_URLS.get(request.locale, LOCALE_OS_RELEASE_URLS["en-US"])

    template_vars = {
        "locale_os_url": locale_os_url,
        "locale_os_release_url": locale_os_release_url,
        "locale_os_release_active": LOCALE_OS_RELEASE_URLS,
        "js_common": JS_COMMON,
        "js_mobile": JS_MOBILE,
        "js_desktop": JS_DESKTOP,
    }

    form_kwargs = {"interest_set": "fx"}

    return process_partnership_form(
        request, "firefox/partners/index.html", "firefox.partners.index", template_vars, form_kwargs
    )
예제 #19
0
def firefox_partners(request):
    # If the current locale isn't in our list, return the en-US value
    # MWC announcement
    locale_os_url = LOCALE_OS_URLS.get(request.locale, LOCALE_OS_URLS['en-US'])
    # Firefox OS 1.0 release
    locale_os_release_url = LOCALE_OS_RELEASE_URLS.get(
        request.locale, LOCALE_OS_RELEASE_URLS['en-US'])

    template_vars = {
        'locale_os_url': locale_os_url,
        'locale_os_release_url': locale_os_release_url,
        'locale_os_release_active': LOCALE_OS_RELEASE_URLS,
        'js_common': JS_COMMON,
        'js_mobile': JS_MOBILE,
        'js_desktop': JS_DESKTOP,
    }

    form_kwargs = {'interest_set': 'fx'}

    return process_partnership_form(request, 'firefox/partners/index.html',
                                    'firefox.partners.index', template_vars,
                                    form_kwargs)
예제 #20
0
        def _req(form_kwargs):
            request = self.factory.post(self.url, self.post_data)
            views.process_partnership_form(request, self.template,
                                           self.view, {}, form_kwargs)

            return str(mock_render_to_string.call_args[0][1])
예제 #21
0
 def _req(form_kwargs):
     request = self.factory.post(self.url, self.post_data)
     views.process_partnership_form(request, self.template,
                                    self.view, {}, form_kwargs)
     return self.requests_mock.call_args[0][1]['lead_source']
예제 #22
0
 def _req(form_kwargs):
     request = self.factory.post(self.url, self.post_data)
     views.process_partnership_form(request, self.template, self.view,
                                    {}, form_kwargs)
     return self.requests_mock.call_args[0][1]['lead_source']
예제 #23
0
 def _req(form_kwargs):
     with patch('bedrock.mozorg.views.requests.post') as mock:
         request = self.factory.post(self.url, self.post_data)
         views.process_partnership_form(request, self.template,
                                        self.view, {}, form_kwargs)
     return mock.call_args[0][1]['lead_source']
예제 #24
0
        def _req(form_kwargs):
            request = self.factory.post(self.url, self.post_data)
            views.process_partnership_form(request, self.template,
                                           self.view, {}, form_kwargs)

            return str(mock_render_to_string.call_args[0][1])
예제 #25
0
 def _req(form_kwargs):
     with patch('bedrock.mozorg.views.requests.post') as mock:
         request = self.factory.post(self.url, self.post_data)
         views.process_partnership_form(request, self.template,
                                        self.view, {}, form_kwargs)
     return mock.call_args[0][1]['lead_source']