from __future__ import unicode_literals, division, absolute_import
from tests import FlexGetBase


class TestBacklog(FlexGetBase):

    __yaml__ = """
        tasks:
          test:
            mock:
              - {title: 'Test.S01E01.hdtv-FlexGet', description: ''}
            set:
              description: '{{description}}I'
              laterfield: 'something'
            # Change the priority of set plugin so it runs on all entries. TODO: Remove, this is an ugly hack.
            plugin_priority:
              set: -254
            backlog: 10 minutes
    """

    def test_backlog(self):
        """Tests backlog (and snapshot) functionality."""

        # Test entry comes out as expected on first run
        self.execute_task('test')
        entry = self.task.find_entry(title='Test.S01E01.hdtv-FlexGet')
        assert entry['description'] == 'I'
        assert entry['laterfield'] == 'something'
        # Simulate entry leaving the task, make sure backlog injects it
        del(self.manager.config['tasks']['test']['mock'])
        self.execute_task('test')
        entry = self.task.find_entry(title='Test.S01E01.hdtv-FlexGet')
        assert entry['description'] == 'I'
        assert entry['laterfield'] == 'something'
        # This time take away the set plugin too, to make sure data is being restored at it's state from input
        del(self.manager.config['tasks']['test']['set'])
        self.execute_task('test')
        entry = self.task.find_entry(title='Test.S01E01.hdtv-FlexGet')
        assert entry['description'] == ''
        assert 'laterfield' not in entry

@@ -64,40 +64,10 @@
 ort%0A
-from tests import FlexGetBase
 %0A%0A
-%0A
 clas
@@ -84,35 +84,28 @@
 log(
-FlexGetBase):%0A%0A    __yaml__
+object):%0A%0A    config
  = %22
@@ -556,16 +556,39 @@
 log(self
+, manager, execute_task
 ):%0A     
@@ -697,37 +697,39 @@
 rst run%0A        
-self.
+task = 
 execute_task('te
@@ -741,37 +741,32 @@
         entry = 
-self.
 task.find_entry(
@@ -968,37 +968,32 @@
  it%0A        del(
-self.
 manager.config%5B'
@@ -1017,37 +1017,39 @@
 mock'%5D)%0A        
-self.
+task = 
 execute_task('te
@@ -1061,37 +1061,32 @@
         entry = 
-self.
 task.find_entry(
@@ -1335,21 +1335,16 @@
     del(
-self.
 manager.
@@ -1383,21 +1383,23 @@
         
-self.
+task = 
 execute_
@@ -1431,13 +1431,8 @@
 y = 
-self.
 task

Convert test_backlog to py.test