django.utils.six.moves.urllib.parse.parse_qs

Here are the examples of the python api django.utils.six.moves.urllib.parse.parse_qs taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

9 Examples 7

Example 1

Project: reviewboard
Source File: paginator.py
View license
    def _add_query_params(self, url, new_query_params):
        """Adds query parameters onto the given URL."""
        scheme, netloc, path, query_string, fragment = urlsplit(url)
        query_params = parse_qs(query_string)
        query_params.update(new_query_params)
        new_query_string = urlencode(
            [
                (key, value)
                for key, value in sorted(six.iteritems(query_params),
                                         key=lambda i: i[0])
            ],
            doseq=True)

        return urlunsplit((scheme, netloc, path, new_query_string, fragment))

Example 2

Project: reviewboard
Source File: tests.py
View license
    def test_construct_with_start(self):
        """Testing APIPaginator construction with start=<value>"""
        url = 'http://example.com/api/list/?foo=1'
        paginator = DummyAPIPaginator(None, url, start=10)

        parts = urlsplit(paginator.url)
        query_params = parse_qs(parts[3])

        self.assertEqual(query_params['foo'], ['1'])
        self.assertEqual(query_params['start'], ['10'])

Example 3

Project: reviewboard
Source File: tests.py
View license
    def test_construct_with_per_page(self):
        """Testing APIPaginator construction with per_page=<value>"""
        url = 'http://example.com/api/list/?foo=1'
        paginator = DummyAPIPaginator(None, url, per_page=10)

        parts = urlsplit(paginator.url)
        query_params = parse_qs(parts[3])

        self.assertEqual(query_params['foo'], ['1'])
        self.assertEqual(query_params['per-page'], ['10'])

Example 4

Project: wagtail
Source File: pagination.py
View license
def replace_page_in_query(query, page_number, page_key=DEFAULT_PAGE_KEY):
    """
    Replaces ``page_key`` from query string with ``page_number``.

    >>> replace_page_in_query("p=1&key=value", 2)
    'p=2&key=value'
    >>> replace_page_in_query("p=1&key=value", None)
    'key=value'
    """
    getvars = parse_qs(query)
    if page_number is None:
        getvars.pop(page_key, None)
    else:
        getvars[page_key] = page_number
    return urlencode(getvars, True)

Example 5

Project: django-oscar-paypal
Source File: facade_tests.py
View license
    def _get_paypal_params(self):
        return parse_qs(self.mocked_post.call_args[0][1])

Example 6

Project: plata
Source File: test_views.py
View license
    def test_07_paypal_ipn(self):
        """Test PayPal Instant Payment Notification handler"""
        paypal_ipn_data = {
            'txn_id': '123456789',
            'invoice': 'Order-1-1',
            'mc_currency': 'CHF',
            'mc_gross': '1234',
            'payment_status': 'Completed',
            'last_name': u'H\xe5konsen',
        }

        from plata.payment.modules import paypal

        def mock_urlopen(*args, **kwargs):
            qs = six.moves.urllib.parse.parse_qs(args[1])
            if not six.PY3:
                # Fix doubly encoded UTF-8
                # Thanks, http://stackoverflow.com/a/1177542
                qs = {
                    k: [
                        val.encode('raw_unicode_escape').decode('utf8')
                        for val in v
                    ] for k, v in qs.items()
                }

            self.assertEqual(qs['cmd'][0], '_notify-validate')
            for k, v in paypal_ipn_data.items():
                self.assertEqual('%s' % qs[k][0], v)
            s = BytesIO(b'VERIFIED')
            return s
        paypal.urlopen = mock_urlopen

        product = self.create_product()
        product.stock_transactions.create(
            type=StockTransaction.PURCHASE, change=10)
        self.client.post(product.get_absolute_url(), {
            'quantity': 5,
        })

        response = self.client.post('/confirmation/', {
            'terms_and_conditions': True,
            'payment_method': 'paypal',
        })
        self.assertContains(response, 'sandbox')

        self.assertEqual(StockTransaction.objects.count(), 2)
        self.assertEqual(Order.objects.count(), 1)
        self.assertEqual(OrderPayment.objects.count(), 1)

        self.assertContains(
            self.client.post('/payment/paypal/ipn/', paypal_ipn_data),
            'Ok'
        )

        order = Order.objects.get(pk=1)
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            self.assertTrue(order.is_paid())
            self.assertEqual(len(w), 1)
            self.assertTrue(
                'Order.is_paid() has been deprecated' in str(w[-1]))

        self.assertEqual(
            set((
                StockTransaction.PURCHASE,
                StockTransaction.SALE,
                StockTransaction.PAYMENT_PROCESS_RESERVATION,
            )),
            set(StockTransaction.objects.values_list('type', flat=True)))

