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


Python Api.top_level方法代码示例

本文整理汇总了Python中tastypie.api.Api.top_level方法的典型用法代码示例。如果您正苦于以下问题:Python Api.top_level方法的具体用法?Python Api.top_level怎么用?Python Api.top_level使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tastypie.api.Api的用法示例。


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

示例1: test_custom_api_serializer

# 需要导入模块: from tastypie.api import Api [as 别名]
# 或者: from tastypie.api.Api import top_level [as 别名]
    def test_custom_api_serializer(self):
        """Confirm that an Api can use a custom serializer"""

        # Origin: https://github.com/django-tastypie/django-tastypie/pull/817

        class JSONSerializer(Serializer):
            formats = ('json', )

        api = Api(serializer_class=JSONSerializer)
        api.register(NoteResource())

        request = HttpRequest()
        request.META = {'HTTP_ACCEPT': 'text/javascript'}

        resp = api.top_level(request)
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp['content-type'], 'application/json',
                         msg="Expected application/json response but received %s" % resp['content-type'])

        request = HttpRequest()
        request.META = {'HTTP_ACCEPT': 'application/xml'}

        resp = api.top_level(request)
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp['content-type'], 'application/json',
                         msg="Expected application/json response but received %s" % resp['content-type'])
开发者ID:Adusei,项目名称:django-tastypie,代码行数:28,代码来源:api.py

示例2: test_top_level_jsonp

# 需要导入模块: from tastypie.api import Api [as 别名]
# 或者: from tastypie.api.Api import top_level [as 别名]
    def test_top_level_jsonp(self):
        api = Api()
        api.register(NoteResource())
        api.register(UserResource())
        request = HttpRequest()
        request.META = {"HTTP_ACCEPT": "text/javascript"}
        request.GET = {"callback": "foo"}

        resp = api.top_level(request)
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp["content-type"].split(";")[0], "text/javascript")
        self.assertEqual(
            resp.content.decode("utf-8"),
            'foo({"notes": {"list_endpoint": "/api/v1/notes/", "schema": "/api/v1/notes/schema/"}, "users": {"list_endpoint": "/api/v1/users/", "schema": "/api/v1/users/schema/"}})',
        )

        request = HttpRequest()
        request.META = {"HTTP_ACCEPT": "text/javascript"}
        request.GET = {"callback": ""}

        try:
            resp = api.top_level(request)
            self.fail("Broken callback didn't fail!")
        except BadRequest:
            # Regression: We expect this, which is fine, but this used to
            #             be an import error.
            pass
开发者ID:nim65s,项目名称:django-tastypie,代码行数:29,代码来源:api.py

示例3: test_top_level_include_schema_content

# 需要导入模块: from tastypie.api import Api [as 别名]
# 或者: from tastypie.api.Api import top_level [as 别名]
    def test_top_level_include_schema_content(self):
        api = Api()

        note_resource = NoteResource()
        user_resource = UserResource()

        api.register(note_resource)
        api.register(user_resource)

        request = HttpRequest()
        request.GET = {'fullschema': 'true'}

        resp = api.top_level(request)
        self.assertEqual(resp.status_code, 200)

        content = json.loads(resp.content.decode('utf-8'))

        content['notes']['schema'] = adjust_schema(content['notes']['schema'])
        content['users']['schema'] = adjust_schema(content['users']['schema'])

        dummy_request = HttpRequest()
        dummy_request.method = 'GET'

        notes_schema = adjust_schema(json.loads(note_resource.get_schema(dummy_request).content.decode('utf-8')))
        user_schema = adjust_schema(json.loads(user_resource.get_schema(dummy_request).content.decode('utf-8')))

        self.assertEqual(content['notes']['list_endpoint'], '/api/v1/notes/')
        self.assertEqual(content['notes']['schema'], notes_schema)

        self.assertEqual(content['users']['list_endpoint'], '/api/v1/users/')
        self.assertEqual(content['users']['schema'], user_schema)
开发者ID:Adusei,项目名称:django-tastypie,代码行数:33,代码来源:api.py

