Esempio n. 1
0
    def test_decorator_accepts_result_depends_on_as_argument(self):
        """Ensure that passing in depends_on to the decorator sets the
        correct dependency on the job
        """
        # Ensure default
        result = decorated_job.delay(1, 2)
        self.assertEqual(result.dependency, None)
        self.assertEqual(result._dependency_id, None)

        @job(queue='queue_name')
        def foo():
            return 'Firstly'

        foo_job = foo.delay()

        @job(queue='queue_name', depends_on=foo_job)
        def bar():
            return 'Secondly'

        bar_job = bar.delay()

        self.assertIsNone(foo_job._dependency_id)

        self.assertEqual(bar_job.dependency, foo_job)

        self.assertEqual(bar_job._dependency_id, foo_job.id)
Esempio n. 2
0
    def test_decorator_delay_accepts_depends_on_as_argument(self):
        """Ensure that passing in depends_on to the delay method of
        a decorated function overrides the depends_on set in the
        constructor.
        """
        # Ensure default
        result = decorated_job.delay(1, 2)
        self.assertEqual(result.dependency, None)
        self.assertEqual(result._dependency_id, None)

        @job(queue='queue_name')
        def foo():
            return 'Firstly'

        @job(queue='queue_name')
        def bar():
            return 'Firstly'

        foo_job = foo.delay()
        bar_job = bar.delay()

        @job(queue='queue_name', depends_on=foo_job)
        def baz():
            return 'Secondly'

        baz_job = bar.delay(depends_on=bar_job)

        self.assertIsNone(foo_job._dependency_id)
        self.assertIsNone(bar_job._dependency_id)

        self.assertEqual(baz_job.dependency, bar_job)
        self.assertEqual(baz_job._dependency_id, bar_job.id)
Esempio n. 3
0
    def test_decorator_delay_accepts_depends_on_as_argument(self):
        """Ensure that passing in depends_on to the delay method of
        a decorated function overrides the depends_on set in the
        constructor.
        """
        # Ensure default
        result = decorated_job.delay(1, 2)
        self.assertEqual(result.dependency, None)
        self.assertEqual(result._dependency_id, None)

        @job(queue='queue_name')
        def foo():
            return 'Firstly'

        @job(queue='queue_name')
        def bar():
            return 'Firstly'

        foo_job = foo.delay()
        bar_job = bar.delay()

        @job(queue='queue_name', depends_on=foo_job)
        def baz():
            return 'Secondly'

        baz_job = bar.delay(depends_on=bar_job)

        self.assertIsNone(foo_job._dependency_id)
        self.assertIsNone(bar_job._dependency_id)

        self.assertEqual(baz_job.dependency, bar_job)
        self.assertEqual(baz_job._dependency_id, bar_job.id)
Esempio n. 4
0
    def test_decorator_accepts_result_depends_on_as_argument(self):
        """Ensure that passing in depends_on to the decorator sets the
        correct dependency on the job
        """
        # Ensure default
        result = decorated_job.delay(1, 2)
        self.assertEqual(result.dependency, None)
        self.assertEqual(result._dependency_id, None)

        @job(queue='queue_name')
        def foo():
            return 'Firstly'

        foo_job = foo.delay()

        @job(queue='queue_name', depends_on=foo_job)
        def bar():
            return 'Secondly'

        bar_job = bar.delay()

        self.assertIsNone(foo_job._dependency_id)

        self.assertEqual(bar_job.dependency, foo_job)

        self.assertEqual(bar_job._dependency_id, foo_job.id)
Esempio n. 5
0
 def test_decorator_adds_delay_attr(self):
     """Ensure that decorator adds a delay attribute to function that returns
     a Job instance when called.
     """
     self.assertTrue(hasattr(decorated_job, 'delay'))
     result = decorated_job.delay(1, 2)
     self.assertTrue(isinstance(result, Job))
     # Ensure that job returns the right result when performed
     self.assertEqual(result.perform(), 3)