Example 7

Project: plata
Source File: test_views.py
View license
    def test_07_paypal_ipn(self):
        """Test PayPal Instant Payment Notification handler"""
        paypal_ipn_data = {
            'txn_id': '123456789',
            'invoice': 'Order-1-1',
            'mc_currency': 'CHF',
            'mc_gross': '1234',
            'payment_status': 'Completed',
            'last_name': u'H\xe5konsen',
        }

        from plata.payment.modules import paypal

        def mock_urlopen(*args, **kwargs):
            qs = six.moves.urllib.parse.parse_qs(args[1])
            if not six.PY3:
                # Fix doubly encoded UTF-8
                # Thanks, http://stackoverflow.com/a/1177542
                qs = {
                    k: [
                        val.encode('raw_unicode_escape').decode('utf8')
                        for val in v
                    ] for k, v in qs.items()
                }

            self.assertEqual(qs['cmd'][0], '_notify-validate')
            for k, v in paypal_ipn_data.items():
                self.assertEqual('%s' % qs[k][0], v)
            s = BytesIO(b'VERIFIED')
            return s
        paypal.urlopen = mock_urlopen

        product = self.create_product()
        product.stock_transactions.create(
            type=StockTransaction.PURCHASE, change=10)
        self.client.post(product.get_absolute_url(), {
            'quantity': 5,
        })

        response = self.client.post('/confirmation/', {
            'terms_and_conditions': True,
            'payment_method': 'paypal',
        })
        self.assertContains(response, 'sandbox')

        self.assertEqual(StockTransaction.objects.count(), 2)
        self.assertEqual(Order.objects.count(), 1)
        self.assertEqual(OrderPayment.objects.count(), 1)

        self.assertContains(
            self.client.post('/payment/paypal/ipn/', paypal_ipn_data),
            'Ok'
        )

        order = Order.objects.get(pk=1)
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            self.assertTrue(order.is_paid())
            self.assertEqual(len(w), 1)
            self.assertTrue(
                'Order.is_paid() has been deprecated' in str(w[-1]))

        self.assertEqual(
            set((
                StockTransaction.PURCHASE,
                StockTransaction.SALE,
                StockTransaction.PAYMENT_PROCESS_RESERVATION,
            )),
            set(StockTransaction.objects.values_list('type', flat=True)))

Example 8

Project: django-disqus
Source File: tests.py
View license
    def test__get_request_if_http_method_is_get(self):

        attr_ = {'user_api_key': ['spam'],
                 'developer_api_key': ['ham'],
                 'api_version': ['1.1']
                 }

        for api_method, http_method in DisqusClient.METHODS.items():
            if http_method == "GET":

                url = self.client.api_url % api_method

                request_params = self.client._get_request(
                    url, http_method,
                    **self.attr)
                request_no_params = self.client._get_request(url, http_method)

                self.assertEqual(request_params.get_host(), 'disqus.com')
                self.assertEqual(request_no_params.get_host(), 'disqus.com')

                # check actual request method
                self.assertEqual(request_params.get_method(), http_method)
                self.assertEqual(request_no_params.get_method(), http_method)

                # getting url's query string
                # since parameters passed to api_url from a dict, mean randomly

                url_parsed1 = urlparse(request_params.get_full_url())
                qs_params = parse_qs(url_parsed1.query)

                url_parsed2 = urlparse(request_no_params.get_full_url())
                qs_no_params = parse_qs(url_parsed2.query)

                self.assertEqual(qs_params, attr_)
                # hardcoded in api_url
                self.assertEqual(qs_no_params, {'api_version': ['1.1']})

Example 9

Project: django-disqus
Source File: tests.py
View license
    def test__get_request_if_http_method_is_post(self):

        attr_ = {'user_api_key': ['spam'], 'developer_api_key': ['ham']}

        for api_method, http_method in DisqusClient.METHODS.items():
            if http_method == "POST":

                url = self.client.api_url % api_method

                request_params = self.client._get_request(url,
                                                          http_method,
                                                          **self.attr)
                request_no_params = self.client._get_request(url, http_method)

                self.assertEqual(request_params.get_host(), 'disqus.com')
                self.assertEqual(request_no_params.get_host(), 'disqus.com')

                self.assertEqual(request_params.get_method(), http_method)
                self.assertEqual(request_no_params.get_method(), http_method)

                qs_params = parse_qs(request_params.data)
                qs_no_params = parse_qs(request_no_params.data)

                self.assertEqual(qs_params, attr_)
                self.assertEqual(qs_no_params, {})