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


Python Collection.from_json方法代码示例

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


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

示例1: test_get

# 需要导入模块: from collection_json import Collection [as 别名]
# 或者: from collection_json.Collection import from_json [as 别名]
 def test_get(self):
     test_url = self.test_url + "/devices/7324ef5a-b1a6-4ff4-9d97-61b4dde35924"
     test_response = get(test_url)
     collection = Collection.from_json(test_response.text)
     print collection.version
     print collection.href
     print [data.name for data in collection.items[0].data]
开发者ID:dawgware,项目名称:stemlab,代码行数:9,代码来源:test_api_client.py

示例2: _get_device_links

# 需要导入模块: from collection_json import Collection [as 别名]
# 或者: from collection_json.Collection import from_json [as 别名]
 def _get_device_links(self):
     if self._device_settings.device_url is not None:
         get_url = self._device_settings.device_url
         link_response = get(url=get_url)
         if link_response.status_code == 200:
             collection = Collection.from_json(link_response.text)
             device_id = [data.value for data in collection.items[0].data if data.name == 'device_id'][0]
             if device_id is not None:
                 self._device_settings.device_id = device_id
             for link in collection.links:
                 if link.rel == 'latest':
                     self._device_settings.latest_url = link.href
                 else:
                     resp = get(url=link.href)
                     if resp.status_code == 200:
                         link_coll = Collection.from_json(resp.text)
                         self._device_settings.process_measurement_template(link_coll, link.rel)
开发者ID:dawgware,项目名称:stemlab,代码行数:19,代码来源:sensor_client.py

示例3: test_get_template

# 需要导入模块: from collection_json import Collection [as 别名]
# 或者: from collection_json.Collection import from_json [as 别名]
 def test_get_template(self):
     test_url = self.test_url + "/readings/temperature/template/7324ef5a-b1a6-4ff4-9d97-61b4dde35924"
     test_response = get(test_url)
     collection = Collection.from_json(test_response.text)
     print collection.version
     print collection.href
     data = collection.template.data
     print [item.name for item in data]
开发者ID:dawgware,项目名称:stemlab,代码行数:10,代码来源:test_api_client.py

示例4: test_get_by_date_device

# 需要导入模块: from collection_json import Collection [as 别名]
# 或者: from collection_json.Collection import from_json [as 别名]
 def test_get_by_date_device(self):
     test_url = self.test_url + "/devices/0c89fded-76ea-4890-a8a1-25c25b24986d/2013-06-13T13:49:23-04:00"
     test_response = get(test_url)
     collection = Collection.from_json(test_response.text)
     self.assertIsNotNone(collection.items, """
     Api_ClientTestCase::test_get_by_date_device:
     Expected '{expected}' got '{returned}' value instead
     """.format(expected='values', returned='None'))
开发者ID:dawgware,项目名称:stemlab,代码行数:10,代码来源:test_api_client.py

示例5: test_from_json_minimal

# 需要导入模块: from collection_json import Collection [as 别名]
# 或者: from collection_json.Collection import from_json [as 别名]
 def test_from_json_minimal(self):
     collection = Collection.from_json(
         '{"collection": {"href": "http://example.org"}}')
     self.assertEqual(collection.version, '1.0')
     self.assertEqual(collection.href, 'http://example.org')
     self.assertEqual(collection.links, Array(Link, 'links', []))
     self.assertEqual(collection.items, Array(Item, 'items', []))
     self.assertEqual(collection.queries, Array(Query, 'queries', []))
     self.assertEqual(collection.template, None)
     self.assertEqual(collection.error, None)
开发者ID:ievans3024,项目名称:collection-json.python,代码行数:12,代码来源:tests.py

示例6: test_from_json_with_template_data

# 需要导入模块: from collection_json import Collection [as 别名]
# 或者: from collection_json.Collection import from_json [as 别名]
 def test_from_json_with_template_data(self):
     data = json.dumps({
         'collection': {
             'version': '1.0',
             'href': 'http://example.com',
             'template': {
                 'data': [
                     {'name': 'name', 'value': 'value', 'prompt': 'prompt'}
                 ]
             }
         }
     })
     collection = Collection.from_json(data)
     self.assertEqual(collection.template,
                      Template([Data('name', 'value', 'prompt')]))
开发者ID:oszi,项目名称:collection-json.python,代码行数:17,代码来源:tests.py

示例7: test_from_json_with_error_data

# 需要导入模块: from collection_json import Collection [as 别名]
# 或者: from collection_json.Collection import from_json [as 别名]
 def test_from_json_with_error_data(self):
     data = json.dumps({
         'collection': {
             'version': '1.0',
             'href': 'http://example.org',
             'error': {
                 'code': 'code',
                 'message': 'message',
                 'title': 'title',
             }
         }
     })
     collection = Collection.from_json(data)
     self.assertEqual(collection.error,
                      Error('code', 'message', 'title'))
开发者ID:oszi,项目名称:collection-json.python,代码行数:17,代码来源:tests.py

示例8: test_from_json_with_links_data

