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


Python Factual.raw_read方法代码示例

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


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

示例1: FactualAPITestSuite

# 需要导入模块: from factual import Factual [as 别名]
# 或者: from factual.Factual import raw_read [as 别名]

#.........这里部分代码省略.........
        schema = self.places.schema()
        self.assertGreater(len(schema['fields']),20)
        self.assertIn('title', schema)
        self.assertIn('locality', set(f['name'] for f in schema['fields']))

    # full text search for things where locality equals 大阪市 (Osaka: test unicode)
    def test_unicode(self):
        q = self.places.filters({'locality': u'大阪市'})
        for r in q.data():
            self.assertEqual(u'大阪市', r['locality'])

    def test_bw_encoding(self):
        q = self.places.filters({'name': {"$bw":"Star"}})
        row = q.data()[0]
        self.assertRegexpMatches(row['name'], "Star")

    def test_in(self):
        q = self.places.filters({"locality":{"$in":["Santa Monica","Los Angeles","Culver City"]}})
        row = q.data()[0]
        self.assertIn(row['locality'], ["Santa Monica","Los Angeles","Culver City"])

    def test_and(self):
        q = self.places.filters({"$and":[{"country":"US"},{"website":{"$blank":False}}]})
        row = q.data()[0]
        self.assertEqual('US', row['country'].upper())
        self.assertRegexpMatches(row['website'], 'http')

    def test_includes(self):
        q = self.places.filters({'category_ids':{'$includes':10}})
        rows = q.data()
        for row in rows:
            self.assertIn(10, row['category_ids'])

    def test_raw_read(self):
        # filters here is url encoded {"name":"Starbucks"}
        response = self.factual.raw_read('t/places/read', 'limit=15&filters=%7B%22name%22%3A%22Starbucks%22%7D')
        payload = json.loads(response)
        data = payload['response']['data']
        self.assertEqual(15, payload['response']['included_rows'])
        self.assertTrue(all(row['name'] == 'Starbucks' for row in data))

    def test_raw_read_with_map(self):
        response = self.factual.raw_read('t/places/read', {'limit':15,'filters':{"name":"Starbucks"}})
        payload = json.loads(response)
        data = payload['response']['data']
        self.assertEqual(15, payload['response']['included_rows'])
        self.assertTrue(all(row['name'] == 'Starbucks' for row in data))

    def test_raw_write(self):
        uuid = '1007462b-dd79-44f5-a69f-e0b6041fa8bd'
        params = {'problem':'other','user':'python_driver_tester','debug':True}
        response = self.factual.raw_write('t/us-sandbox/' + uuid + '/flag', params)
        payload = json.loads(response)
        self.assertEqual('ok', payload['status'])

    def test_facets1(self):
        q = self.facets.search("starbucks").select("country")
        results = q.data()['country']
        self.assertTrue(results['us'] > 5000)
        self.assertTrue(results['ca'] > 200)

    def test_facets2(self):
        q = self.facets.search("starbucks").select("locality,region").filters({"country":"US"})
        locality = q.data()['locality']
        region = q.data()['region']
        self.assertTrue(locality['chicago'] > 50)
开发者ID:jgraham6,项目名称:factual-python-driver,代码行数:70,代码来源:api_test.py

示例2: FactualAPITestSuite

