def get(self, title, session=None): """TVMaze series lookup""" try: tvmaze_id = int(title) except ValueError: tvmaze_id = None try: if tvmaze_id: series = APITVMaze.series_lookup(tvmaze_id=tvmaze_id, session=session) else: series = APITVMaze.series_lookup(series_name=title, session=session) except LookupError as e: raise NotFoundError(e.args[0]) return jsonify(series.to_dict())
def get(self, title, session=None): """TVMaze series lookup""" try: tvmaze_id = int(title) except ValueError: tvmaze_id = None try: if tvmaze_id: series = APITVMaze.series_lookup(tvmaze_id=tvmaze_id, session=session) else: series = APITVMaze.series_lookup(series_name=title, session=session) except LookupError as e: raise NotFoundError(e.args[0]) return jsonify(series.to_dict())
def test_search_results(self, execute_task): task = execute_task('test_search_result') entry = task.entries[0] print(entry['tvmaze_series_name'].lower()) assert entry['tvmaze_series_name'].lower() == 'Shameless'.lower( ), 'lookup failed' with Session() as session: assert task.entries[1]['tvmaze_series_name'].lower( ) == 'Shameless'.lower(), 'second lookup failed' assert len(session.query(TVMazeLookup).all() ) == 1, 'should have added 1 show to search result' assert len(session.query(TVMazeSeries).all() ) == 1, 'should only have added one show to show table' assert session.query(TVMazeSeries).first( ).name == 'Shameless', 'should have added Shameless and not Shameless (2011)' # change the search query session.query(TVMazeLookup).update( {'search_name': "shameless.s01e03.hdtv-flexget"}) session.commit() lookupargs = {'title': "Shameless.S01E03.HDTV-FlexGet"} series = APITVMaze.series_lookup(**lookupargs) assert series.tvdb_id == entry[ 'tvdb_id'], 'tvdb id should be the same as the first entry' assert series.tvmaze_id == entry[ 'tvmaze_series_id'], 'tvmaze id should be the same as the first entry' assert series.name.lower() == entry['tvmaze_series_name'].lower( ), 'series name should match first entry'
def test_series_expiration(self, execute_task): task = execute_task('test_series_expiration') entry = task.entries[0] assert entry['tvmaze_series_name'].lower() == 'Shameless'.lower(), 'lookup failed' assert entry['tvmaze_episode_id'] == 11134, ( 'episode id should be 11134, instead its %s' % entry['tvmaze_episode_id'] ) with Session() as session: # Manually change a value of the series to differ from actual value assert ( session.query(TVMazeSeries).first().name == 'Shameless' ), 'should have added Shameless and not Shameless (2011)' session.query(TVMazeSeries).update({'runtime': 100}) session.commit() # Verify value has changed successfully and series expiration status is still False assert ( not session.query(TVMazeSeries).first().expired ), 'expired status should be False' assert session.query(TVMazeSeries).first().runtime == 100, 'should be updated to 99' # Set series last_update time to 8 days ago, to trigger a show refresh upon request. last_week = datetime.now() - timedelta( days=8 ) # Assuming max days between refreshes is 7 session.query(TVMazeSeries).update({'last_update': last_week}) session.commit() # Verify series expiration flag is now True assert session.query(TVMazeSeries).first().expired, 'expired status should be True' lookupargs = {'title': "Shameless"} series = APITVMaze.series_lookup(**lookupargs) # Verify series data has been refreshed with actual values upon 2nd call, and series expiration flag # is set to False assert series.runtime == 60, ( 'runtime should have been updated back to 60 from 100, instead its %s' % series.runtime ) assert ( not session.query(TVMazeSeries).first().expired ), 'expired status should be False'
def test_series_expiration(self, execute_task): task = execute_task('test_series_expiration') entry = task.entries[0] assert entry['tvmaze_series_name'].lower() == 'Shameless'.lower(), 'lookup failed' assert entry['tvmaze_episode_id'] == 11134, ( 'episode id should be 11134, instead its %s' % entry['tvmaze_episode_id'] ) with Session() as session: # Manually change a value of the series to differ from actual value assert ( session.query(TVMazeSeries).first().name == 'Shameless' ), 'should have added Shameless and not Shameless (2011)' session.query(TVMazeSeries).update({'runtime': 100}) session.commit() # Verify value has changed successfully and series expiration status is still False assert ( not session.query(TVMazeSeries).first().expired ), 'expired status should be False' assert session.query(TVMazeSeries).first().runtime == 100, 'should be updated to 99' # Set series last_update time to 8 days ago, to trigger a show refresh upon request. last_week = datetime.now() - timedelta( days=8 ) # Assuming max days between refreshes is 7 session.query(TVMazeSeries).update({'last_update': last_week}) session.commit() # Verify series expiration flag is now True assert session.query(TVMazeSeries).first().expired, 'expired status should be True' lookupargs = {'title': "Shameless"} series = APITVMaze.series_lookup(**lookupargs) # Verify series data has been refreshed with actual values upon 2nd call, and series expiration flag # is set to False assert series.runtime == 60, ( 'runtime should have been updated back to 60 from 100, instead its %s' % series.runtime ) assert ( not session.query(TVMazeSeries).first().expired ), 'expired status should be False'
def get(self, tvmaze_id, session=None): """TVMaze episode lookup""" args = episode_parser.parse_args() air_date = args.get('air_date') season_num = args.get('season_num') ep_num = args.get('ep_num') kwargs = {'tvmaze_id': tvmaze_id, 'session': session} if air_date: kwargs['series_id_type'] = 'date' kwargs['series_date'] = air_date elif season_num and ep_num: kwargs['series_id_type'] = 'ep' kwargs['series_season'] = season_num kwargs['series_episode'] = ep_num else: raise BadRequest('not enough parameters sent for lookup') try: episode = APITVMaze.episode_lookup(**kwargs) except LookupError as e: raise NotFoundError(e.args[0]) return jsonify(episode.to_dict())
def get(self, tvmaze_id, session=None): """TVMaze episode lookup""" args = episode_parser.parse_args() air_date = args.get('air_date') season_num = args.get('season_num') ep_num = args.get('ep_num') kwargs = {'tvmaze_id': tvmaze_id, 'session': session} if air_date: kwargs['series_id_type'] = 'date' kwargs['series_date'] = air_date elif season_num and ep_num: kwargs['series_id_type'] = 'ep' kwargs['series_season'] = season_num kwargs['series_episode'] = ep_num else: raise BadRequest('not enough parameters sent for lookup') try: episode = APITVMaze.episode_lookup(**kwargs) except LookupError as e: raise NotFoundError(e.args[0]) return jsonify(episode.to_dict())
def test_search_results(self, execute_task): task = execute_task('test_search_result') entry = task.entries[0] print(entry['tvmaze_series_name'].lower()) assert entry['tvmaze_series_name'].lower() == 'Shameless'.lower(), 'lookup failed' with Session() as session: assert ( task.entries[1]['tvmaze_series_name'].lower() == 'Shameless'.lower() ), 'second lookup failed' assert ( len(session.query(TVMazeLookup).all()) == 1 ), 'should have added 1 show to search result' assert ( len(session.query(TVMazeSeries).all()) == 1 ), 'should only have added one show to show table' assert ( session.query(TVMazeSeries).first().name == 'Shameless' ), 'should have added Shameless and not Shameless (2011)' # change the search query session.query(TVMazeLookup).update({'search_name': "shameless.s01e03.hdtv-flexget"}) session.commit() lookupargs = {'title': "Shameless.S01E03.HDTV-FlexGet"} series = APITVMaze.series_lookup(**lookupargs) assert ( series.tvdb_id == entry['tvdb_id'] ), 'tvdb id should be the same as the first entry' assert ( series.tvmaze_id == entry['tvmaze_series_id'] ), 'tvmaze id should be the same as the first entry' assert ( series.name.lower() == entry['tvmaze_series_name'].lower() ), 'series name should match first entry'