本文整理汇总了Python中httpretty.POST属性的典型用法代码示例。如果您正苦于以下问题:Python httpretty.POST属性的具体用法?Python httpretty.POST怎么用?Python httpretty.POST使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类httpretty
的用法示例。
在下文中一共展示了httpretty.POST属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import POST [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: test_can_process_userinfo_included_in_the_id_token_instead_of_calling_the_userinfo_endpoint
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import POST [as 别名]
def test_can_process_userinfo_included_in_the_id_token_instead_of_calling_the_userinfo_endpoint(
self, rf):
httpretty.register_uri(
httpretty.POST, oidc_rp_settings.PROVIDER_TOKEN_ENDPOINT,
body=json.dumps({
'id_token': self.generate_jws(email='test1@example.com'),
'access_token': 'accesstoken',
'refresh_token': 'refreshtoken',
}),
content_type='text/json')
request = rf.get('/oidc/cb/', {'state': 'state', 'code': 'authcode', })
SessionMiddleware().process_request(request)
request.session.save()
backend = OIDCAuthBackend()
user = backend.authenticate(request, 'nonce')
assert user.email == 'test1@example.com'
assert user.oidc_user.sub == '1234'
示例3: test_log_out_the_user_if_the_id_token_is_not_valid
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import POST [as 别名]
def test_log_out_the_user_if_the_id_token_is_not_valid(self, rf):
request = rf.get('/oidc/cb/', {'state': 'state', 'code': 'authcode', })
SessionMiddleware().process_request(request)
request.session.save()
backend = OIDCAuthBackend()
user = backend.authenticate(request, 'nonce')
request.session['oidc_auth_id_token_exp_timestamp'] = \
(tz.now() - dt.timedelta(minutes=1)).timestamp()
request.session['oidc_auth_refresh_token'] = 'this_is_a_refresh_token'
auth.login(request, user)
request.user = user
httpretty.register_uri(
httpretty.POST, oidc_rp_settings.PROVIDER_TOKEN_ENDPOINT,
body=json.dumps({
'id_token': 'badidtoken', 'access_token': 'accesstoken',
'refresh_token': 'refreshtoken', }),
content_type='text/json')
middleware = OIDCRefreshIDTokenMiddleware(lambda r: 'OK')
middleware(request)
assert not request.user.is_authenticated
示例4: configure_httpretty
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import POST [as 别名]
def configure_httpretty(sitedir):
httpretty.enable()
dir = Path(f"tests/test_sites/data/test_{sitedir}/")
data_file = dir / 'data.json'
data = None
with open(data_file) as f:
data = json.load(f)
for obj in data:
method = httpretty.POST
if obj['method'] == 'GET':
method = httpretty.GET
with open(dir / obj['file']) as f:
httpretty.register_uri(
method,
obj['url'],
f.read(),
)
示例5: test_send_key_with_file
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import POST [as 别名]
def test_send_key_with_file(self):
driver = android_w3c_driver()
# Should not send this file
tmp_f = tempfile.NamedTemporaryFile()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/element/element_id/value')
)
try:
element = MobileWebElement(driver, 'element_id', w3c=True)
element.send_keys(tmp_f.name)
finally:
tmp_f.close()
d = get_httpretty_request_body(httpretty.last_request())
assert d['text'] == ''.join(d['value'])
示例6: test_find_element_by_android_data_matcher
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import POST [as 别名]
def test_find_element_by_android_data_matcher(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/element'),
body='{"value": {"element-6066-11e4-a52e-4f735466cecf": "element-id"}}'
)
el = driver.find_element_by_android_data_matcher(
name='title', args=['title', 'Animation'], className='class name')
d = get_httpretty_request_body(httpretty.last_request())
assert d['using'] == '-android datamatcher'
value_dict = json.loads(d['value'])
assert value_dict['args'] == ['title', 'Animation']
assert value_dict['name'] == 'title'
assert value_dict['class'] == 'class name'
assert el.id == 'element-id'
示例7: test_find_elements_by_android_data_matcher
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import POST [as 别名]
def test_find_elements_by_android_data_matcher(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/elements'),
body='{"value": [{"element-6066-11e4-a52e-4f735466cecf": "element-id1"}, {"element-6066-11e4-a52e-4f735466cecf": "element-id2"}]}'
)
els = driver.find_elements_by_android_data_matcher(name='title', args=['title', 'Animation'])
d = get_httpretty_request_body(httpretty.last_request())
assert d['using'] == '-android datamatcher'
value_dict = json.loads(d['value'])
assert value_dict['args'] == ['title', 'Animation']
assert value_dict['name'] == 'title'
assert els[0].id == 'element-id1'
assert els[1].id == 'element-id2'
示例8: because_an_event_is_published_on_a_stream
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import POST [as 别名]
def because_an_event_is_published_on_a_stream(self):
httpretty.register_uri(
httpretty.POST,
"http://{}:{}/streams/{}".format(self._host, self._port, self.stream),
body='{}')
data = {'foo': 'bar'}
metadata = {'lorem': 'ipsum'}
evt = Event(
id=self.event_id,
type='my-event-type',
data=data,
stream=self.stream,
sequence=None,
metadata=metadata,
)
self.publisher.post(evt, correlation_id=self.correlation_id)
self.response_body = json.loads(httpretty.last_request().body.decode())[0]
示例9: test_cannot_authenticate_a_user_if_the_id_token_validation_fails
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import POST [as 别名]
def test_cannot_authenticate_a_user_if_the_id_token_validation_fails(self, rf):
httpretty.register_uri(
httpretty.POST, oidc_rp_settings.PROVIDER_TOKEN_ENDPOINT,
body=json.dumps({
'id_token': 'badidtoken', 'access_token': 'accesstoken',
'refresh_token': 'refreshtoken', }),
content_type='text/json')
request = rf.get('/oidc/cb/', {'state': 'state', 'code': 'authcode', })
SessionMiddleware().process_request(request)
request.session.save()
backend = OIDCAuthBackend()
assert backend.authenticate(request, 'nonce') is None
示例10: test_request_timeout
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import POST [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()
示例11: test_update_settings_bool
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import POST [as 别名]
def test_update_settings_bool(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/appium/settings'),
)
assert isinstance(driver.update_settings({"sample": True}), WebDriver)
d = get_httpretty_request_body(httpretty.last_request())
assert d['settings']['sample'] is True
示例12: test_update_settings_string
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import POST [as 别名]
def test_update_settings_string(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/appium/settings'),
)
assert isinstance(driver.update_settings({"sample": 'string'}), WebDriver)
d = get_httpretty_request_body(httpretty.last_request())
assert d['settings']['sample'] == 'string'
示例13: test_set_value
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import POST [as 别名]
def test_set_value(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/appium/element/element_id/value')
)
element = MobileWebElement(driver, 'element_id', w3c=True)
value = 'happy testing'
element.set_value(value)
d = get_httpretty_request_body(httpretty.last_request())
assert d['value'] == [value]
示例14: test_send_key
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import POST [as 别名]
def test_send_key(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/element/element_id/value')
)
element = MobileWebElement(driver, 'element_id', w3c=True)
element.send_keys('happy testing')
d = get_httpretty_request_body(httpretty.last_request())
assert d['text'] == ''.join(d['value'])
示例15: test_press_keycode
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import POST [as 别名]
def test_press_keycode(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/appium/device/press_keycode'),
body='{"value": "86"}'
)
driver.press_keycode(86)
d = get_httpretty_request_body((httpretty.last_request()))
assert d['keycode'] == 86