# 需要导入模块: from collection_json import Collection [as 别名]
# 或者: from collection_json.Collection import from_json [as 别名]
 def test_from_json_with_links_data(self):
     data = json.dumps({
         'collection': {
             'version': '1.0',
             'href': 'http://example.com',
             'links': [
                 {
                     'rel': 'rel',
                     'href': 'href',
                 }
             ],
         }
     })
     collection = Collection.from_json(data)
     link = Link('href', 'rel')
     self.assertEqual(collection.links, Array(Link, 'links', [link]))
开发者ID:oszi,项目名称:collection-json.python,代码行数:18,代码来源:tests.py

示例9: test_from_json_with_queries_data

# 需要导入模块: from collection_json import Collection [as 别名]
# 或者: from collection_json.Collection import from_json [as 别名]
 def test_from_json_with_queries_data(self):
     data = json.dumps({
         'collection': {
             'version': '1.0',
             'href': 'http://example.com',
             'queries': [
                 {
                     'rel': 'rel',
                     'href': 'href',
                 }
             ],
         }
     })
     collection = Collection.from_json(data)
     query = Query('href', 'rel')
     self.assertEqual(collection.queries, Array(Query, 'queries', [query]))
开发者ID:oszi,项目名称:collection-json.python,代码行数:18,代码来源:tests.py

示例10: test_from_json_with_inline_data

# 需要导入模块: from collection_json import Collection [as 别名]
# 或者: from collection_json.Collection import from_json [as 别名]
 def test_from_json_with_inline_data(self):
     data = json.dumps({
         'collection': {
             'version': '1.0',
             'href': 'http://example.com',
             'links': [
                 {
                     'href': 'href-inline',
                     'rel': 'rel-inline',
                     'length': 1,
                     'inline': True,
                 }
             ],
             'inline': {
                 'href-inline': {
                     'collection': {
                         'version': '1.0',
                         'href': 'href-inline',
                         'items': [
                             {
                                 'href': 'href',
                                 'data': [
                                     {'name': 'name'}
                                 ],
                                 'links': [
                                     {'href': 'href', 'rel': 'rel'}
                                 ]
                             }
                         ]
                     }
                 }
             }
         }
     })
     collection = Collection.from_json(data)
     data = Data('name')
     link = Link('href', 'rel')
     item = Item('href', [data], [link])
     inline = [Collection(href='href-inline', items=[item])]
     link = Link('href-inline', 'rel-inline', length=1, inline=True)
     self.assertEqual(collection.inline, Array(Collection, 'inline', inline))
     self.assertEqual(collection.links, Array(Link, 'links', [link]))
开发者ID:oszi,项目名称:collection-json.python,代码行数:44,代码来源:tests.py

示例11: test_from_json_with_items_data

# 需要导入模块: from collection_json import Collection [as 别名]
# 或者: from collection_json.Collection import from_json [as 别名]
 def test_from_json_with_items_data(self):
     data = json.dumps({
         'collection': {
             'version': '1.0',
             'href': 'http://example.com',
             'items': [
                 {
                     'href': 'href',
                     'data': [
                         {'name': 'name'}
                     ],
                     'links': [
                         {'href': 'href', 'rel': 'rel'}
                     ]
                 }
             ],
         }
     })
     collection = Collection.from_json(data)
     data = Data('name')
     link = Link('href', 'rel')
     item = Item('href', [data], [link])
     self.assertEqual(collection.items, Array(Item, 'items', [item]))
开发者ID:oszi,项目名称:collection-json.python,代码行数:25,代码来源:tests.py

示例12: test_from_json_invaid_uri

# 需要导入模块: from collection_json import Collection [as 别名]
# 或者: from collection_json.Collection import from_json [as 别名]
 def test_from_json_invaid_uri(self):
     with self.assertRaises(ValueError):
         Collection.from_json('{"collection": {}}')
开发者ID:oszi,项目名称:collection-json.python,代码行数:5,代码来源:tests.py

示例13: test_from_json_invalid_document

# 需要导入模块: from collection_json import Collection [as 别名]
# 或者: from collection_json.Collection import from_json [as 别名]
 def test_from_json_invalid_document(self):
     with self.assertRaises(ValueError):
         Collection.from_json('{}')
开发者ID:oszi,项目名称:collection-json.python,代码行数:5,代码来源:tests.py

示例14: test_from_json_invalid_data

# 需要导入模块: from collection_json import Collection [as 别名]
# 或者: from collection_json.Collection import from_json [as 别名]
 def test_from_json_invalid_data(self):
     with self.assertRaises(ValueError):
         Collection.from_json('')
开发者ID:oszi,项目名称:collection-json.python,代码行数:5,代码来源:tests.py

示例15: setUp

# 需要导入模块: from collection_json import Collection [as 别名]
# 或者: from collection_json.Collection import from_json [as 别名]
 def setUp(self):
     self.response = self.client.get(self.endpoint)
     self.collection = Collection.from_json(self.response.content.decode('utf8'))
开发者ID:FNNDSC,项目名称:pman_fileio,代码行数:5,代码来源:test_services.py


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