Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def httprettify():
'''Context manager to do what the @httprettified decorator does (without
mucking up py.test's magic)
'''
httpretty.HTTPretty.reset()
httpretty.HTTPretty.enable()
try:
yield httpretty.HTTPretty
finally:
httpretty.HTTPretty.disable()
def setUp(self):
httpretty.HTTPretty.enable()
httpretty.register_uri(httpretty.GET, '%s/%s' % (constants.BASE_URL,
'item?id=6115341'),
body=get_content('6115341.html'))
self.PY2 = sys.version_info[0] == 2
if not self.PY2:
self.text_type = [str]
else:
self.text_type = [unicode, str]
# https://news.ycombinator.com/item?id=6115341
self.story = Story.fromid(6115341)
def setUp(self):
HTTPretty.enable()
HTTPretty.register_uri(
HTTPretty.POST,
("http://doc-demo-userdomain.us-east-1.cloudsearch.amazonaws.com/"
"2013-01-01/documents/batch"),
body=json.dumps(self.response),
content_type="application/json")
def test_start_works_and_sets_id(self):
url = '{0}/backup/action-requested'.format(self.connection.host)
HTTPretty.register_uri(HTTPretty.POST, url, body=json.dumps(100))
self.cmd.start()
self.assertEqual(self.cmd.id, 100)
start_query = parse_qs(urlparse(start_url).query)
location_url = target_url + ('?' in target_url and '&' or '?') + \
'state=' + start_query['state']
location_query = parse_qs(urlparse(location_url).query)
HTTPretty.register_uri(HTTPretty.GET, start_url, status=301,
location=location_url)
HTTPretty.register_uri(HTTPretty.GET, location_url, status=200,
body='foobar')
response = requests.get(start_url)
expect(response.url).to.equal(location_url)
expect(response.text).to.equal('foobar')
HTTPretty.register_uri(HTTPretty.GET,
uri=self.backend.ACCESS_TOKEN_URL,
status=200,
body=self.access_token_body or '',
content_type='text/json')
if self.user_data_url:
HTTPretty.register_uri(HTTPretty.GET, self.user_data_url,
body=self.user_data_body or '',
content_type='text/json')
self.strategy.set_request_data(location_query)
def _login(strategy, user):
strategy.session_set('username', user.username)
redirect = do_complete(self.strategy, user=self.user, login=_login)
url = self.strategy.build_absolute_uri('/password')
def test_urls(self):
HTTPretty.register_uri(HTTPretty.GET, self.URL)
client = Hammock(self.BASE_URL)
combs = [
client.sample.path.to.resource,
client('sample').path('to').resource,
client('sample', 'path', 'to', 'resource'),
client('sample')('path')('to')('resource'),
client.sample('path')('to', 'resource'),
client('sample', 'path',).to.resource
]
for comb in combs:
self.assertEqual(str(comb), self.URL)
resp = comb.GET()
self.assertEqual(HTTPretty.last_request.path, self.PATH)
def tearDown(self):
httpretty.HTTPretty.disable()
def register_hal_page(doc, **kwargs):
status = kwargs.pop('status', 200)
method = kwargs.pop('method', 'GET')
content_type = kwargs.pop('content_type', 'application/hal+json')
def body_callback(request, url, headers):
'''We do a callback so the response body can be updated'''
headers2 = kwargs.pop('headers', headers)
return (
status,
headers2,
json.dumps(doc),
)
httpretty.HTTPretty.register_uri(
method,
body=body_callback,
content_type=content_type,
uri=uri_of(doc),
**kwargs
)
"limit": 25,
"items": [self.app_body]
}
httpretty.register_uri(httpretty.GET,
self.tenant_href + "/applications",
body=json.dumps(self.resource_body),
content_type="application/json")
applications = self.client.applications.search(self.app_body["name"])
for app in applications:
pass
self.assertIsInstance(applications, CollectionResource)
self.assertEqual(HTTPretty.last_request.method, 'GET')
self.assertEqual(HTTPretty.last_request.path,
"%s/applications?q=%s" % (self.tenant_path, self.app_body['name']))
# search tenant directories
self.resource_body = {
"href": self.tenant_href + "/directories",
"offset": 0,
"limit": 25,
"items": [self.dir_body]
}
httpretty.register_uri(httpretty.GET,
self.tenant_href + "/directories",
body=json.dumps(self.resource_body),
content_type="application/json")
directories = self.client.directories.search(self.dir_body['name'])