# 需要导入模块: from factual import Factual [as 别名]
# 或者: from factual.Factual import raw_read [as 别名]
class FactualAPITestSuite(unittest.TestCase):
    def setUp(self):
        self.factual = Factual(KEY, SECRET)
        self.places = self.factual.table('places')
        self.facets = self.factual.facets('global')

    def test_search(self):
        q = self.places.search('factual')
        row = q.data()[0]
        self.assertRegexpMatches(row['name'], 'Factual')

    # full text search for "Mcdonald's, Santa Monica" (test spaces, commas, and apostrophes)
    def test_search2(self):
        q = self.places.search("McDonald's,Santa Monica").limit(20)
        included_rows = q.included_rows()
        self.assertEqual(20, included_rows)

    def test_limit(self):
        q = self.places.search('sushi').limit(3)
        self.assertEqual(3, len(q.data()))

    def test_select(self):
        q = self.places.select('name,address')
        row = q.data()[0]
        self.assertEqual(2, len(row.keys()))

    def test_sort(self):
        q1 = self.places.sort_asc('name')
        self.assertTrue(q1.data()[0]['name'] < q1.data()[1]['name'])

        q2 = self.places.sort_desc('name')
        self.assertTrue(q2.data()[0]['name'] > q2.data()[1]['name'])

    def test_paging(self):
        q1 = self.places.offset(30)
        r1 = q1.data()[0]

        q2 = self.places.page(3, 15)
        r2 = q2.data()[0]
        self.assertEqual(r1['name'], r2['name'])

    def test_filters(self):
        q = self.places.filters({'region': 'NV'})
        for r in q.data():
            self.assertEqual('NV', r['region'])

    def test_geo(self):
        q = self.places.search('factual').geo(circle(34.06021, -118.41828, 1000))
        row = q.data()[0]
        self.assertEqual('Factual', row['name'])
        self.assertEqual('1801 Avenue Of The Stars', row['address'])

    def test_resolve(self):
        q = self.factual.resolve({'name': 'factual inc', 'locality': 'los angeles'})
        row = q.data()[0]
        self.assertTrue(row['resolved'])
        self.assertEqual('1801 Avenue Of The Stars', row['address'])

    def test_crosswalk(self):
        q = self.factual.crosswalk()
        result = q.filters({'factual_id':'03c26917-5d66-4de9-96bc-b13066173c65','namespace':'simplegeo'}).data()
        self.assertEqual(1, len(result))
        self.assertEqual('SG_3ueEyOH4YN3ob9ryHjV1ey', result[0]['namespace_id'])

    def test_schema(self):
        schema = self.places.schema()
        self.assertEqual(21, len(schema['fields']))
        self.assertIn('title', schema)
        self.assertIn('locality', set(f['name'] for f in schema['fields']))

    # full text search for things where locality equals 大阪市 (Osaka: test unicode)
    def test_unicode(self):
        q = self.places.filters({'locality': '大阪市'})
        for r in q.data():
            self.assertEqual('大阪市', r['locality'])

    def test_bw_encoding(self):
        q = self.places.filters({'category': {"$bw":"Arts, Entertainment & Nightlife > Bars"}})
        row = q.data()[0]
        self.assertRegexpMatches(row['category'], "Arts, Entertainment & Nightlife > Bars")

    def test_in(self):
        q = self.places.filters({"locality":{"$in":["Santa Monica","Los Angeles","Culver City"]}})
        row = q.data()[0]
        self.assertIn(row['locality'], ["Santa Monica","Los Angeles","Culver City"])

    def test_and(self):
        q = self.places.filters({"$and":[{"country":"US"},{"website":{"$blank":False}}]})
        row = q.data()[0]
        self.assertEqual('US', row['country'])
        self.assertRegexpMatches(row['website'], 'http')

    def test_raw_read(self):
        # filters here is url encoded {"name":"Starbucks"}
        response = self.factual.raw_read('t/places/read', 'limit=15&filters=%7B%22name%22%3A%22Starbucks%22%7D')
        payload = json.loads(response)
        data = payload['response']['data']
        self.assertEqual(15, payload['response']['included_rows'])
        self.assertTrue(all(row['name'] == 'Starbucks' for row in data))

#.........这里部分代码省略.........
开发者ID:mmoutenot,项目名称:factual-python-driver,代码行数:103,代码来源:api_test.py

示例3: FactualAPITestSuite

# 需要导入模块: from factual import Factual [as 别名]
# 或者: from factual.Factual import raw_read [as 别名]
class FactualAPITestSuite(unittest.TestCase):
    def setUp(self):
        self.factual = Factual(KEY, SECRET)
        self.places = self.factual.table("places")
        self.facets = self.factual.facets("global")

    def test_search(self):
        q = self.places.search("factual")
        row = q.data()[0]
        self.assertRegexpMatches(row["name"], "Factual")

    # full text search for "Mcdonald's, Santa Monica" (test spaces, commas, and apostrophes)
    def test_search2(self):
        q = self.places.search("McDonald's,Santa Monica").limit(20)
        included_rows = q.included_rows()
        self.assertEqual(20, included_rows)

    def test_limit(self):
        q = self.places.search("sushi").limit(3)
        self.assertEqual(3, len(q.data()))

    def test_select(self):
        q = self.places.select("name,address")
        row = q.data()[0]
        self.assertEqual(2, len(row.keys()))

    def test_sort(self):
        q1 = self.places.sort_asc("name")
        self.assertTrue(q1.data()[0]["name"] < q1.data()[1]["name"])

        q2 = self.places.sort_desc("name")
        self.assertTrue(q2.data()[0]["name"] > q2.data()[1]["name"])

    def test_paging(self):
        q1 = self.places.offset(30)
        r1 = q1.data()[0]

        q2 = self.places.page(3, 15)
        r2 = q2.data()[0]
        self.assertEqual(r1["name"], r2["name"])

    def test_filters(self):
        q = self.places.filters({"region": "NV"})
        for r in q.data():
            self.assertEqual("NV", r["region"])

    def test_geo(self):
        q = self.places.search("factual").geo(circle(34.06021, -118.41828, 1000))
        row = q.data()[0]
        self.assertEqual("Factual", row["name"])
        self.assertEqual("1801 Avenue Of The Stars", row["address"])

    def test_resolve(self):
        q = self.factual.resolve({"name": "factual inc", "locality": "los angeles"})
        row = q.data()[0]
        self.assertTrue(row["resolved"])
        self.assertEqual("1801 Avenue Of The Stars", row["address"])

    def test_schema(self):
        schema = self.places.schema()
        self.assertEqual(21, len(schema["fields"]))
        self.assertIn("title", schema)
        self.assertIn("locality", set(f["name"] for f in schema["fields"]))

    # full text search for things where locality equals 大阪市 (Osaka: test unicode)
    def test_unicode(self):
        q = self.places.filters({"locality": "大阪市"})
        for r in q.data():
            self.assertEqual("大阪市", r["locality"])

    def test_bw_encoding(self):
        q = self.places.filters({"category": {"$bw": "Arts, Entertainment & Nightlife > Bars"}})
        row = q.data()[0]
        self.assertRegexpMatches(row["category"], "Arts, Entertainment & Nightlife > Bars")

    def test_in(self):
        q = self.places.filters({"locality": {"$in": ["Santa Monica", "Los Angeles", "Culver City"]}})
        row = q.data()[0]
        self.assertIn(row["locality"], ["Santa Monica", "Los Angeles", "Culver City"])

    def test_and(self):
        q = self.places.filters({"$and": [{"country": "US"}, {"website": {"$blank": False}}]})
        row = q.data()[0]
        self.assertEqual("US", row["country"])
        self.assertRegexpMatches(row["website"], "http")

    def test_raw_read(self):
        # filters here is url encoded {"name":"Starbucks"}
        response = self.factual.raw_read("t/places/read", "limit=15&filters=%7B%22name%22%3A%22Starbucks%22%7D")
        payload = json.loads(response)
        data = payload["response"]["data"]
        self.assertEqual(15, payload["response"]["included_rows"])
        self.assertTrue(all(row["name"] == "Starbucks" for row in data))

    def test_facets1(self):
        q = self.facets.search("starbucks").select("country")
        results = q.data()["country"]
        self.assertTrue(results["us"] > 5000)
        self.assertTrue(results["ca"] > 200)

