def test_expire_no_check(self, execute_task): persist['auth_tokens'] = {'default': None} def test_run(): # Run the task and check tvdb data was populated. task = execute_task('test_mark_expired') entry = task.find_entry(title='House.S02E02.hdtv') assert entry['tvdb_ep_name'] == 'Autopsy' # Run the task once, this populates data from tvdb test_run() # Should not expire as it was checked less then an hour ago persist['last_check'] = datetime.utcnow() - timedelta(hours=1) with mock.patch( 'requests.sessions.Session.request', side_effect=Exception( 'Tried to expire or lookup, less then an hour since last check' )): # Ensure series is not marked as expired with Session() as session: mark_expired(session) ep = session.query(TVDBEpisode) \ .filter(TVDBEpisode.series_id == 73255) \ .filter(TVDBEpisode.episode_number == 2) \ .filter(TVDBEpisode.season_number == 2) \ .first() assert not ep.expired assert not ep.series.expired
def test_expire_no_check(self, execute_task): persist['auth_tokens'] = {'default': None} def test_run(): # Run the task and check tvdb data was populated. task = execute_task('test_mark_expired') entry = task.find_entry(title='House.S02E02.hdtv') assert entry['tvdb_ep_name'] == 'Autopsy' # Run the task once, this populates data from tvdb test_run() # Should not expire as it was checked less then an hour ago persist['last_check'] = datetime.utcnow() - timedelta(hours=1) with mock.patch('requests.sessions.Session.request', side_effect=Exception('Tried to expire or lookup, less then an hour since last check')): # Ensure series is not marked as expired with Session() as session: mark_expired(session) ep = session.query(TVDBEpisode) \ .filter(TVDBEpisode.series_id == 73255) \ .filter(TVDBEpisode.episode_number == 2) \ .filter(TVDBEpisode.season_number == 2) \ .first() assert not ep.expired assert not ep.series.expired
def test_expire_check(self, execute_task): persist['auth_tokens'] = {'default': None} def test_run(): # Run the task and check tvdb data was populated. task = execute_task('test_mark_expired') entry = task.find_entry(title='House.S02E02.hdtv') assert entry['tvdb_ep_name'] == 'Autopsy' # Run the task once, this populates data from tvdb test_run() # Should expire persist['last_check'] = datetime.utcnow() - timedelta(hours=3) expired_data = [ { "id": 73255, "lastUpdated": 1458186055 }, { "id": 295743, "lastUpdated": 1458186088 } ] # Ensure series is marked as expired with mock.patch.object(TVDBRequest, 'get', side_effect=[expired_data]): with Session() as session: mark_expired(session) ep = session.query(TVDBEpisode) \ .filter(TVDBEpisode.series_id == 73255) \ .filter(TVDBEpisode.episode_number == 2) \ .filter(TVDBEpisode.season_number == 2) \ .first() assert ep.expired assert ep.series.expired # Run the task again, should be re-populated from tvdb test_run() with Session() as session: ep = session.query(TVDBEpisode) \ .filter(TVDBEpisode.series_id == 73255) \ .filter(TVDBEpisode.episode_number == 2) \ .filter(TVDBEpisode.season_number == 2) \ .first() assert not ep.expired assert not ep.series.expired