本文整理汇总了Python中flask.json.loads方法的典型用法代码示例。如果您正苦于以下问题:Python json.loads方法的具体用法?Python json.loads怎么用?Python json.loads使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.json
的用法示例。
在下文中一共展示了json.loads方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_server_endpoint
# 需要导入模块: from flask import json [as 别名]
# 或者: from flask.json import loads [as 别名]
def test_server_endpoint():
with app.test_client() as client:
assert get_url('server_endpoint') == '/'
tokens_url = get_url(
'token',
token_id='TOKEN_ID',
_external=True
).replace('/TOKEN_ID/', '/')
master_key_url = get_url('master_key', _external=True)
response = client.get('/')
links = dict(parse_link_header(link)[::-1]
for link in response.headers.getlist('Link'))
assert links == {
'tokens': tokens_url,
'masterkey': master_key_url,
}
assert json.loads(response.get_data()) == {
'tokens_url': tokens_url,
'master_key_url': master_key_url,
}
示例2: test_get_identity_403
# 需要导入模块: from flask import json [as 别名]
# 或者: from flask.json import loads [as 别名]
def test_get_identity_403(fx_app, fx_token_store, fx_token_id):
expires_at = (datetime.datetime.now(datetime.timezone.utc) +
datetime.timedelta(hours=1))
fx_token_store.set(
fx_token_id,
Token(Identity(DummyTeam, 1, False), expires_at)
)
with fx_app.test_request_context():
try:
result = get_identity(fx_token_id)
except HTTPException as e:
response = e.get_response(request.environ)
assert response.status_code == 403
data = json.loads(response.get_data())
assert data['error'] == 'not-authorized'
else:
fail('get_identity() does not raise HTTPException, but returns ' +
repr(result))
示例3: test_list_public_keys
# 需要导入模块: from flask import json [as 别名]
# 或者: from flask.json import loads [as 别名]
def test_list_public_keys(fx_app, fx_key_store,
fx_authorized_identity,
fx_token_id):
with fx_app.test_client() as c:
response = c.get(get_url('list_public_keys', token_id=fx_token_id))
assert response.status_code == 200
assert response.mimetype == 'application/json'
assert response.get_data() == b'{}'
key = RSAKey.generate(1024)
fx_key_store.register(fx_authorized_identity, key)
with fx_app.test_client() as c:
response = c.get(get_url('list_public_keys', token_id=fx_token_id))
assert response.status_code == 200
assert response.mimetype == 'application/json'
data = {f: parse_openssh_pubkey(k)
for f, k in json.loads(response.get_data()).items()}
assert data == {get_key_fingerprint(key): key}
示例4: test_authorize_remote_403
# 需要导入模块: from flask import json [as 别名]
# 或者: from flask.json import loads [as 别名]
def test_authorize_remote_403(fx_app, fx_mock_remote_set,
fx_authorized_identity, fx_token_id):
default = fx_app.config['PERMISSION_POLICY']
try:
fx_app.config['PERMISSION_POLICY'] = DisallowAllPolicy()
with fx_app.test_client() as client:
response = client.post(
get_url('authorize_remote',
token_id=fx_token_id,
alias='web-1')
)
assert response.status_code == 403
assert response.mimetype == 'application/json'
result = json.loads(response.get_data())
assert result['error'] == 'forbidden'
finally:
fx_app.config['PERMISSION_POLICY'] = default
示例5: test_run_all_lotteries
# 需要导入模块: from flask import json [as 别名]
# 或者: from flask.json import loads [as 别名]
def test_run_all_lotteries(app, admin):
for _ in xrange(3):
item = InventoryEntry('Item' + str(_), 'Wow lick my socks',
'http://test.co', 'Item', [], '', 3, item_type=ItemType.LOTTERY)
db.session.add(item)
for _ in range(item.quantity + 3):
request_item = RequestItem(item, 1)
request = Request([request_item], admin.id, proposal='Test')
db.session.add(request_item)
db.session.add(request)
db.session.commit()
rv = app.post(url_for('run_all_lotteries'))
assert json.loads(rv.data)['success'] == True
items = InventoryEntry.query.all()
for item in items:
assert RequestItem.query.filter_by(entry_id=item.id) \
.join(Request).filter_by(status=RequestStatus.APPROVED).count() == 3
示例6: _validate_request
# 需要导入模块: from flask import json [as 别名]
# 或者: from flask.json import loads [as 别名]
def _validate_request(self):
request_data = json.loads(self.request.data)
if self.request.method == 'POST':
device = NewDeviceRequest()
device.pairing_code = request_data['pairingCode']
else:
device = UpdateDeviceRequest()
device.city = request_data['city']
device.country = request_data['country']
device.name = request_data['name']
device.placement = request_data['placement']
device.region = request_data['region']
device.timezone = request_data['timezone']
device.wake_word = request_data['wakeWord']
device.voice = request_data['voice']
device.validate()
return device
示例7: _validate_response
# 需要导入模块: from flask import json [as 别名]
# 或者: from flask.json import loads [as 别名]
def _validate_response(self, response, tmpdir=None, code=200, check_content=True):
if tmpdir:
tmpdir.join("response.html").write(response.data, mode='wb')
assert response.status_code == code, "HTTP status: %s" % response.status
if response.data:
response_data = response.data.decode('utf-8')
if check_content:
if response.mimetype == 'text/html':
self._validate_html5(response_data)
elif response.mimetype == 'application/json':
return json.loads(response_data)
else:
raise ValueError("illegal mimetype: '%s'" % response.mimetype)
return response_data
示例8: get_letter_details_from_zips_sent_file
# 需要导入模块: from flask import json [as 别名]
# 或者: from flask.json import loads [as 别名]
def get_letter_details_from_zips_sent_file(file_paths):
"""Get notification details from letters listed in zips_sent file(s)
This takes one or more file paths for the zips_sent files in S3 as its parameters, for example:
get-letter-details-from-zips-sent-file '2019-04-01/zips_sent/filename_1' '2019-04-01/zips_sent/filename_2'
"""
rows_from_file = []
for path in file_paths:
file_contents = s3.get_s3_file(
bucket_name=current_app.config['LETTERS_PDF_BUCKET_NAME'],
file_location=path
)
rows_from_file.extend(json.loads(file_contents))
notification_references = tuple(row[18:34] for row in rows_from_file)
get_letters_data_from_references(notification_references)
示例9: test_receive_notification_returns_received_to_mmg
# 需要导入模块: from flask import json [as 别名]
# 或者: from flask.json import loads [as 别名]
def test_receive_notification_returns_received_to_mmg(client, mocker, sample_service_full_permissions):
mocked = mocker.patch("app.notifications.receive_notifications.tasks.send_inbound_sms_to_service.apply_async")
prom_counter_labels_mock = mocker.patch('app.notifications.receive_notifications.INBOUND_SMS_COUNTER.labels')
data = {
"ID": "1234",
"MSISDN": "447700900855",
"Message": "Some message to notify",
"Trigger": "Trigger?",
"Number": sample_service_full_permissions.get_inbound_number(),
"Channel": "SMS",
"DateRecieved": "2012-06-27 12:33:00"
}
response = mmg_post(client, data)
assert response.status_code == 200
result = json.loads(response.get_data(as_text=True))
assert result['status'] == 'ok'
prom_counter_labels_mock.assert_called_once_with("mmg")
prom_counter_labels_mock.return_value.inc.assert_called_once_with()
inbound_sms_id = InboundSms.query.all()[0].id
mocked.assert_called_once_with(
[str(inbound_sms_id), str(sample_service_full_permissions.id)], queue="notify-internal-tasks")
示例10: test_create_access_token
# 需要导入模块: from flask import json [as 别名]
# 或者: from flask.json import loads [as 别名]
def test_create_access_token(fx_app, fx_token_id) -> None:
url = get_url('create_access_token', token_id=fx_token_id)
with app.test_client() as c:
response = c.put(url)
assert response.status_code == 202
link = response.headers['Link']
assert link.startswith('<http://example.com/auth/')
assert link.endswith('>; rel=next')
qs = url_decode(link[link.find('?') + 1:link.find('>')])
result = json.loads(response.get_data())
assert qs['redirect_url'] == get_url('authenticate',
token_id=fx_token_id,
_external=True)
assert result == {'next_url': link[1:link.find('>')]}
示例11: test_get_identity_404
# 需要导入模块: from flask import json [as 别名]
# 或者: from flask.json import loads [as 别名]
def test_get_identity_404(fx_app, fx_token_id):
with fx_app.test_request_context():
try:
result = get_identity(fx_token_id)
except HTTPException as e:
response = e.get_response(request.environ)
assert response.status_code == 404
data = json.loads(response.get_data())
assert data['error'] == 'token-not-found'
else:
fail('get_identity() does not raise HTTPException, but returns ' +
repr(result))
示例12: test_get_identity_412
# 需要导入模块: from flask import json [as 别名]
# 或者: from flask.json import loads [as 别名]
def test_get_identity_412(fx_app, fx_token_store, fx_token_id):
fx_token_store.set(fx_token_id, 'nonce')
with fx_app.test_request_context():
try:
result = get_identity(fx_token_id)
except HTTPException as e:
response = e.get_response(request.environ)
assert response.status_code == 412
data = json.loads(response.get_data())
assert data['error'] == 'unfinished-authentication'
else:
fail('get_identity() does not raise HTTPException, but returns ' +
repr(result))
示例13: test_token_412
# 需要导入模块: from flask import json [as 别名]
# 或者: from flask.json import loads [as 别名]
def test_token_412(fx_app, fx_token_store, fx_token_id):
fx_token_store.set(fx_token_id, 'nonce')
with fx_app.test_client() as c:
url = get_url('token', token_id=fx_token_id)
response = c.get(url)
assert response.status_code == 412
assert response.headers['content-type'] == 'application/json'
content = response.get_data(as_text=True)
assert content
print(content)
assert json.loads(content)['error'] == 'unfinished-authentication'
示例14: test_token_404
# 需要导入模块: from flask import json [as 别名]
# 或者: from flask.json import loads [as 别名]
def test_token_404(fx_app, fx_token_id):
with fx_app.test_client() as c:
response = c.get(get_url('token', token_id=fx_token_id))
assert response.status_code == 404
assert json.loads(response.get_data())['error'] == 'token-not-found'
示例15: test_add_public_key_415
# 需要导入模块: from flask import json [as 别名]
# 或者: from flask.json import loads [as 别名]
def test_add_public_key_415(fx_app, fx_key_store,
fx_authorized_identity, fx_token_id):
pkey = RSAKey.generate(1024)
with fx_app.test_client() as c:
response = c.post(
get_url('add_public_key', token_id=fx_token_id),
data={'key': format_openssh_pubkey(pkey)}
)
assert response.status_code == 415
error = json.loads(response.get_data())
assert error['error'] == 'unsupported-content-type'
assert pkey not in fx_key_store.list_keys(fx_authorized_identity)