#.........这里部分代码省略.........
开发者ID:jebrown6,项目名称:factual-python-driver,代码行数:103,代码来源:api_test.py

示例4: FactualAPITestSuite

# 需要导入模块: from factual import Factual [as 别名]
# 或者: from factual.Factual import raw_read [as 别名]

#.........这里部分代码省略.........
        schema = self.places.schema()
        self.assertGreater(len(schema['fields']),20)
        self.assertIn('title', schema)
        self.assertIn('locality', set(f['name'] for f in schema['fields']))

    # full text search for things where locality equals 大阪市 (Osaka: test unicode)
    def test_unicode(self):
        q = self.places.filters({'locality': u'大阪市'})
        for r in q.data():
            self.assertEqual(u'大阪市', r['locality'])

    def test_bw_encoding(self):
        q = self.places.filters({'name': {"$bw":"Star"}})
        row = q.data()[0]
        self.assertRegexpMatches(row['name'], "Star")

    def test_in(self):
        q = self.places.filters({"locality":{"$in":["Santa Monica","Los Angeles","Culver City"]}})
        row = q.data()[0]
        self.assertIn(row['locality'], ["Santa Monica","Los Angeles","Culver City"])

    def test_and(self):
        q = self.places.filters({"$and":[{"country":"US"},{"website":{"$blank":False}}]})
        row = q.data()[0]
        self.assertEqual('US', row['country'].upper())
        self.assertRegexpMatches(row['website'], 'http')

    def test_includes(self):
        q = self.places.filters({'category_ids':{'$includes':10}})
        rows = q.data()
        for row in rows:
            self.assertIn(10, row['category_ids'])

    def test_raw_read(self):
        # filters here is url encoded {"name":"Starbucks"}
        response = self.factual.raw_read('t/places/read', 'limit=15&filters=%7B%22name%22%3A%22Starbucks%22%7D')
        payload = json.loads(response)
        data = payload['response']['data']
        self.assertEqual(15, payload['response']['included_rows'])
        self.assertTrue(all(row['name'] == 'Starbucks' for row in data))

    def test_raw_read_with_map(self):
        response = self.factual.raw_read('t/places/read', {'limit':15,'filters':{"name":"Starbucks"}})
        payload = json.loads(response)
        data = payload['response']['data']
        self.assertEqual(15, payload['response']['included_rows'])
        self.assertTrue(all(row['name'] == 'Starbucks' for row in data))

    def test_raw_write(self):
        uuid = SANDBOX_UUID
        params = {'problem':'other','user':'python_driver_tester','debug':True}
        response = self.factual.raw_write('t/us-sandbox/' + uuid + '/flag', params)
        payload = json.loads(response)
        self.assertEqual('ok', payload['status'])

    def test_facets1(self):
        q = self.facets.search("starbucks").select("country")
        results = q.data()['country']
        self.assertTrue(results['us'] > 5000)
        self.assertTrue(results['ca'] > 200)

    def test_facets2(self):
        q = self.facets.search("starbucks").select("locality,region").filters({"country":"US"})
        locality = q.data()['locality']
        region = q.data()['region']
        self.assertTrue(locality['chicago'] > 50)
开发者ID:jholkeboer,项目名称:check-me-in,代码行数:70,代码来源:api_test.py


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