当前位置: 首页>>代码示例>>Python>>正文


Python test.CoreAPIClient类代码示例

本文整理汇总了Python中rest_framework.test.CoreAPIClient的典型用法代码示例。如果您正苦于以下问题:Python CoreAPIClient类的具体用法?Python CoreAPIClient怎么用?Python CoreAPIClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CoreAPIClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_download_response

    def test_download_response(self):
        client = CoreAPIClient()
        schema = client.get('http://api.example.com/')

        data = client.action(schema, ['response', 'download'])
        assert data.basename == 'download.png'
        assert data.read() == b'some file content'
开发者ID:patrickdizon,项目名称:django-rest-framework,代码行数:7,代码来源:test_api_client.py

示例2: test_text_response

    def test_text_response(self):
        client = CoreAPIClient()
        schema = client.get('http://api.example.com/')

        data = client.action(schema, ['response', 'text'])

        expected = '123'
        assert data == expected
开发者ID:patrickdizon,项目名称:django-rest-framework,代码行数:8,代码来源:test_api_client.py

示例3: test_query_params_with_multiple_values

 def test_query_params_with_multiple_values(self):
     client = CoreAPIClient()
     schema = client.get('http://api.example.com/')
     data = client.action(schema, ['location', 'query'], params={'example': [1, 2, 3]})
     expected = {
         'method': 'GET',
         'query_params': {'example': ['1', '2', '3']}
     }
     assert data == expected
开发者ID:patrickdizon,项目名称:django-rest-framework,代码行数:9,代码来源:test_api_client.py

示例4: test_query_params

 def test_query_params(self):
     client = CoreAPIClient()
     schema = client.get('http://api.example.com/')
     data = client.action(schema, ['location', 'query'], params={'example': 123})
     expected = {
         'method': 'GET',
         'query_params': {'example': '123'}
     }
     assert data == expected
开发者ID:patrickdizon,项目名称:django-rest-framework,代码行数:9,代码来源:test_api_client.py

示例5: test_urlencoded_encoding_in_body

 def test_urlencoded_encoding_in_body(self):
     client = CoreAPIClient()
     schema = client.get('http://api.example.com/')
     data = client.action(schema, ['encoding', 'urlencoded-body'], params={'example': {'foo': 123, 'bar': True}})
     expected = {
         'method': 'POST',
         'content_type': 'application/x-www-form-urlencoded',
         'query_params': {},
         'data': {'foo': '123', 'bar': 'true'},
         'files': {}
     }
     assert data == expected
开发者ID:patrickdizon,项目名称:django-rest-framework,代码行数:12,代码来源:test_api_client.py

示例6: test_urlencoded_encoding_multiple_values

 def test_urlencoded_encoding_multiple_values(self):
     client = CoreAPIClient()
     schema = client.get('http://api.example.com/')
     data = client.action(schema, ['encoding', 'urlencoded'], params={'example': [1, 2, 3]})
     expected = {
         'method': 'POST',
         'content_type': 'application/x-www-form-urlencoded',
         'query_params': {},
         'data': {'example': ['1', '2', '3']},
         'files': {}
     }
     assert data == expected
开发者ID:patrickdizon,项目名称:django-rest-framework,代码行数:12,代码来源:test_api_client.py

示例7: test_body_params

 def test_body_params(self):
     client = CoreAPIClient()
     schema = client.get('http://api.example.com/')
     data = client.action(schema, ['location', 'body'], params={'example': 123})
     expected = {
         'method': 'POST',
         'content_type': 'application/json',
         'query_params': {},
         'data': 123,
         'files': {}
     }
     assert data == expected
开发者ID:patrickdizon,项目名称:django-rest-framework,代码行数:12,代码来源:test_api_client.py

示例8: test_api_client

 def test_api_client(self):
     client = CoreAPIClient()
     schema = client.get('http://api.example.com/')
     assert schema.title == 'Example API'
     assert schema.url == 'https://api.example.com/'
     assert schema['simple_link'].description == 'example link'
     assert schema['location']['query'].fields[0].schema.description == 'example field'
     data = client.action(schema, ['simple_link'])
     expected = {
         'method': 'GET',
         'query_params': {}
     }
     assert data == expected
开发者ID:patrickdizon,项目名称:django-rest-framework,代码行数:13,代码来源:test_api_client.py

