Exemplo n.º 1
0
    def test_make_url(self):
        self.assertEqual(make_url('http://test.com/path', param='value'),
                         'http://test.com/path?param=value')

        self.assertEqual(make_url('http://test.com/path?k=v', param='value'),
                         'http://test.com/path?k=v&param=value')

        self.assertEqual(
            make_url(u'http://тест.рф/path?k=v', param=u'тест'),
            u'http://тест.рф/path?k=v&param=%D1%82%D0%B5%D1%81%D1%82')
Exemplo n.º 2
0
    def test_make_url(self):
        self.assertEqual(
            make_url('http://test.com/path', param='value'),
            'http://test.com/path?param=value'
        )

        self.assertEqual(
            make_url('http://test.com/path?k=v', param='value'),
            'http://test.com/path?k=v&param=value'
        )

        self.assertEqual(
            make_url('http://тест.рф/path?k=v', param='тест'),
            'http://тест.рф/path?k=v&param=%D1%82%D0%B5%D1%81%D1%82'
        )
Exemplo n.º 3
0
    def test_argument_with_invalid_chars(self):
        arg_with_invalid_chars = '≤'.encode('koi8_r') + 'тест'.encode('utf-8')
        response = frontik_test_app.get_page(
            make_url('arguments', param=arg_with_invalid_chars))

        self.assertEqual(response.status_code, 200)
        self.assertEqual(to_unicode(response.content), '{"тест": "тест"}')
Exemplo n.º 4
0
    def test_cp1251_argument(self):
        cp1251_arg = 'тест'.encode('cp1251')
        response = frontik_test_app.get_page(
            make_url('arguments', param=cp1251_arg))

        self.assertEqual(response.status_code, 200)
        self.assertEqual(to_unicode(response.content), '{"тест": "тест"}')
Exemplo n.º 5
0
 def fetch(self, path, query=None, **kwargs):
     """Extends `AsyncHTTPTestCase.fetch` method with `query` kwarg.
     This argument accepts a `dict` of request query parameters that will be encoded
     and added to request path.
     Any additional kwargs will be passed to `AsyncHTTPTestCase.fetch`.
     """
     query = {} if query is None else query
     return super().fetch(make_url(path, **query), **kwargs)
Exemplo n.º 6
0
 def fetch(self, path, query=None, **kwargs):
     """Extends `AsyncHTTPTestCase.fetch` method with `query` kwarg.
     This argument accepts a `dict` of request query parameters that will be encoded
     and added to request path.
     Any additional kwargs will be passed to `AsyncHTTPTestCase.fetch`.
     """
     query = {} if query is None else query
     return super().fetch(make_url(path, **query), **kwargs)
Exemplo n.º 7
0
    def modify_http_client_request(self,
                                   balanced_request: 'BalancedHttpRequest'):
        if self.debug_mode.pass_debug:
            balanced_request.headers[DEBUG_HEADER_NAME] = 'true'

            # debug_timestamp is added to avoid caching of debug responses
            balanced_request.uri = make_url(balanced_request.uri,
                                            debug_timestamp=int(time.time()))

            for header_name in ('Authorization', DEBUG_AUTH_HEADER_NAME):
                authorization = self.request.headers.get(header_name)
                if authorization is not None:
                    balanced_request.headers[header_name] = authorization
Exemplo n.º 8
0
    def modify_http_client_request(self, balanced_request: 'BalancedHttpRequest'):
        balanced_request.headers['x-request-id'] = request_context.get_request_id()

        balanced_request.headers[OUTER_TIMEOUT_MS_HEADER] = f'{balanced_request.request_timeout * 1000:.0f}'

        if self.timeout_checker is not None:
            self.timeout_checker.check(balanced_request)

        if self.debug_mode.pass_debug:
            balanced_request.headers[DEBUG_HEADER_NAME] = 'true'

            # debug_timestamp is added to avoid caching of debug responses
            balanced_request.uri = make_url(balanced_request.uri, debug_timestamp=int(time.time()))

            for header_name in ('Authorization', DEBUG_AUTH_HEADER_NAME):
                authorization = self.request.headers.get(header_name)
                if authorization is not None:
                    balanced_request.headers[header_name] = authorization
Exemplo n.º 9
0
    def test_argument_with_invalid_chars(self):
        arg_with_invalid_chars = '≤'.encode('koi8_r') + 'тест'.encode('utf-8')
        response = frontik_test_app.get_page(make_url('arguments', param=arg_with_invalid_chars))

        self.assertEqual(response.status_code, 200)
        self.assertEqual(to_unicode(response.content), '{"тест": "тест"}')
Exemplo n.º 10
0
    def test_cp1251_argument(self):
        cp1251_arg = 'тест'.encode('cp1251')
        response = frontik_test_app.get_page(make_url('arguments', param=cp1251_arg))

        self.assertEqual(response.status_code, 200)
        self.assertEqual(to_unicode(response.content), '{"тест": "тест"}')
Exemplo n.º 11
0
 def test_unicode_argument(self):
     response = frontik_test_app.get_page(make_url('arguments', param='тест'))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(to_unicode(response.content), '{"тест": "тест"}')
Exemplo n.º 12
0
 def test_unicode_argument(self):
     response = frontik_test_app.get_page(
         make_url('arguments', param='тест'))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(to_unicode(response.content), '{"тест": "тест"}')