• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.to_json函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_reload

 def test_reload(self):
     self.http.respond_to(
         'GET', '/people/1.json', {}, util.to_json(self.arnold, root='person'))
     arnold = self.person.find(1)
     arnold.name = 'someone else'
     arnold.reload()
     self.assertEqual(self.arnold, arnold.attributes)
开发者ID:drwelby,项目名称:pyactiveresource,代码行数:7,代码来源:activeresource_test.py


示例2: test_find_by_id

    def test_find_by_id(self):
        # Return a single person for a find(id=<id>) call
        self.http.respond_to(
            'GET', '/people/1.json', {}, util.to_json(self.arnold, root='person'))

        arnold = self.person.find(1)
        self.assertEqual(self.arnold, arnold.attributes)
开发者ID:drwelby,项目名称:pyactiveresource,代码行数:7,代码来源:activeresource_test.py


示例3: test_set_prefix_source

 def test_set_prefix_source(self):
     self.http.respond_to(
         'GET', '/stores/1/people.json?name=Ralph', {},
         util.to_json([], root='people'))
     self.person.prefix_source = '/stores/${store_id}/'
     nobody = self.person.find(store_id=1, name='Ralph')
     self.assertEqual([], nobody)
开发者ID:drwelby,项目名称:pyactiveresource,代码行数:7,代码来源:activeresource_test.py


示例4: test_find_should_handle_long_query_args

 def test_find_should_handle_long_query_args(self):
     self.http.respond_to(
         'GET', '/people.json?employee_id=12345', {},
         util.to_json([self.arnold], root='people'))
     for int_type in six.integer_types:
         arnold = self.person.find_first(employee_id=int_type(12345))
         self.assertEqual(self.arnold, arnold.attributes)
开发者ID:varesa,项目名称:pyactiveresource,代码行数:7,代码来源:activeresource_test.py


示例5: test_get

 def test_get(self):
     person = util.to_json({'id': 1, 'name': 'Matz'}, root='person')
     self.http.respond_to(
         'GET', 'http://localhost/people/1.json', {}, person)
     self.connection.format = formats.JSONFormat
     response = self.connection.get('/people/1.json')
     self.assertEqual(response['name'], 'Matz')
开发者ID:varesa,项目名称:pyactiveresource,代码行数:7,代码来源:connection_test.py


示例6: test_find_should_handle_dictionary_query_args_with_array_value

 def test_find_should_handle_dictionary_query_args_with_array_value(self):
     query = urllib.urlencode({'vars[key][]': ['val1', 'val2']}, True)
     self.http.respond_to(
         'GET', '/people.json?%s' % query, {},
         util.to_json([self.arnold], root='people'))
     arnold = self.person.find_first(vars={'key': ['val1', 'val2']})
     self.assertEqual(self.arnold, arnold.attributes)
开发者ID:drwelby,项目名称:pyactiveresource,代码行数:7,代码来源:activeresource_test.py


示例7: test_find_should_handle_array_query_args

 def test_find_should_handle_array_query_args(self):
     query = urllib.urlencode({'vars[]': ['a', 'b', 'c']}, True)
     self.http.respond_to(
         'GET', '/people.json?%s' % query, {},
         util.to_json([self.arnold], root='people'))
     arnold = self.person.find_first(vars=['a', 'b', 'c'])
     self.assertEqual(self.arnold, arnold.attributes)
开发者ID:drwelby,项目名称:pyactiveresource,代码行数:7,代码来源:activeresource_test.py


示例8: test_save

    def test_save(self):
        # Return an object with id for a post(save) request.
        self.http.respond_to(
            'POST', '/stores.json', self.json_headers,
            util.to_json(self.general_store))
        # Return an object for a put request.
        self.http.respond_to(
            'PUT', '/stores/1.json', self.json_headers,
            util.to_json(self.store_update, root='store'))

        self.store.format = formats.JSONFormat
        store = self.store(self.store_new)
        store.save()
        self.assertEqual(self.general_store, store.attributes)
        store.manager_id = 3
        store.save()
开发者ID:drwelby,项目名称:pyactiveresource,代码行数:16,代码来源:activeresource_test.py


示例9: test_find_with_prefix_and_query_options

 def test_find_with_prefix_and_query_options(self):
     self.http.respond_to(
         'GET', '/stores/1/people.json?name=Ralph', {},
         util.to_json([], root='people'))
     # Query & prefix options
     self.person._site = 'http://localhost/stores/$store_id/'
     nobody = self.person.find(store_id=1, name='Ralph')
     self.assertEqual([], nobody)
开发者ID:drwelby,项目名称:pyactiveresource,代码行数:8,代码来源:activeresource_test.py


示例10: test_save_should_clear_errors

 def test_save_should_clear_errors(self):
   self.http.respond_to(
       'POST', '/stores.json', self.json_headers,
       util.to_json(self.general_store))
   store = self.store(self.store_new)
   store.errors.add_to_base('bad things!')
   store.save()
   self.assertEqual(0, store.errors.size)
开发者ID:drwelby,项目名称:pyactiveresource,代码行数:8,代码来源:activeresource_test.py


示例11: test_find_with_query_options

 def test_find_with_query_options(self):
     # Return a single-item people list for a find() call with kwargs
     self.http.respond_to(
         'GET', '/people.json?name=Arnold', {},
         util.to_json([self.arnold], root='people'))
     # Query options only
     arnold = self.person.find(name='Arnold')[0]
     self.assertEqual(self.arnold, arnold.attributes)
开发者ID:drwelby,项目名称:pyactiveresource,代码行数:8,代码来源:activeresource_test.py


