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({'weight': 99}) session.commit() # Verify value has changed successfully and series expiration status is still False assert session.query(TVMazeSeries).first().expired == False, 'expired status should be False' assert session.query(TVMazeSeries).first().weight == 99, '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 == True, '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.weight == 15, \ 'weight should have been updated back to 15 from 99, instead its %s' % series.weight assert session.query(TVMazeSeries).first().expired == False, 'expired status should be False'
def get(self, tvmaze_id, session=None): 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: return {'status': 'error', 'message': 'not enough parameters sent for lookup'}, 500 try: episode = tvm.episode_lookup(**kwargs) except LookupError as e: return {'status': 'error', 'message': e.args[0] }, 404 return jsonify(episode.to_dict())
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, search, session=None): try: tvmaze_id = int(search) except ValueError: tvmaze_id = None try: if tvmaze_id: result = tvm.series_lookup(tvmaze_id=tvmaze_id, session=session) else: result = tvm.series_lookup(series_name=search, session=session) except LookupError as e: return {'status': 'error', 'message': e.args[0]}, 404 return jsonify(result.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 get(self, search, session=None): try: tvmaze_id = int(search) except ValueError: tvmaze_id = None try: if tvmaze_id: result = tvm.series_lookup(tvmaze_id=tvmaze_id, session=session) else: result = tvm.series_lookup(series_name=search, session=session) except LookupError as e: return {'status': 'error', 'message': e.args[0] }, 404 return jsonify(result.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'