Esempio n. 6
0
 def test_decorator_adds_delay_attr(self):
     """Ensure that decorator adds a delay attribute to function that returns
     a Job instance when called.
     """
     self.assertTrue(hasattr(decorated_job, 'delay'))
     result = decorated_job.delay(1, 2)
     self.assertTrue(isinstance(result, Job))
     # Ensure that job returns the right result when performed
     self.assertEqual(result.perform(), 3)
Esempio n. 7
0
    def test_decorator_accepts_ttl_as_argument(self):
        """Ensure that passing in ttl to the decorator sets the ttl on the job
        """
        # Ensure default
        result = decorated_job.delay(1, 2)
        self.assertEqual(result.ttl, None)

        @job('default', ttl=30)
        def hello():
            return 'Hello'
        result = hello.delay()
        self.assertEqual(result.ttl, 30)
Esempio n. 8
0
    def test_decorator_accepts_ttl_as_argument(self):
        """Ensure that passing in ttl to the decorator sets the ttl on the job
        """
        # Ensure default
        result = decorated_job.delay(1, 2)
        self.assertEqual(result.ttl, None)

        @job('default', ttl=30)
        def hello():
            return 'Hello'
        result = hello.delay()
        self.assertEqual(result.ttl, 30)
Esempio n. 9
0
    def test_decorator_accepts_result_ttl_as_argument(self):
        """Ensure that passing in result_ttl to the decorator sets the
        result_ttl on the job
        """
        # Ensure default
        result = decorated_job.delay(1, 2)
        self.assertEqual(result.result_ttl, DEFAULT_RESULT_TTL)

        @job('default', result_ttl=10)
        def hello():
            return 'Why hello'
        result = hello.delay()
        self.assertEqual(result.result_ttl, 10)
Esempio n. 10
0
    def test_decorator_accepts_result_ttl_as_argument(self):
        """Ensure that passing in result_ttl to the decorator sets the
        result_ttl on the job
        """
        # Ensure default
        result = decorated_job.delay(1, 2)
        self.assertEqual(result.result_ttl, DEFAULT_RESULT_TTL)

        @job('default', result_ttl=10)
        def hello():
            return 'Why hello'
        result = hello.delay()
        self.assertEqual(result.result_ttl, 10)
Esempio n. 11
0
    def test_decorator_custom_failure_ttl(self):
        """Ensure that passing in failure_ttl to the decorator sets the
        failure_ttl on the job
        """
        # Ensure default
        result = decorated_job.delay(1, 2)
        self.assertEqual(result.failure_ttl, None)

        @job('default', failure_ttl=10)
        def hello():
            return 'Why hello'
        result = hello.delay()
        self.assertEqual(result.failure_ttl, 10)
Esempio n. 12
0
    def test_decorator_custom_retry(self):
        """ Ensure that passing in retry to the decorator sets the
        retry on the job
        """
        # Ensure default
        result = decorated_job.delay(1, 2)
        self.assertEqual(result.retries_left, None)
        self.assertEqual(result.retry_intervals, None)

        @job('default', retry=Retry(3, [2]))
        def hello():
            return 'Why hello'
        result = hello.delay()
        self.assertEqual(result.retries_left, 3)
        self.assertEqual(result.retry_intervals, [2])
Esempio n. 13
0
    def test_decorator_accepts_meta_as_argument(self):
        """Ensure that passing in meta to the decorator sets the meta on the job
        """
        # Ensure default
        result = decorated_job.delay(1, 2)
        self.assertEqual(result.meta, {})

        test_meta = {
            'metaKey1': 1,
            'metaKey2': 2,
        }

        @job('default', meta=test_meta)
        def hello():
            return 'Hello'
        result = hello.delay()
        self.assertEqual(result.meta, test_meta)
Esempio n. 14
0
    def test_decorator_accepts_meta_as_argument(self):
        """Ensure that passing in meta to the decorator sets the meta on the job
        """
        # Ensure default
        result = decorated_job.delay(1, 2)
        self.assertEqual(result.meta, {})

        test_meta = {
            'metaKey1': 1,
            'metaKey2': 2,
        }

        @job('default', meta=test_meta)
        def hello():
            return 'Hello'
        result = hello.delay()
        self.assertEqual(result.meta, test_meta)