本文整理汇总了Python中httpretty.disable方法的典型用法代码示例。如果您正苦于以下问题:Python httpretty.disable方法的具体用法?Python httpretty.disable怎么用?Python httpretty.disable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类httpretty
的用法示例。
在下文中一共展示了httpretty.disable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import disable [as 别名]
def setup(self):
httpretty.enable()
self.key = RSAKey(kid='testkey').load(os.path.join(FIXTURE_ROOT, 'testkey.pem'))
def jwks(_request, _uri, headers): # noqa: E306
ks = KEYS()
ks.add(self.key.serialize())
return 200, headers, ks.dump_jwks()
httpretty.register_uri(
httpretty.GET, oidc_rp_settings.PROVIDER_JWKS_ENDPOINT, status=200, body=jwks)
httpretty.register_uri(
httpretty.POST, oidc_rp_settings.PROVIDER_TOKEN_ENDPOINT,
body=json.dumps({
'id_token': self.generate_jws(), 'access_token': 'accesstoken',
'refresh_token': 'refreshtoken', }),
content_type='text/json')
httpretty.register_uri(
httpretty.GET, oidc_rp_settings.PROVIDER_USERINFO_ENDPOINT,
body=json.dumps({'sub': '1234', 'email': 'test@example.com', }),
content_type='text/json')
yield
httpretty.disable()
示例2: endpoints
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import disable [as 别名]
def endpoints():
httpretty.enable()
with open(os.path.join(TESTS_DIR, 'endpoints.json')) as resource:
test_data = json.load(resource)
endpoints = test_data['endpoints']
for endpoint, options in endpoints.items():
if isinstance(options.get('body'), (dict, list, tuple)):
body = json.dumps(options.get('body'))
else:
body = options.get('body')
httpretty.register_uri(method=options.get('method', 'GET'),
status=options.get('status', 200),
uri=API_URL + endpoint,
body=body)
yield endpoints
httpretty.disable()
示例3: test_get_lms_resource_for_user_caching_none
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import disable [as 别名]
def test_get_lms_resource_for_user_caching_none(self):
"""
LMS resource should be properly cached when enrollments is None.
"""
basket = BasketFactory(site=self.site, owner=UserFactory())
resource_name = 'test_resource_name'
mock_endpoint = mock.Mock()
mock_endpoint.get.return_value = None
return_value = self.condition._get_lms_resource_for_user(basket, resource_name, mock_endpoint) # pylint: disable=protected-access
self.assertEqual(return_value, [])
self.assertEqual(mock_endpoint.get.call_count, 1, 'Endpoint should be called before caching.')
mock_endpoint.reset_mock()
return_value = self.condition._get_lms_resource_for_user(basket, resource_name, mock_endpoint) # pylint: disable=protected-access
self.assertEqual(return_value, [])
self.assertEqual(mock_endpoint.get.call_count, 0, 'Endpoint should NOT be called after caching.')
示例4: test_get
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import disable [as 别名]
def test_get(self):
""" The context should contain a list of program offers. """
# These should be ignored since their associated Condition objects do NOT have a program UUID.
factories.ConditionalOfferFactory.create_batch(3)
program_offers = factories.ProgramOfferFactory.create_batch(4, partner=self.partner)
for offer in program_offers:
self.mock_program_detail_endpoint(offer.condition.program_uuid, self.site_configuration.discovery_api_url)
response = self.assert_get_response_status(200)
self.assertEqual(list(response.context['object_list']), program_offers)
# The page should load even if the Programs API is inaccessible
httpretty.disable()
response = self.assert_get_response_status(200)
self.assertEqual(list(response.context['object_list']), program_offers)
示例5: test_course_name_missing
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import disable [as 别名]
def test_course_name_missing(self):
"""Verify the Course Structure API is queried if the Commerce API doesn't return a course name."""
# Mock the Commerce API so that it does not return a name
body = {
'name': None,
'verification_deadline': EXPIRES_STRING,
}
httpretty.register_uri(httpretty.GET, self.commerce_api_url, body=json.dumps(body), content_type=JSON)
# Mock the Course Structure API
httpretty.register_uri(httpretty.GET, self.course_structure_url, body='{}', content_type=JSON)
# Try migrating the course, which should fail.
try:
migrated_course = MigratedCourse(self.course_id, self.site.domain)
migrated_course.load_from_lms()
except Exception as ex: # pylint: disable=broad-except
self.assertEqual(six.text_type(ex),
'Aborting migration. No name is available for {}.'.format(self.course_id))
# Verify the Course Structure API was called.
last_request = httpretty.last_request()
self.assertEqual(last_request.path, urlparse(self.course_structure_url).path)
示例6: test_get
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import disable [as 别名]
def test_get(self):
""" The context should contain a list of enterprise offers. """
# These should be ignored since their associated Condition objects do NOT have an Enterprise Customer UUID.
factories.ConditionalOfferFactory.create_batch(3)
enterprise_offers = factories.EnterpriseOfferFactory.create_batch(4, partner=self.partner)
for offer in enterprise_offers:
self.mock_specific_enterprise_customer_api(offer.condition.enterprise_customer_uuid)
response = self.assert_get_response_status(200)
self.assertEqual(list(response.context['object_list']), enterprise_offers)
# The page should load even if the Enterprise API is inaccessible
httpretty.disable()
response = self.assert_get_response_status(200)
self.assertEqual(list(response.context['object_list']), enterprise_offers)
示例7: test_write_query_gzip
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import disable [as 别名]
def test_write_query_gzip(self):
httpretty.disable()
self.client = InfluxDBClient(self.host, token="my-token", org="my-org", debug=False,
enable_gzip=True)
self.api_client = self.client.api_client
self.buckets_client = self.client.buckets_api()
self.query_client = self.client.query_api()
self.org = "my-org"
self.my_organization = self.find_my_org()
_bucket = self.create_test_bucket()
self.client.write_api(write_options=SYNCHRONOUS) \
.write(_bucket.name, self.org, "h2o_feet,location=coyote_creek water_level=111.0 1")
_result = self.query_client.query(
"from(bucket:\"{0}\") |> range(start: 1970-01-01T00:00:00.000000001Z) |> last()".format(_bucket.name),
self.org)
self.assertEqual(len(_result), 1)
self.assertEqual(_result[0].records[0].get_measurement(), "h2o_feet")
self.assertEqual(_result[0].records[0].get_value(), 111.0)
self.assertEqual(_result[0].records[0].get_field(), "water_level")
示例8: tearDown
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import disable [as 别名]
def tearDown(self):
httpretty.disable()
httpretty.reset()
示例9: setup
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import disable [as 别名]
def setup(self):
httpretty.enable()
self.key = RSAKey(kid='testkey').load(os.path.join(FIXTURE_ROOT, 'testkey.pem'))
def jwks(_request, _uri, headers): # noqa: E306
ks = KEYS()
ks.add(self.key.serialize())
return 200, headers, ks.dump_jwks()
httpretty.register_uri(
httpretty.GET, oidc_rp_settings.PROVIDER_JWKS_ENDPOINT, status=200, body=jwks)
yield
httpretty.disable()
示例10: tearDown
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import disable [as 别名]
def tearDown(self):
httpretty.reset()
httpretty.disable()
示例11: test_request_timeout
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import disable [as 别名]
def test_request_timeout():
timeout = 0.1
http_scheme = "http"
host = "coordinator"
port = 8080
url = http_scheme + "://" + host + ":" + str(port) + constants.URL_STATEMENT_PATH
def long_call(request, uri, headers):
time.sleep(timeout * 2)
return (200, headers, "delayed success")
httpretty.enable()
for method in [httpretty.POST, httpretty.GET]:
httpretty.register_uri(method, url, body=long_call)
# timeout without retry
for request_timeout in [timeout, (timeout, timeout)]:
req = PrestoRequest(
host=host,
port=port,
user="test",
http_scheme=http_scheme,
max_attempts=1,
request_timeout=request_timeout,
)
with pytest.raises(requests.exceptions.Timeout):
req.get(url)
with pytest.raises(requests.exceptions.Timeout):
req.post("select 1")
httpretty.disable()
httpretty.reset()
示例12: patch_get
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import disable [as 别名]
def patch_get():
httpretty.enable()
yield partial(httpretty.register_uri, httpretty.GET)
httpretty.disable()
httpretty.reset()
示例13: test_it_works_with_remote_files
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import disable [as 别名]
def test_it_works_with_remote_files(datapackage_zip):
httpretty.enable()
datapackage_zip.seek(0)
url = 'http://someplace.com/datapackage.zip'
httpretty.register_uri(
httpretty.GET, url, body=datapackage_zip.read(), content_type='application/zip')
package = Package(url)
assert package.descriptor['name'] == 'proverbs'
assert len(package.resources) == 1
assert package.resources[0].data == b'foo\n'
httpretty.disable()
示例14: tearDown
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import disable [as 别名]
def tearDown(self):
super(ModulesTests, self).tearDown()
httpretty.disable()
示例15: tearDown
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import disable [as 别名]
def tearDown(self):
super(CoursesTests, self).tearDown()
httpretty.disable()