示例4: test_top_level

# 需要导入模块: from tastypie.api import Api [as 别名]
# 或者: from tastypie.api.Api import top_level [as 别名]
 def test_top_level(self):
     api = Api()
     api.register(NoteResource())
     api.register(UserResource())
     request = HttpRequest()
     
     resp = api.top_level(request)
     self.assertEqual(resp.status_code, 200)
     self.assertEqual(resp.content, '{"notes": "/api/v1/notes/", "users": "/api/v1/users/"}')
开发者ID:codysoyland,项目名称:django-tastypie,代码行数:11,代码来源:api.py

示例5: test_top_level

# 需要导入模块: from tastypie.api import Api [as 别名]
# 或者: from tastypie.api.Api import top_level [as 别名]
    def test_top_level(self):
        api = Api()
        api.register(NoteResource())
        api.register(UserResource())
        request = HttpRequest()

        resp = api.top_level(request)
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp.content.decode('utf-8'), '{"notes": {"list_endpoint": "/api/v1/notes/", "schema": "/api/v1/notes/schema/"}, "users": {"list_endpoint": "/api/v1/users/", "schema": "/api/v1/users/schema/"}}')
开发者ID:Adusei,项目名称:django-tastypie,代码行数:11,代码来源:api.py

示例6: test_top_level_jsonp

# 需要导入模块: from tastypie.api import Api [as 别名]
# 或者: from tastypie.api.Api import top_level [as 别名]
    def test_top_level_jsonp(self):
        api = Api()
        api.register(NoteResource())
        api.register(UserResource())
        request = HttpRequest()
        request.META = {'HTTP_ACCEPT': 'text/javascript'}
        request.GET = {'callback': 'foo'}

        resp = api.top_level(request)
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp['content-type'].split(';')[0], 'text/javascript')
        self.assertEqual(resp.content.decode('utf-8'), 'foo({"notes": {"list_endpoint": "/api/v1/notes/", "schema": "/api/v1/notes/schema/"}, "users": {"list_endpoint": "/api/v1/users/", "schema": "/api/v1/users/schema/"}})')

        request = HttpRequest()
        request.META = {'HTTP_ACCEPT': 'text/javascript'}
        request.GET = {'callback': ''}

        # Regression: We expect this, which is fine, but this used to
        #             be an import error.
        with self.assertRaises(BadRequest):
            api.top_level(request)
开发者ID:Adusei,项目名称:django-tastypie,代码行数:23,代码来源:api.py

示例7: test_jsonp_not_on_by_default

# 需要导入模块: from tastypie.api import Api [as 别名]
# 或者: from tastypie.api.Api import top_level [as 别名]
    def test_jsonp_not_on_by_default(self):
        api = Api()
        api.register(NoteResource())
        api.register(UserResource())
        request = HttpRequest()
        request.META = {'HTTP_ACCEPT': 'text/javascript'}
        request.GET = {'callback': 'foo'}

        resp = api.top_level(request)
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp['content-type'].split(';')[0], 'application/json')
        self.assertFalse("foo" in resp.content.decode('utf-8'))
开发者ID:Fitblip,项目名称:django-tastypie,代码行数:14,代码来源:api.py

示例8: test_top_level_jsonp

# 需要导入模块: from tastypie.api import Api [as 别名]
# 或者: from tastypie.api.Api import top_level [as 别名]
    def test_top_level_jsonp(self):
        api = Api()
        api.register(NoteResource())
        api.register(UserResource())
        request = HttpRequest()
        request.META = {"HTTP_ACCEPT": "text/javascript"}
        request.GET = {"callback": "foo"}

        resp = api.top_level(request)
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp["content-type"].split(";")[0], "text/javascript")
        self.assertEqual(
            resp.content,
            'foo({"notes": {"list_endpoint": "/api/v1/notes/", "schema": "/api/v1/notes/schema/"}, "users": {"list_endpoint": "/api/v1/users/", "schema": "/api/v1/users/schema/"}})',
        )
开发者ID:novel,项目名称:django-tastypie,代码行数:17,代码来源:api.py


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