本文整理汇总了Python中slumber.connector.ua.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_real_does_not_use_cached_httplib2_client
def test_real_does_not_use_cached_httplib2_client(self):
"""
When we use this slumber in Wimbledon project, we found that the request
is occationally error on IE9 (got 500 response in return bcoz of the empty
request). We are not sure if the root cause was in IE9 or in the httplib2,
but stop caching httplib2's client fixed it (reset client everytime).
The downside is we cannot use caching features of the httplib2's client,
but until we understand this problem in more details, we'll stick with
resetting client every time.
juacompe, 2nd November 2011
ref: http://proteus.eidos.proteus-tech.com/project/BBG/story/BBG-251/card/
"""
self.callers = []
class response:
status = 200
content = '''{"apps":{}}'''
def _request(_self, url, headers={}):
self.callers.append(_self)
r = response()
return r, r.content
with patch('slumber.connector.ua.Http.request',_request):
get(self.cache_url)
get(self.cache_url)
self.assertNotEqual(self.callers[0], self.callers[1])
示例2: test_cache_ttl
def test_cache_ttl(self):
def _request(_self, url, headers={}):
r = _response_httplib2()
return r, r.content
with patch('slumber.connector.ua.Http.request', _request):
get(self.cache_url, 2)
with patch('slumber.connector.ua.Http.request', self.fail):
get(self.cache_url, 2)
示例3: test_retry_get_still_can_fail
def test_retry_get_still_can_fail(self):
class _response:
content = ''
status = 500
def _request(_self, url, headers={}):
r = _response()
return r, r.content
with patch('slumber.connector.ua.Http.request',_request):
with self.assertRaises(AssertionError):
get(self.cache_url)
示例4: test_get_retries
def test_get_retries(self):
class _response:
content = '''{"apps":{}}'''
def __init__(self, counter):
self.status = 200 if counter == 1 else 404
counter = []
def _request(_self, url, headers={}):
r = _response(len(counter))
counter.append(True)
return r, r.content
with patch('slumber.connector.ua.Http.request', _request):
get(self.cache_url)
self.assertEqual(len(counter), 2)
示例5: get_all_permissions
def get_all_permissions(self):
"""Forward access to all of the permissions.
"""
# We're accessing attributes that are provided by the other types
# pylint: disable = E1101
_, json = get(self._operations['get-permissions'], self._CACHE_TTL)
return set(json['all_permissions'])
示例6: __getattr__
def __getattr__(self, name):
_, json = get(self._url)
for k, v in json['fields'].items():
setattr(self, k, from_json_data(self._url, v))
if name in json['fields'].keys():
return getattr(self, name)
return _return_data_array(self._url, json['data_arrays'], self, name)
示例7: test_mount_point
def test_mount_point(self):
response, json = get('/slumber/shops/mount1/')
self.assertEqual(response.status_code, 200)
self.assertEqual(json, dict(_meta={'message': 'OK', 'status': 200},
shops=[{
'name': 'Hard Coded Pizza Parlour'
}]))
示例8: test_mount_point
def test_mount_point(self):
shop = Shop.objects.create(name="Test One")
with patch("slumber.connector._get_slumber_authn_name", lambda: "service"):
response, json = get("/slumber/pizzas/shop/%s/" % shop.pk)
self.assertEqual(response.status_code, 200)
self.assertTrue(json["operations"].has_key("data"), json)
self.assertEqual(json["operations"]["data"], "/slumber/pizzas/shop/%s/" % shop.pk)
示例9: test_fifteen_shops
def test_fifteen_shops(self):
for s in xrange(1, 16):
Shop.objects.create(name="Shop %d" % s, slug="shop%2d" % s)
response, json = get('/slumber/shops/mount2/')
self.assertEqual(response.status_code, 200)
self.assertFalse(json.has_key('instances'))
self.assertTrue(json.has_key('_links'))
links = json['_links']
self.assertEqual(links['self']['href'], '/slumber/shops/mount2/')
self.assertEqual(links['model']['href'], '/slumber/slumber_examples/Shop/')
self.assertTrue(links.has_key('next'), links)
self.assertTrue(json.has_key('_embedded'))
self.assertTrue(json['_embedded'].has_key('page'))
page = json['_embedded']['page']
self.assertEqual(len(page), 10)
self.assertEqual(page[0], dict(
_links={'self': dict(href='/slumber/pizzas/shop/15/')},
display="Shop 15"))
self.assertEqual(links['next']['href'],
'/slumber/shops/mount2/?lpk=6')
示例10: pull_monitor
def pull_monitor(model_url, callback, delay=dict(minutes=1),
page_url=None, floor=0, pull_priority=5, job_priority=5):
"""Used to look for instances that need to be pulled.
This only works with models who use an auto-incremented primary key.
"""
if not page_url:
model = get_model(model_url)
instances_url = model._operations['instances']
else:
instances_url = page_url
_, json = get(instances_url or page_url)
latest, highest = None, floor
for item in json['page']:
highest = max(item['pk'], highest)
latest = item['pk']
if latest > floor:
schedule(callback, args=[urljoin(instances_url, item['data'])], priority=job_priority)
if json.has_key('next_page') and latest > floor:
schedule('pubsubpull.async.pull_monitor', args=[model_url, callback],
kwargs=dict(delay=delay, floor=floor,
page_url=urljoin(instances_url, json['next_page']),
pull_priority=pull_priority, job_priority=job_priority),
priority=pull_priority)
print("Got another page to process", json['next_page'], floor)
if not page_url:
run_after = timezone.now() + timedelta(**delay)
schedule('pubsubpull.async.pull_monitor', run_after=run_after,
args=[model_url, callback], kwargs=dict(delay=delay, floor=highest,
pull_priority=pull_priority, job_priority=job_priority),
priority=pull_priority)
print("Looking for new instances above", highest)
示例11: __getattr__
def __getattr__(self, attr_name):
"""Fetch the application list from the Slumber directory on request.
"""
_, json = get(self._directory)
apps = {}
for app in json['apps'].keys():
root = apps
for k in app.split('.'):
if not root.has_key(k):
root[k] = {}
root = root[k]
def recurse_apps(loc, this_level, name):
"""Recursively build the application connectors.
"""
current_appname = '.'.join(name)
if json['apps'].has_key(current_appname):
loc._url = urljoin(self._directory,
json['apps'][current_appname])
for k, v in this_level.items():
app_cnx = AppConnector()
setattr(loc, k, app_cnx)
recurse_apps(app_cnx, v, name + [k])
recurse_apps(self, apps, [])
if attr_name in apps.keys():
return getattr(self, attr_name)
else:
raise AttributeError(attr_name)
示例12: get_profile
def get_profile(self):
"""Forward access to the profile.
"""
# We're accessing attributes that are provided by the other types
# pylint: disable = E1101
base_url = self._operations['get-profile']
_, json = get(base_url, self._CACHE_TTL)
return get_instance_from_data(base_url, json)
示例13: has_perm
def has_perm(self, permission):
"""Forward the permission check.
"""
# We're accessing attributes that are provided by the other types
# pylint: disable = E1101
url = urljoin(self._operations['has-permission'], permission)
_, json = get(url, self._CACHE_TTL)
return json['is-allowed']
示例14: get
def get(self, **kwargs):
"""Implements the client side for the model 'get' operator.
"""
assert len(kwargs), \
"You must supply kwargs to filter on to fetch the instance"
url = urljoin(self._url, 'get/')
_, json = get(url + '?' + urlencode(kwargs), self._CACHE_TTL)
return get_instance_from_data(url, json)
示例15: test_model_operation_with_mock_ua
def test_model_operation_with_mock_ua(self, expect):
expect.get('http://pizzas/app/Model/test-op/', {'test': 'item'})
expect.post('http://pizzas/app/Model/test-op/', {'test': 'item'}, {'item': 'test'})
self.assertEqual(len(expect.expectations), 2)
response1, json1 = get(client.pizzas.app.Model._operations['test-op'])
self.assertEqual(json1, dict(test='item'))
response2, json2 = post(client.pizzas.app.Model._operations['test-op'], json1)
self.assertEqual(json2, dict(item='test'))