def test_post(self): response = self.post('/1/users', { 'name': 'testø', 'email': 'wrongemail', 'password': '******', }) 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': '*****@*****.**', 'password': '******', }) self.assertEqual(response.code, 201) user = utils.json_loads(response.body) self.assertEqual(user['name'], 'test') self.assertEqual(user['email'], '*****@*****.**') self.assertTrue('password' not in user) self.assertTrue('created' in user)
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')
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'])
def test_get(self): # new user response = self.post('/1/users', { 'name': 'test', 'email': '*****@*****.**', 'password': '******', }) 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)
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'])
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, )
def test_post(self): response = self.post('/1/users', { 'name': 'testø', 'email': 'wrongemail', 'password': '******', }) 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': '*****@*****.**', 'password': '******', }) self.assertEqual(response.code, 201) user = utils.json_loads(response.body) self.assertEqual(user['name'], 'test') self.assertEqual(user['email'], '*****@*****.**') self.assertTrue('password' not in user) self.assertTrue('created' in user)
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')
async def es_get(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 = await http_client.fetch( 'http://{}{}?{}'.format( config['api']['elasticsearch'], url, utils.url_encode_tornado_arguments(query) \ if query else '', connect_timeout=2.0, request_timeout=2.0, ), method='POST' if body else 'GET', headers={ 'Content-Type': 'application/json', }, 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) if e.code == 404: return extra except: extra = {'error': e.response.body.decode('utf-8')} raise exceptions.Elasticsearch_exception( e.code, extra, )
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, )
def test(self): self.login(constants.LEVEL_EDIT_SHOW) response = self.post('/1/shows', { 'title': 'Something', }) self.assertEqual(response.code, 201, response.body) show = utils.json_loads(response.body) response = self.put(f'/1/shows/{show["id"]}/user-rating', { 'rating': 5, }) self.assertEqual(response.code, 204) response = self.get(f'/1/shows/{show["id"]}/user-rating') self.assertEqual(response.code, 200) d = utils.json_loads(response.body) self.assertEqual(d['rating'], 5) response = self.get(f'/1/shows/{show["id"]}', {'append': 'user_rating'}) self.assertEqual(response.code, 200) d = utils.json_loads(response.body) self.assertEqual(d['user_rating'], 5) response = self.delete(f'/1/shows/{show["id"]}/user-rating') self.assertEqual(response.code, 204) response = self.get(f'/1/shows/{show["id"]}', {'append': 'user_rating'}) self.assertEqual(response.code, 200) d = utils.json_loads(response.body) self.assertEqual(d['user_rating'], None)
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'])
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'])
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)
def test(self): self.login(3) user = User.new( name='testuser2', email='*****@*****.**', 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)
def test(self): self.login(constants.LEVEL_EDIT_SHOW) response = self.post('/1/shows', { 'title': 'Test show 1', 'episodes': [ { 'number': 1, 'air_datetime': (datetime.utcnow()-timedelta(days=1)).isoformat(), }, { 'number': 2, 'air_datetime': datetime.utcnow().isoformat(), }, { 'number': 3, 'air_datetime': (datetime.utcnow()+timedelta(days=1)).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_datetime': (datetime.utcnow()-timedelta(days=1)).isoformat(), }, { 'number': 2, 'air_datetime': datetime.utcnow().isoformat(), }, { 'number': 3, 'air_datetime': (datetime.utcnow()+timedelta(days=1)).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/{}/shows-following/{}'.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)
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)
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, })
def test(self): self.login(3) user = User.new( name='testuser2', email='*****@*****.**', 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)
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, })
def test(self): self.login() response = self.get('/1/progress-token') self.assertEqual(response.code, 200) d = utils.json_loads(response.body) self.access_token = d['token'] response = self.get('/1/users/current') self.assertEqual(response.code, 403, response.body) d = utils.json_loads(response.body) self.assertEqual(d['extra']['user_level'], -1)
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'])
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'])
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)
def test_season_count(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) show = utils.json_loads(response.body) self.assertEqual(show['seasons'], []) response = self.patch( '/1/shows/{}'.format(show_id), { 'episodes': [{ 'number': 1, 'season': 1, 'episode': 1, }, { 'number': 2, 'season': 1, 'episode': 2, }, { 'number': 3, 'season': 2, 'episode': 1, }] }) self.assertEqual(response.code, 200, response.body) show = utils.json_loads(response.body) self.assertEqual(show['seasons'], [ { 'total': 2, 'season': 1, 'to': 2, 'from': 1 }, { 'total': 1, 'season': 2, 'to': 3, 'from': 3 }, ])
def test_get(self): # new user response = self.post('/1/users', { 'name': 'test___', 'email': '*****@*****.**', 'password': '******', }) self.assertEqual(response.code, 201) user = utils.json_loads(response.body) # test duplication email response = self.post('/1/users', { 'name': 'test___2', 'email': '*****@*****.**', 'password': '******', }) self.assertEqual(response.code, 400) error = utils.json_loads(response.body) self.assertEqual(error['code'], 1501) # test duplication username response = self.post('/1/users', { 'name': 'test___', 'email': '*****@*****.**', 'password': '******', }) self.assertEqual(response.code, 400) error = utils.json_loads(response.body) self.assertEqual(error['code'], 1502) # 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) # 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) print(response.body) user3 = utils.json_loads(response.body) self.assertEqual(user3['email'], self.current_user.email)
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, ))
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'])
def test_user_search(self): users = [] users.append( self.new_user( name='test___', email='*****@*****.**', password='******', level=0, )) users.append( self.new_user( name='test___2', email='*****@*****.**', password='******', level=0, )) self.refresh_es() # test that we can search for a user response = self.get('/1/users?username=test___2') self.assertEqual(response.code, 200, response.body) user = utils.json_loads(response.body)[0] self.assertEqual(user['name'], 'test___2') # test that the user search does not leak emails self.assertTrue('email' not in user)
def test_description(self): self.login(constants.LEVEL_EDIT_SHOW) response = self.post( '/1/shows', { 'title': 'NCIS', 'description': None, 'premiered': '2003-01-01', 'ended': None, 'indices': { 'info': 'imdb', 'episodes': 'imdb', }, 'externals': { 'imdb': 'tt0364845', }, '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'], 'NCIS')
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')
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'])
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)
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, ))
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)
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)
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 = {}
def decode_play_id(play_id): data = web.decode_signed_value( secret=config['play']['secret'], name='play_id', value=play_id, max_age_days=0.3, ) if not data: raise web.HTTPError(400, 'Play id invalid') return utils.json_loads(data)
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)
def test_season_count(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) show = utils.json_loads(response.body) self.assertEqual(show['seasons'], []) response = self.patch('/1/shows/{}'.format(show_id), { 'episodes': [ { 'number': 1, 'season': 1, 'episode': 1, }, { 'number': 2, 'season': 1, 'episode': 2, }, { 'number': 3, 'season': 2, 'episode': 1, } ] }) self.assertEqual(response.code, 200, response.body) show = utils.json_loads(response.body) self.assertEqual(show['seasons'], [ {'total': 2, 'season': 1, 'to': 2, 'from': 1}, {'total': 1, 'season': 2, 'to': 3, 'from': 3}, ])
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)
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)
def test(self): show_id = self.new_show() url = '/1/shows/{}/user-subtitle-lang'.format(show_id) response = self.get(url) self.assertEqual(response.code, 204) response = self.put(url, { 'subtitle_lang': 'eng', 'audio_lang': 'jpn', }) self.assertEqual(response.code, 204) response = self.get(url) self.assertEqual(response.code, 200) data = utils.json_loads(response.body) self.assertEqual(data['subtitle_lang'], 'eng') self.assertEqual(data['audio_lang'], 'jpn') # Check that put will overwrite values with `None` if not sepcified # in the request. response = self.put(url, { 'subtitle_lang': 'eng', }) self.assertEqual(response.code, 204) response = self.get(url) self.assertEqual(response.code, 200) data = utils.json_loads(response.body) self.assertEqual(data['subtitle_lang'], 'eng') self.assertEqual(data['audio_lang'], None) # Check that patch will not overwrite values not sepcified in the # request response = self.patch(url, { 'audio_lang': 'jpn', }) self.assertEqual(response.code, 204) response = self.get(url) self.assertEqual(response.code, 200) data = utils.json_loads(response.body) self.assertEqual(data['subtitle_lang'], 'eng') self.assertEqual(data['audio_lang'], 'jpn')
def test(self): self.login(constants.LEVEL_EDIT_SHOW) response = self.post('/1/shows', { 'episodes': [ { 'number': 1, }, ], }) self.assertEqual(response.code, 201, response.body) show = json_loads(response.body) url = '/1/shows/{}/episodes/{}/position'.format( show['id'], 1 ) # Return 204 if the episode has not been watched response = self.get(url) self.assertEqual(response.code, 204) response = self.put(url, {'position': 200}) self.assertEqual(response.code, 204, response.body) response = self.get(url) self.assertEqual(response.code, 200) w = json_loads(response.body) self.assertEqual(w['times'], 0) self.assertEqual(w['position'], 200) self.assertTrue(w['watched_at'] is not None) response = self.put(url, {'position': 201}) self.assertEqual(response.code, 204, response.body) response = self.get(url) self.assertEqual(response.code, 200) w = json_loads(response.body) self.assertEqual(w['times'], 0) self.assertEqual(w['position'], 201) self.assertTrue(w['watched_at'] is not None) response = self.delete(url) self.assertEqual(response.code, 204, response.body) response = self.get(url) self.assertEqual(response.code, 204, response.body)
def test_empty_lists(self): self.login(constants.LEVEL_EDIT_SHOW) show_id = self.new_show() response = self.patch('/1/shows/{}'.format(show_id), {'title': 'test'}) self.assertEqual(response.code, 200, response.body) response = self.get('/1/shows/{}'.format(show_id)) self.assertEqual(response.code, 200, response.body) show = utils.json_loads(response.body) self.assertEqual(show['genres'], []) self.assertEqual(show['alternative_titles'], []) self.assertEqual(show['seasons'], [])
def new_show(self): self.login(constants.LEVEL_EDIT_SHOW) response = self.post('/1/shows', { 'status': 1, }) self.assertEqual(response.code, 201, response.body) show = json_loads(response.body) self.assertTrue(show['id'] > 0) self.get('http://{}/_refresh'.format( config['api']['elasticsearch'] )) return show['id']
def new_show(self): '''Signs the user in and returns a show id. :returns: int (show_id) ''' self.login(constants.LEVEL_EDIT_SHOW) response = self.post('/1/shows', { 'status': 1, }) self.assertEqual(response.code, 201, response.body) show = json_loads(response.body) self.assertTrue(show['id'] > 0) self.refresh_es() return show['id']
def new_show(self): '''Signs the user in and returns a show id. :returns: int (show_id) ''' self.login(constants.LEVEL_GOD) response = self.post('/1/shows', { 'status': 1, }) self.assertEqual(response.code, 201, response.body) show = json_loads(response.body) self.assertTrue(show['id'] > 0) self.refresh_es() return show['id']
def test(self): self.login(constants.LEVEL_EDIT_SHOW) response = self.post('/1/shows', { 'episodes': [ { 'number': 1, }, ], }) self.assertEqual(response.code, 201, response.body) show = json_loads(response.body) url = '/1/shows/{}/episodes/{}/position'.format(show['id'], 1) # Return 204 if the episode has not been watched response = self.get(url) self.assertEqual(response.code, 204) response = self.put(url, {'position': 200}) self.assertEqual(response.code, 204, response.body) response = self.get(url) self.assertEqual(response.code, 200) w = json_loads(response.body) self.assertEqual(w['times'], 0) self.assertEqual(w['position'], 200) self.assertTrue(w['watched_at'] is not None) response = self.put(url, {'position': 201}) self.assertEqual(response.code, 204, response.body) response = self.get(url) self.assertEqual(response.code, 200) w = json_loads(response.body) self.assertEqual(w['times'], 0) self.assertEqual(w['position'], 201) self.assertTrue(w['watched_at'] is not None) response = self.delete(url) self.assertEqual(response.code, 204, response.body) response = self.get(url) self.assertEqual(response.code, 204, response.body)
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.refresh_es() 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)
def test_empty_lists(self): self.login(constants.LEVEL_EDIT_SHOW) show_id = self.new_show() response = self.patch('/1/shows/{}'.format(show_id), { 'title': 'test' }) self.assertEqual(response.code, 200, response.body) response = self.get('/1/shows/{}'.format(show_id)) self.assertEqual(response.code, 200, response.body) show = utils.json_loads(response.body) self.assertEqual(show['genres'], []) self.assertEqual(show['alternative_titles'], []) self.assertEqual(show['seasons'], [])
def test_episode_type(self): show_id = self.new_show() response = self.put('/1/shows/{}'.format(show_id), { 'episode_type': constants.SHOW_EPISODE_TYPE_ABSOLUTE_NUMBER, }) self.assertEqual(response.code, 200) show = utils.json_loads(response.body) self.assertEqual( show['episode_type'], constants.SHOW_EPISODE_TYPE_ABSOLUTE_NUMBER, ) # test wrong episode type response = self.put('/1/shows/{}'.format(show_id), { 'episode_type': 999, }) self.assertEqual(response.code, 400)
def prepare(self): access_token = self.get_secure_cookie('session') if access_token: self.client.access_token = access_token.decode('utf-8') try: self.current_user = self.get_secure_cookie('user') self.current_user = utils.json_loads(self.current_user) \ if self.current_user else None if not self.current_user: self.current_user = yield self.client.get('/users/current') self.set_secure_cookie( 'user', utils.json_dumps(self.current_user), expires_days=None, ) except API_error as e: if e.code != 1009: # not signed in raise
def _fetch(self, method, uri, body=None, headers=None, timeout=TIMEOUT): if not headers: headers = {} if 'Content-Type' not in headers: headers['Content-Type'] = 'application/json' if 'Accept' not in headers: headers['Accept'] = 'application/json' if ('Authorization' not in headers) and self.access_token: headers['Authorization'] = 'Bearer {}'.format(self.access_token) try: if uri.startswith('http'): url = uri else: if not uri.startswith('/'): uri = '/'+uri url = self.url+uri response = yield self._client.fetch(httpclient.HTTPRequest( url, method=method, body=utils.json_dumps(body) if body or {} == body else None, headers=headers, connect_timeout=timeout, request_timeout=timeout, validate_cert=config['client']['validate_cert'], )) except httpclient.HTTPError as e: response = e.response if not response and (e.code == 599): raise API_error( status_code=e.code, code=e.code, message='Timeout', ) data = None if response.code != 404: if 400 <= response.code <= 600: if response.headers.get('Content-Type') == 'application/json': data = utils.json_loads(response.body) raise API_error(status_code=response.code, **data) raise Exception(response.body) data = HTTPData(self, response, timeout=timeout) if data is None: data = HTTPData(self, None, timeout=timeout) return data
def test_patch(self): show_id = self.new_show() response = self.patch('/1/shows/{}'.format(show_id), { 'title': 'QWERTY', 'description': { 'text': 'The cases of the Naval Criminal Investigative Service.', }, 'premiered': '2003-01-01', 'importers': { 'info': 'imdb', }, 'externals': { 'imdb': 'tt123456799', }, 'episode_type': constants.SHOW_EPISODE_TYPE_AIR_DATE, }) self.assertEqual(response.code, 200, response.body) response = self.patch('/1/shows/{}'.format(show_id), { 'importers': { 'episodes': 'imdb' } }) self.assertEqual(response.code, 200, response.body) show = utils.json_loads(response.body) self.assertEqual(show['title'], 'QWERTY') self.assertEqual(show['description'], { 'text': 'The cases of the Naval Criminal Investigative Service.', 'title': None, 'url': None, }) self.assertEqual(show['premiered'], '2003-01-01') self.assertEqual(show['ended'], None) self.assertEqual(show['importers'], { 'info': 'imdb', 'episodes': 'imdb', 'images': None, }) self.assertEqual(show['externals'], { 'imdb': 'tt123456799', }) self.assertEqual( show['episode_type'], constants.SHOW_EPISODE_TYPE_AIR_DATE )