示例12: test_find_with_prefix_options

 def test_find_with_prefix_options(self):
     # Paths for prefix_options related requests
     self.http.respond_to(
         'GET', '/stores/1/people.json', {},
         util.to_json([self.sam], root='people'))
     # Prefix options only
     self.person._site = 'http://localhost/stores/$store_id/'
     sam = self.person.find(store_id=1)[0]
     self.assertEqual(self.sam, sam.attributes)
开发者ID:drwelby,项目名称:pyactiveresource,代码行数:9,代码来源:activeresource_test.py


示例13: test_find

    def test_find(self):
        # Return a list of people for a find method call
        self.http.respond_to(
            'GET', '/people.json', {},
            util.to_json([self.arnold, self.eb], root='people'))

        people = self.person.find()
        self.assertEqual([self.arnold, self.eb],
                         [p.attributes for p in people])
开发者ID:drwelby,项目名称:pyactiveresource,代码行数:9,代码来源:activeresource_test.py


示例14: test_find_one

    def test_find_one(self):
        # Return an object for a specific one-off url
        self.http.respond_to(
            'GET', '/what_kind_of_soup.json', {},
            util.to_json(self.soup, root='soup'))

        class Soup(activeresource.ActiveResource):
            _site = 'http://localhost'
        soup = Soup.find_one(from_='/what_kind_of_soup.json')
        self.assertEqual(self.soup, soup.attributes)
开发者ID:drwelby,项目名称:pyactiveresource,代码行数:10,代码来源:activeresource_test.py


示例15: setUp

    def setUp(self):
        '''Create test objects.'''
        matz = {'id': 1, 'name': 'Matz'}
        david = {'id': 2, 'name': 'David'}
        self.matz  = util.to_json(matz, root='person')
        self.david = util.to_json(david, root='person') 
        self.people = util.to_json([matz, david], root='people')
        self.people_single = util.to_json(
            [matz], root='people-single-elements')
        self.people_empty = util.to_json([], root='people-empty-elements')

        http_fake.initialize()
        self.http = http_fake.TestHandler
        self.http.site = 'http://localhost'
        self.http.set_response(Error('Bad request'))

        self.zero_length_content_headers = {'Content-Length': '0',
                                            'Content-Type': 'application/json'}

        self.header = {'Key': 'value'}
        self.connection = connection.Connection(self.http.site)
开发者ID:varesa,项目名称:pyactiveresource,代码行数:21,代码来源:connection_test.py


示例16: setUp

    def setUp(self):
        """Create test objects."""
        self.arnold = {'id': 1, 'name': 'Arnold Ziffel'}
        self.eb = {'id': 2, 'name': 'Eb Dawson'}
        self.sam = {'id': 3, 'name': 'Sam Drucker'}
        self.soup = {'id': 1, 'name': 'Hot Water Soup'}
        self.store_new = {'name': 'General Store'}
        self.general_store = {'id': 1, 'name': 'General Store'}
        self.store_update = {'manager_id': 3, 'id': 1, 'name':'General Store'}
        self.xml_headers = {'Content-type': 'application/xml'}
        self.json_headers = {'Content-type': 'application/json'}

        self.matz  = util.to_json(
                {'id': 1, 'name': 'Matz'}, root='person')
        self.matz_deep  = util.to_json(
                {'id': 1, 'name': 'Matz', 'other': 'other'},
                root='person')
        self.matz_array = util.to_json(
                [{'id': 1, 'name': 'Matz'}], root='people')
        self.ryan = util.to_json(
                {'name': 'Ryan'}, root='person')
        self.addy = util.to_json(
                {'id': 1, 'street': '12345 Street'},
                root='address')
        self.addy_deep  = util.to_json(
                {'id': 1, 'street': '12345 Street', 'zip': "27519" },
                root='address')

        http_fake.initialize()  # Fake all http requests
        self.http = http_fake.TestHandler
        self.http.set_response(Error('Bad request'))
        self.http.site = 'http://localhost'
        self.zero_length_content_headers = {'Content-length': '0',
                                            'Content-type': 'application/json'}

        class Person(activeresource.ActiveResource):
            _site = 'http://localhost'

        self.person = Person
        self.store = Store
        self.address = Address
开发者ID:drwelby,项目名称:pyactiveresource,代码行数:41,代码来源:activeresource_test.py


示例17: to_json

 def to_json(self, root=True):
     """Convert the object to a json string."""
     if root == True:
         root = self._singular
     return util.to_json(self.to_dict(), root=root)
开发者ID:roninio,项目名称:gae-shopify-python-boilerplate,代码行数:5,代码来源:activeresource.py


示例18: test_to_json_should_allow_utf8_encoded_strings

 def test_to_json_should_allow_utf8_encoded_strings(self):
     json = util.to_json({'data': u'\u00e9'.encode('utf-8')})
     self.assert_('\u00e9' in json)
开发者ID:hockeybuggy,项目名称:pyactiveresource,代码行数:3,代码来源:util_test.py


示例19: test_to_json_should_allow_unicode

 def test_to_json_should_allow_unicode(self):
     json = util.to_json({'data': u'\u00e9'})
     self.assert_('\u00e9' in json or '\\u00e9' in json)
开发者ID:hockeybuggy,项目名称:pyactiveresource,代码行数:3,代码来源:util_test.py


示例20: test_find_should_handle_unicode_query_args

 def test_find_should_handle_unicode_query_args(self):
     self.http.respond_to(
         'GET', '/people.json?name=%C3%83%C3%A9', {},
         util.to_json([self.arnold], root='people'))
     arnold = self.person.find_first(name=u'\xc3\xe9')
     self.assertEqual(self.arnold, arnold.attributes)
开发者ID:drwelby,项目名称:pyactiveresource,代码行数:6,代码来源:activeresource_test.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.to_xml函数代码示例发布时间:2022-05-25
下一篇:
Python controller.start_controller函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap