本文整理汇总了Python中seplis.utils.json_loads函数的典型用法代码示例。如果您正苦于以下问题:Python json_loads函数的具体用法?Python json_loads怎么用?Python json_loads使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了json_loads函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_item_list_updates
def test_item_list_updates(self):
show_id = self.new_show()
response = self.patch('/1/shows/{}'.format(show_id), {
'alternative_titles': [
'test',
],
})
self.assertEqual(response.code, 200, response.body)
show = utils.json_loads(response.body)
self.assertTrue('test' in show['alternative_titles'])
# append and duplicate
response = self.patch('/1/shows/{}'.format(show_id), {
'alternative_titles': [
'test',
'test2'
],
})
self.assertEqual(response.code, 200, response.body)
show = utils.json_loads(response.body)
self.assertTrue('test' in show['alternative_titles'])
self.assertTrue('test2' in show['alternative_titles'])
response = self.patch('/1/shows/{}'.format(show_id), {
'alternative_titles': [
'test',
'test',
'test2'
],
})
self.assertEqual(response.code, 200, response.body)
show = utils.json_loads(response.body)
self.assertTrue('test' in show['alternative_titles'])
self.assertTrue('test2' in show['alternative_titles'])
开发者ID:thomaserlang,项目名称:seplis,代码行数:34,代码来源:test_show.py
示例2: test_post
def test_post(self):
response = self.post('/1/users', {
'name': 'testø',
'email': 'wrongemail',
'password': 'hej',
})
self.assertEqual(response.code, 400)
error = utils.json_loads(response.body)
for error in error['errors']:
if error['message'] == 'required key not provided':
continue
if error['field'] == 'name':
self.assertEqual(error['message'], 'must only contain a-z, 0-9, _ and - for dictionary value')
elif error['field'] == 'email':
self.assertEqual(error['message'], 'this is an invalid email address for dictionary value')
elif error['field'] == 'password':
self.assertEqual(error['message'], 'length of value must be at least 6 for dictionary value')
response = self.post('/1/users', {
'name': 'test',
'email': '[email protected]',
'password': '123456',
})
self.assertEqual(response.code, 201)
user = utils.json_loads(response.body)
self.assertEqual(user['name'], 'test')
self.assertEqual(user['email'], '[email protected]')
self.assertTrue('password' not in user)
self.assertTrue('created' in user)
开发者ID:jonathan1994,项目名称:seplis,代码行数:29,代码来源:test_user.py
示例3: test
def test(self):
self.login(constants.LEVEL_EDIT_SHOW)
response = self.post('/1/shows', {
'title': 'Test show',
'episodes': [
{
'title': 'Episode 1',
'number': 1,
},
],
})
self.assertEqual(response.code, 201, response.body)
show = utils.json_loads(response.body)
response = self.post('/1/play-servers'.format(self.current_user.id), {
'name': 'Thomas',
'url': 'http://example.net',
'secret': 'SOME SECRET',
})
self.assertEqual(response.code, 201, response.body)
server = utils.json_loads(response.body)
# Let's get the server that the user has access to
# with a play id, that we can use when contacting the server.
response = self.get('/1/shows/{}/episodes/1/play-servers'.format(
show['id'],
))
self.assertEqual(response.code, 200)
servers = utils.json_loads(response.body)
self.assertEqual(len(servers), 1)
self.assertEqual(servers[0]['play_url'], 'http://example.net')
self.assertTrue(servers[0]['play_id'])
开发者ID:thomaserlang,项目名称:seplis,代码行数:32,代码来源:test_episode.py
示例4: test_get
def test_get(self):
# new user
response = self.post('/1/users', {
'name': 'test',
'email': '[email protected]',
'password': '123456',
})
self.assertEqual(response.code, 201)
user = utils.json_loads(response.body)
# we should not be able to retrieve any users without being logged in
response = self.get('/1/users/{}'.format(user['id']))
self.assertEqual(response.code, 401)
# login and test that we can retrieve the user.
# because our user does not have a high enough level to view the email
# it should not be there.
self.login(user_level=2)
response = self.get('/1/users/{}'.format(user['id']))
self.assertEqual(response.code, 200)
user2 = utils.json_loads(response.body)
self.assertEqual(user2['name'], 'test')
self.assertFalse('email' in user2)
user.pop('email')
self.assertEqual(user2, user)
# check that we can get the current user.
# when we retrieve our own user name the email
# should be visible.
response = self.get('/1/users/current')
self.assertEqual(response.code, 200)
user3 = utils.json_loads(response.body)
self.assertEqual(user3['email'], self.current_user.email)
开发者ID:jonathan1994,项目名称:seplis,代码行数:33,代码来源:test_user.py
示例5: es
def es(self, url, query={}, body={}):
http_client = AsyncHTTPClient()
if not url.startswith('/'):
url = '/'+url
for arg in query:
if not isinstance(query[arg], list):
query[arg] = [query[arg]]
try:
response = yield http_client.fetch(
'http://{}{}?{}'.format(
config['api']['elasticsearch'],
url,
utils.url_encode_tornado_arguments(query) \
if query else '',
),
method='POST' if body else 'GET',
body=utils.json_dumps(body) if body else None,
)
return utils.json_loads(response.body)
except HTTPError as e:
try:
extra = utils.json_loads(e.response.body)
except:
extra = {'error': e.response.body.decode('utf-8')}
raise exceptions.Elasticsearch_exception(
e.code,
extra,
)
开发者ID:jonathan1994,项目名称:seplis,代码行数:28,代码来源:base.py
示例6: test_search
def test_search(self):
show_id1 = self.new_show()
response = self.patch('/1/shows/{}'.format(show_id1), {
'title': 'This is a test show',
'premiered': '2013-01-01',
})
self.assertEqual(response.code, 200)
response = self.get('/1/shows/{}'.format(show_id1))
self.assertEqual(response.code, 200)
show = utils.json_loads(response.body)
self.assertEqual(show['title'], 'This is a test show')
show_id2 = self.new_show()
response = self.patch('/1/shows/{}'.format(show_id2), {
'title': 'Test show',
'premiered': '2014-01-01',
})
self.assertEqual(response.code, 200)
self.get('http://{}/shows/_refresh'.format(
config['api']['elasticsearch']
))
response = self.get('/1/shows', {
'q': 'this is a',
})
self.assertEqual(response.code, 200)
shows = utils.json_loads(response.body)
self.assertEqual(len(shows), 1)
self.assertEqual(shows[0]['title'], 'This is a test show')
开发者ID:thomaserlang,项目名称:seplis,代码行数:29,代码来源:test_show.py
示例7: test_single
def test_single(self):
self.login(0)
# create a new play server
response = self.post('/1/play-servers'.format(self.current_user.id), {
'name': 'Thomas',
'url': 'http://example.net',
'secret': 'SOME SECRET',
})
self.assertEqual(response.code, 201, response.body)
server = utils.json_loads(response.body)
self.assertEqual(server['name'], 'Thomas')
self.assertEqual(server['url'], 'http://example.net')
self.assertEqual(server['secret'], 'SOME SECRET')
self.assertTrue(server['created'])
self.assertTrue(server['updated'])
self.assertTrue(server['external_id'])
self.assertEqual(server['user_id'], self.current_user.id)
# get
response = self.get('/1/play-servers/{}'.format(
server['id']
))
self.assertEqual(response.code, 200)
server = utils.json_loads(response.body)
self.assertEqual(server['name'], 'Thomas')
self.assertEqual(server['url'], 'http://example.net')
self.assertEqual(server['secret'], 'SOME SECRET')
self.assertTrue(server['updated'])
self.assertEqual(server['user_id'], self.current_user.id)
self.assertTrue(isinstance(server['id'], int))
# edit
response = self.put('/1/play-servers/{}'.format(
server['id']
), {
'name': 'Thomas 2',
'url': 'http://example2.net',
'secret': 'SOME SECRET 2',
})
self.assertEqual(response.code, 200)
server = utils.json_loads(response.body)
self.assertEqual(server['name'], 'Thomas 2')
self.assertEqual(server['url'], 'http://example2.net')
self.assertEqual(server['secret'], 'SOME SECRET 2')
self.assertTrue(server['updated'])
# delete
response = self.delete('/1/play-servers/{}'.format(
server['id']
))
self.assertEqual(response.code, 204)
# get
response = self.get('/1/play-servers/{}'.format(
server['id']
))
self.assertEqual(response.code, 404)
开发者ID:thomaserlang,项目名称:seplis,代码行数:59,代码来源:test_play_server.py
示例8: test
def test(self):
self.login(constants.LEVEL_EDIT_SHOW)
response = self.post('/1/shows', {
'title': 'Test show 1',
'episodes': [
{
'number': 1,
'air_date': (datetime.utcnow()-timedelta(days=1)).date().isoformat(),
},
{
'number': 2,
'air_date': datetime.utcnow().date().isoformat(),
},
{
'number': 3,
'air_date': (datetime.utcnow()+timedelta(days=1)).date().isoformat(),
},
],
})
self.assertEqual(response.code, 201)
show = utils.json_loads(response.body)
response = self.post('/1/shows', {
'title': 'Test show 2',
'episodes': [
{
'number': 1,
'air_date': (datetime.utcnow()-timedelta(days=1)).date().isoformat(),
},
{
'number': 2,
'air_date': datetime.utcnow().date().isoformat(),
},
{
'number': 3,
'air_date': (datetime.utcnow()+timedelta(days=1)).date().isoformat(),
},
],
})
self.assertEqual(response.code, 201)
# Not a fan yet = empty
response = self.get('/1/users/{}/shows-countdown'.format(self.current_user.id))
self.assertEqual(response.code, 200, response.body)
shows = utils.json_loads(response.body)
self.assertEqual(shows, [])
response = self.put('/1/users/{}/fan-of/{}'.format(
self.current_user.id, show['id'],
))
response = self.get('/1/users/{}/shows-countdown'.format(self.current_user.id))
self.assertEqual(response.code, 200, response.body)
shows = utils.json_loads(response.body)
self.assertEqual(len(shows), 1)
self.assertEqual(shows[0]['show']['title'], 'Test show 1')
self.assertEqual(shows[0]['episode']['number'], 3)
开发者ID:thomaserlang,项目名称:seplis,代码行数:57,代码来源:test_shows_countdown.py
示例9: test
def test(self):
self.login(3)
user = User.new(
name='testuser2',
email='[email protected]e.com',
level=0,
)
response = self.post('/1/users/{}/play-servers'.format(self.current_user.id), {
'name': 'Thomas',
'url': 'http://example.net',
'secret': 'SOME SECRET',
})
self.assertEqual(response.code, 201)
server = utils.json_loads(response.body)
# Test that only the user who created the server has access
response = self.get('/1/users/{}/play-servers/{}/users'.format(
self.current_user.id,
server['id'],
))
self.assertEqual(response.code, 200, response.body)
users = utils.json_loads(response.body)
self.assertEqual(len(users), 1)
self.assertEqual(users[0]['id'], self.current_user.id)
# Let's get the user access to the play server
response = self.put('/1/users/{}/play-servers/{}/users/{}'.format(
self.current_user.id,
server['id'],
user.id,
))
# Now the user should have access
response = self.get('/1/users/{}/play-servers/{}/users'.format(
self.current_user.id,
server['id'],
))
self.assertEqual(response.code, 200, response.body)
users = utils.json_loads(response.body)
self.assertEqual(len(users), 2)
self.assertEqual(users[1]['id'], user.id)
# Remove the user from the server access list
response = self.delete('/1/users/{}/play-servers/{}/users/{}'.format(
self.current_user.id,
server['id'],
user.id,
))
response = self.get('/1/users/{}/play-servers/{}/users'.format(
self.current_user.id,
server['id'],
))
self.assertEqual(response.code, 200, response.body)
users = utils.json_loads(response.body)
self.assertEqual(len(users), 1)
self.assertEqual(users[0]['id'], self.current_user.id)
开发者ID:jonathan1994,项目名称:seplis,代码行数:57,代码来源:test_play.py
示例10: test_indices
def test_indices(self):
show_id = self.new_show()
# it should not be possible to add a index with out it exists as
# a external.
response = self.patch('/1/shows/{}'.format(show_id), {
'indices':{
'info': 'imdb',
}
})
self.assertEqual(response.code, 400, response.body)
error = utils.json_loads(response.body)
self.assertEqual(error['code'], 1401)
# so when adding the index to the externals with a value
# it should be OK.
response = self.patch('/1/shows/{}'.format(show_id), {
'indices':{
'info': 'imdb',
},
'externals': {
'imdb': 'tt1234',
}
})
self.assertEqual(response.code, 200, response.body)
show = utils.json_loads(response.body)
self.assertEqual(show['indices'], {
'info': 'imdb',
'episodes': None,
'images': None,
})
self.assertEqual(show['externals'], {
'imdb': 'tt1234',
})
# it should be possible to set both the index and the external
# value to None.
response = self.patch('/1/shows/{}'.format(show_id), {
'indices':{
'info': None,
},
'externals': {
'imdb': None,
}
})
show = utils.json_loads(response.body)
self.assertEqual(response.code, 200, response.body)
self.assertEqual(show['indices'], {
'info': None,
'episodes': None,
'images': None,
})
self.assertEqual(show['externals'], {
'imdb': None,
})
开发者ID:jonathan1994,项目名称:seplis,代码行数:57,代码来源:test_show.py
示例11: test_add_image
def test_add_image(self):
self.login(constants.LEVEL_EDIT_SHOW)
response = self.post('/1/shows/1/images', {
'external_name': 'Test',
'external_id': '1',
'source_title': 'Test',
'source_url': 'http://example.net',
'type': constants.IMAGE_TYPE_POSTER,
})
self.assertEqual(response.code, 200, response.body)
image = utils.json_loads(response.body)
# we need to fake that an image has been uploaded
with new_session() as session:
session.query(models.Image).filter(
models.Image.id == image['id'],
).update({
'hash': '17fb3ee9dac3969819af794c1fd11fbd0e02ca3d0e86b9f0c0365f13fa27d225'
})
session.commit()
response = self.post('/1/shows', {
'title': 'test show',
'status': 1,
'poster_image_id': image['id']
})
self.assertEqual(response.code, 201, response.body)
show = utils.json_loads(response.body)
self.assertEqual(show['poster_image']['id'], image['id'])
# when retrieving the show the poster image must be there.
response = self.get('/1/shows/{}'.format(show['id']))
self.assertEqual(response.code, 200)
show = utils.json_loads(response.body)
self.assertEqual(show['poster_image']['id'], image['id'])
# remove the image
response = self.put('/1/shows/{}'.format(show['id']), {
'poster_image_id': None
})
self.assertEqual(response.code, 200)
show = utils.json_loads(response.body)
self.assertEqual(show['poster_image'], None)
# add the image again
response = self.put('/1/shows/{}'.format(show['id']), {
'poster_image_id': image['id']
})
self.assertEqual(response.code, 200)
show = utils.json_loads(response.body)
self.assertEqual(show['poster_image']['id'], image['id'])
开发者ID:thomaserlang,项目名称:seplis,代码行数:51,代码来源:test_show.py
示例12: test_multiple
def test_multiple(self):
self.login(0)
response = self.post('/1/users/{}/play-servers'.format(self.current_user.id), {
'name': 'Thomas',
'url': 'http://example.net',
'secret': 'SOME SECRET',
})
self.assertEqual(response.code, 201, response.body)
server1 = utils.json_loads(response.body)
response = self.post('/1/users/{}/play-servers'.format(self.current_user.id), {
'name': 'Thomas 2',
'url': 'http://example.net',
'secret': 'SOME SECRET',
})
self.assertEqual(response.code, 201, response.body)
server2 = utils.json_loads(response.body)
# get the servers
response = self.get('/1/users/{}/play-servers'.format(
self.current_user.id
))
self.assertEqual(response.code, 200, response.body)
servers = utils.json_loads(response.body)
self.assertEqual(len(servers), 2)
self.assertEqual(response.headers['X-Total-Count'], '2')
self.assertEqual(servers[0]['external_id'], server1['external_id'])
self.assertEqual(servers[1]['external_id'], server2['external_id'])
self.assertTrue('secret' in servers[0])
self.assertTrue('secret' in servers[1])
# get the servers that the user has access to
response = self.get('/1/users/{}/play-servers?access_to=true'.format(
self.current_user.id
))
servers = utils.json_loads(response.body)
self.assertEqual(len(servers), 2)
self.assertFalse('secret' in servers[0])
self.assertFalse('secret' in servers[1])
# test that deleting a server removes it from the list
response = self.delete('/1/users/{}/play-servers/{}'.format(
self.current_user.id,
servers[0]['id']
))
self.assertEqual(response.code, 200)
response = self.get('/1/users/{}/play-servers'.format(
self.current_user.id
))
servers = utils.json_loads(response.body)
self.assertEqual(len(servers), 1, response.body)
开发者ID:jonathan1994,项目名称:seplis,代码行数:50,代码来源:test_play.py
示例13: test_description
def test_description(self):
self.login(constants.LEVEL_EDIT_SHOW)
response = self.post('/1/shows', {
'title': 'QWERTY',
'description': None,
'premiered': '2003-01-01',
'ended': None,
'importers': {
'info': 'imdb',
'episodes': 'imdb',
},
'externals': {
'imdb': 'tt123456799',
},
'episodes': [
{
'number': 1,
'title': 'Episode 1',
'air_date': '2014-01-01',
'description': None,
}
],
})
self.assertEqual(response.code, 201, response.body)
show = utils.json_loads(response.body)
self.assertEqual(show['title'], 'QWERTY')
开发者ID:thomaserlang,项目名称:seplis,代码行数:26,代码来源:test_show.py
示例14: decode_play_id
def decode_play_id(play_id):
return utils.json_loads(tornado.web.decode_signed_value(
secret=config['play']['secret'],
name='play_id',
value=play_id,
max_age_days=1,
))
开发者ID:jonathan1994,项目名称:seplis,代码行数:7,代码来源:play.py
示例15: __init__
def __init__(self, client, response, timeout=TIMEOUT):
self.client = client
self.data = utils.json_loads(response.body) if \
response and response.body \
else None
self.timeout = timeout
self.link = {}
self.next = None
self.prev = None
self.first = None
self.last = None
self.count = None
self.pages = None
if not response:
return
links = {}
if 'Link' in response.headers:
links = utils.parse_link_header(
response.headers['Link']
)
for link in LINK_TYPES:
self.__dict__[link] = links.get(link)
if self.__dict__[link]:
self.__dict__[link] = urljoin(
self.client.url,
self.__dict__[link]
)
if 'X-Total-Count' in response.headers:
self.count = int(response.headers['X-Total-Count'])
if 'X-Total-Pages' in response.headers:
self.pages = int(response.headers['X-Total-Pages'])
开发者ID:jonathan1994,项目名称:seplis,代码行数:33,代码来源:client.py
示例16: test_episodes
def test_episodes(self):
show_id = self.new_show()
response = self.patch('/1/shows/{}'.format(show_id), {
'episodes': [
{
'number': 1,
'title': 'Episode 1',
'air_date': '2014-01-01',
'description': {
'text': 'Test description.'
}
}
]
})
self.assertEqual(response.code, 200, response.body)
self.get('http://{}/episodes/_refresh'.format(
config['api']['elasticsearch']
))
response = self.get('/1/shows/{}/episodes'.format(show_id))
self.assertEqual(response.code, 200, response.body)
episodes = utils.json_loads(response.body)
self.assertEqual(len(episodes), 1, response.body)
response = self.patch('/1/shows/{}'.format(show_id), {
'episodes': [
{
'number': 1,
'title': 'Episode 0',
'season': 0,
}
]
})
self.assertEqual(response.code, 400, response.body)
response = self.patch('/1/shows/{}'.format(show_id), {
'episodes': [
{
'number': 1,
'title': 'Episode 0',
'episode': 0,
}
]
})
self.assertEqual(response.code, 400, response.body)
# Allow season and episode None
response = self.patch('/1/shows/{}'.format(show_id), {
'episodes': [
{
'number': 1,
'title': 'Episode 0',
'season': None,
'episode': None,
}
]
})
self.assertEqual(response.code, 200, response.body)
开发者ID:thomaserlang,项目名称:seplis,代码行数:58,代码来源:test_show.py
示例17: initialize
def initialize(self):
self.access_token = None
if self.request.body:
try:
self.request.body = utils.json_loads(self.request.body)
except ValueError:
self.request.body = {}
else:
self.request.body = {}
开发者ID:jonathan1994,项目名称:seplis,代码行数:9,代码来源:base.py
示例18: test_post
def test_post(self):
self.login(constants.LEVEL_EDIT_SHOW)
# Creating a new show without any data is OK.
response = self.post('/1/shows')
self.assertEqual(response.code, 201, response.body)
# this should be a successfully creation of a new show
response = self.post('/1/shows', {
'title': 'NCIS',
'description': {
'text': 'The cases of the Naval Criminal Investigative Service. \_(ʘ_ʘ)_/ "\'<!--/*༼ つ ◕_◕ ༽つ',
'title': 'IMDb',
'url': 'http://www.imdb.com/title/tt0364845/',
},
'premiered': '2003-01-01',
'ended': None,
'indices': {
'info': 'imdb',
'episodes': 'imdb',
},
'externals': {
'imdb': 'tt0364845',
},
'genres': [
'Action',
'Thriller',
],
'alternative_titles': [
'NCIS 2',
'NCIS 3',
],
'runtime': 40,
})
self.assertEqual(response.code, 201, response.body)
show = utils.json_loads(response.body)
self.assertEqual(show['title'], 'NCIS')
self.assertEqual(show['description'], {
'text': 'The cases of the Naval Criminal Investigative Service. \_(ʘ_ʘ)_/ "\'<!--/*༼ つ ◕_◕ ༽つ',
'title': 'IMDb',
'url': 'http://www.imdb.com/title/tt0364845/',
})
self.assertEqual(show['premiered'], '2003-01-01')
self.assertEqual(show['ended'], None)
self.assertEqual(show['indices'], {
'info': 'imdb',
'episodes': 'imdb',
'images': None,
})
self.assertEqual(show['externals'], {
'imdb': 'tt0364845',
})
self.assertTrue('Action' in show['genres'])
self.assertTrue('Thriller' in show['genres'])
self.assertTrue('NCIS 2' in show['alternative_titles'])
self.assertTrue('NCIS 3' in show['alternative_titles'])
self.assertEqual(show['runtime'], 40)
开发者ID:jonathan1994,项目名称:seplis,代码行数:57,代码来源:test_show.py
示例19: decode_play_id
def decode_play_id(play_id):
data = tornado.web.decode_signed_value(
secret=config['play']['secret'],
name='play_id',
value=play_id,
max_age_days=0.3,
)
if not data:
raise tornado.web.HTTPError(400, 'Play id invalid')
return utils.json_loads(data)
开发者ID:thomaserlang,项目名称:seplis,代码行数:10,代码来源:play.py
示例20: test_external
def test_external(self):
show_id = self.new_show()
response = self.patch('/1/shows/{}'.format(show_id), {
'externals': {
'imdb': 'tt1234',
'seplis_old': '1234',
}
})
self.assertEqual(response.code, 200, response.body)
response = self.get('/1/shows/externals/imdb/tt1234')
self.assertEqual(response.code, 200)
show = utils.json_loads(response.body)
self.assertEqual(show['id'], show_id)
response = self.get('/1/shows/externals/seplis_old/1234')
self.assertEqual(response.code, 200)
show = utils.json_loads(response.body)
self.assertEqual(show['id'], show_id)
# Let's try to get a show that does not have a
# external id associated with it.
response = self.get('/1/shows/externals/imdb/404')
self.assertEqual(response.code, 404)
# make sure that removing a external id results in it
# not being found again.
response = self.patch('/1/shows/{}'.format(show_id), {
'externals': {
'imdb': None,
}
})
self.assertEqual(response.code, 200, response.body)
response = self.get('/1/shows/externals/imdb/tt1234')
self.assertEqual(response.code, 404)
# with the other external id it should still be possible
# to get the show.
response = self.get('/1/shows/externals/seplis_old/1234')
self.assertEqual(response.code, 200)
开发者ID:jonathan1994,项目名称:seplis,代码行数:43,代码来源:test_show.py
注:本文中的seplis.utils.json_loads函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论