示例9: test_raw_upload_explicit_content_type

    def test_raw_upload_explicit_content_type(self):
        from coreapi.utils import File

        client = CoreAPIClient()
        schema = client.get('http://api.example.com/')

        example = File('example.txt', '123', 'text/html')
        data = client.action(schema, ['encoding', 'raw_upload'], params={'example': example})

        expected = {
            'method': 'POST',
            'files': {'file': {'name': 'example.txt', 'content': '123'}},
            'content_type': 'text/html'
        }
        assert data == expected
开发者ID:patrickdizon,项目名称:django-rest-framework,代码行数:15,代码来源:test_api_client.py

示例10: test_multipart_encoding_no_file

    def test_multipart_encoding_no_file(self):
        # When no file is included, multipart encoding should still be used.
        client = CoreAPIClient()
        schema = client.get('http://api.example.com/')

        data = client.action(schema, ['encoding', 'multipart'], params={'example': 123})

        expected = {
            'method': 'POST',
            'content_type': 'multipart/form-data',
            'query_params': {},
            'data': {'example': '123'},
            'files': {}
        }
        assert data == expected
开发者ID:patrickdizon,项目名称:django-rest-framework,代码行数:15,代码来源:test_api_client.py

示例11: test_multipart_encoding_in_body

    def test_multipart_encoding_in_body(self):
        from coreapi.utils import File

        client = CoreAPIClient()
        schema = client.get('http://api.example.com/')

        example = {'foo': File(name='example.txt', content='123'), 'bar': 'abc'}
        data = client.action(schema, ['encoding', 'multipart-body'], params={'example': example})

        expected = {
            'method': 'POST',
            'content_type': 'multipart/form-data',
            'query_params': {},
            'data': {'bar': 'abc'},
            'files': {'foo': {'name': 'example.txt', 'content': '123'}}
        }
        assert data == expected
开发者ID:patrickdizon,项目名称:django-rest-framework,代码行数:17,代码来源:test_api_client.py

示例12: test_raw_upload

    def test_raw_upload(self):
        client = CoreAPIClient()
        schema = client.get('http://api.example.com/')

        with tempfile.NamedTemporaryFile(delete=False) as temp:
            temp.write(b'example file content')
            temp.flush()
            temp.seek(0)

            name = os.path.basename(temp.name)
            data = client.action(schema, ['encoding', 'raw_upload'], params={'example': temp})

        expected = {
            'method': 'POST',
            'files': {'file': {'name': name, 'content': 'example file content'}},
            'content_type': 'application/octet-stream'
        }
        assert data == expected
开发者ID:patrickdizon,项目名称:django-rest-framework,代码行数:18,代码来源:test_api_client.py

示例13: test_multipart_encoding_string_file_content

    def test_multipart_encoding_string_file_content(self):
        # Test for `coreapi.utils.File` support.
        from coreapi.utils import File

        client = CoreAPIClient()
        schema = client.get('http://api.example.com/')

        example = File(name='example.txt', content='123')
        data = client.action(schema, ['encoding', 'multipart'], params={'example': example})

        expected = {
            'method': 'POST',
            'content_type': 'multipart/form-data',
            'query_params': {},
            'data': {},
            'files': {'example': {'name': 'example.txt', 'content': '123'}}
        }
        assert data == expected
开发者ID:patrickdizon,项目名称:django-rest-framework,代码行数:18,代码来源:test_api_client.py

示例14: test_multipart_encoding

    def test_multipart_encoding(self):
        client = CoreAPIClient()
        schema = client.get('http://api.example.com/')

        with tempfile.NamedTemporaryFile() as temp:
            temp.write(b'example file content')
            temp.flush()
            temp.seek(0)

            name = os.path.basename(temp.name)
            data = client.action(schema, ['encoding', 'multipart'], params={'example': temp})

        expected = {
            'method': 'POST',
            'content_type': 'multipart/form-data',
            'query_params': {},
            'data': {},
            'files': {'example': {'name': name, 'content': 'example file content'}}
        }
        assert data == expected
开发者ID:patrickdizon,项目名称:django-rest-framework,代码行数:20,代码来源:test_api_client.py

示例15: test_session_headers

 def test_session_headers(self):
     client = CoreAPIClient()
     client.session.headers.update({'X-Custom-Header': 'foo'})
     schema = client.get('http://api.example.com/')
     data = client.action(schema, ['headers'])
     assert data['headers']['X-CUSTOM-HEADER'] == 'foo'
开发者ID:patrickdizon,项目名称:django-rest-framework,代码行数:6,代码来源:test_api_client.py


注:本文中的rest_framework.test.CoreAPIClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。