Example #1
0
    def test_retry_value_is_decodable(self):
        """Ensure that from_dict is the inverse of to_dict when retry options
        are given.
        """
        from furious.async import Async

        async_job = Async("something", task_args={"retry_options": {"task_retry_limit": 5}})
        new_async_job = Async.from_dict(async_job.to_dict())

        self.assertEqual(async_job.to_dict(), new_async_job.to_dict())
Example #2
0
    def test_retry_value_is_decodable(self):
        """Ensure that from_dict is the inverse of to_dict when retry options
        are given.
        """
        from furious. async import Async

        async_job = Async("something",
                          task_args={'retry_options': {
                              'task_retry_limit': 5
                          }})
        new_async_job = Async.from_dict(async_job.to_dict())

        self.assertEqual(async_job.to_dict(), new_async_job.to_dict())
Example #3
0
    def test_used_async_retry_value_is_decodable(self):
        """Ensure that from_dict is the inverse of to_dict when retry options
        are given and the async has be cast to task.
        """
        from furious.async import Async

        async_job = Async("something",
                          task_args={'retry_options': {'task_retry_limit': 5}})
        async_job.to_dict()

        new_async_job = Async.from_dict(async_job.to_dict())

        self.assertEqual(async_job.to_dict(), new_async_job.to_dict())
Example #4
0
    def test_process_results_encoded_and_decoded(self):
        """Ensure _process_results is correctly encoded to and decoded from
        an Async options dict.
        """
        from furious.async import Async

        async_job = Async("something", _process_results=locals)

        encoded_async = async_job.to_dict()
        self.assertEqual(encoded_async["__process_results"], "locals")

        new_async_job = Async.from_dict(encoded_async)
        self.assertEqual(new_async_job.get_options()["_process_results"], locals)

        self.assertEqual(async_job.to_dict(), new_async_job.to_dict())
Example #5
0
    def test_context_checker_encoded_and_decoded(self):
        """Ensure the _context_checker is correctly encoded to and decoded from
        an Async options dict.
        """
        from furious. async import Async

        async_job = Async("something", _context_checker=dir)

        encoded_async = async_job.to_dict()
        self.assertEqual(encoded_async['__context_checker'], 'dir')

        new_async_job = Async.from_dict(encoded_async)
        self.assertEqual(new_async_job.get_options()['_context_checker'], dir)

        self.assertEqual(async_job.to_dict(), new_async_job.to_dict())
Example #6
0
    def test_context_checker_encoded_and_decoded(self):
        """Ensure the _context_checker is correctly encoded to and decoded from
        an Async options dict.
        """
        from furious.async import Async

        async_job = Async("something", _context_checker=dir)

        encoded_async = async_job.to_dict()
        self.assertEqual(encoded_async["__context_checker"], "dir")

        new_async_job = Async.from_dict(encoded_async)
        self.assertEqual(new_async_job.get_options()["_context_checker"], dir)

        self.assertEqual(async_job.to_dict(), new_async_job.to_dict())
Example #7
0
    def test_to_dict_with_callbacks(self):
        """Ensure to_dict correctly encodes callbacks."""
        from furious.async import Async

        options = {'id': 'anident',
                   'context_id': 'contextid',
                   'callbacks': {
                       'success': self.__class__.test_to_dict_with_callbacks,
                       'failure': "failure_function",
                       'exec': Async(target=dir, id='subidnet'),
                   }}

        job = Async('nonexistant', **options.copy())

        options['job'] = ('nonexistant', None, None)
        options['callbacks'] = {
            'success': ("furious.tests.test_async."
                        "TestAsync.test_to_dict_with_callbacks"),
            'failure': "failure_function",
            'exec': {'job': ('dir', None, None),
                     'id': 'subidnet',
                     'context_id': None,
                     '_recursion': {'current': 0, 'max': 100},
                     '_type': 'furious.async.Async'}
        }
        options['_recursion'] = {'current': 0, 'max': 100}
        options['_type'] = 'furious.async.Async'

        self.assertEqual(options, job.to_dict())
Example #8
0
    def test_to_dict_with_callbacks(self):
        """Ensure to_dict correctly encodes callbacks."""
        from furious. async import Async

        options = {
            'callbacks': {
                'success': self.__class__.test_to_dict_with_callbacks,
                'failure': "failure_function",
                'exec': Async(target=dir)
            }
        }

        job = Async('nonexistant', **options.copy())

        options['job'] = ('nonexistant', None, None)
        options['callbacks'] = {
            'success': ("furious.tests.test_async."
                        "TestAsync.test_to_dict_with_callbacks"),
            'failure':
            "failure_function",
            'exec': {
                'job': ('dir', None, None),
                '_recursion': {
                    'current': 0,
                    'max': 100
                },
                '_type': 'furious.async.Async'
            }
        }
        options['_recursion'] = {'current': 0, 'max': 100}
        options['_type'] = 'furious.async.Async'

        self.assertEqual(options, job.to_dict())
Example #9
0
    def test_to_dict_with_callbacks(self):
        """Ensure to_dict correctly encodes callbacks."""
        from furious.async import Async

        options = {
            "id": "anident",
            "context_id": "contextid",
            "parent_id": "parentid",
            "callbacks": {
                "success": self.__class__.test_to_dict_with_callbacks,
                "failure": "failure_function",
                "exec": Async(target=dir, id="subidnet", parent_id="parentid"),
            },
        }

        job = Async("nonexistant", **options.copy())

        options["job"] = ("nonexistant", None, None)
        options["callbacks"] = {
            "success": ("furious.tests.test_async." "TestAsync.test_to_dict_with_callbacks"),
            "failure": "failure_function",
            "exec": {
                "job": ("dir", None, None),
                "id": "subidnet",
                "context_id": None,
                "parent_id": "parentid",
                "_recursion": {"current": 0, "max": 100},
                "_type": "furious.async.Async",
            },
        }
        options["_recursion"] = {"current": 0, "max": 100}
        options["_type"] = "furious.async.Async"

        self.assertEqual(options, job.to_dict())
    def test_process_results_encoded_and_decoded(self):
        """Ensure _process_results is correctly encoded to and decoded from
        an Async options dict.
        """
        from furious. async import Async

        async_job = Async("something", _process_results=locals)

        encoded_async = async_job.to_dict()
        self.assertEqual(encoded_async['__process_results'], 'locals')

        new_async_job = Async.from_dict(encoded_async)
        self.assertEqual(new_async_job.get_options()['_process_results'],
                         locals)

        self.assertEqual(async_job.to_dict(), new_async_job.to_dict())
Example #11
0
    def test_to_dict(self):
        """Ensure to_dict returns a dictionary representation of the Async."""
        from furious.async import Async

        task_args = {'other': 'zzz', 'nested': 1}
        headers = {'some': 'thing', 'fun': 1}
        options = {'headers': headers, 'task_args': task_args}

        job = Async('nonexistant', **options.copy())

        options['job'] = ('nonexistant', None, None)

        self.assertEqual(options, job.to_dict())
Example #12
0
    def test_no_type(self):
        """Ensure that if not _type is in options, that it defaults to
        furious.async.Async.
        """
        from furious. async import Async
        from furious. async import async_from_options

        async_job = Async(dir)

        options = async_job.to_dict()
        options.pop('_type')

        result = async_from_options(options)

        self.assertIsInstance(result, Async)
Example #13
0
    def test_to_dict(self):
        """Ensure to_dict returns a dictionary representation of the Async."""
        from furious.async import Async

        task_args = {"other": "zzz", "nested": 1}
        headers = {"some": "thing", "fun": 1}
        options = {"headers": headers, "task_args": task_args, "id": "me", "context_id": None, "parent_id": "parentid"}

        job = Async("nonexistant", **options.copy())

        options["job"] = ("nonexistant", None, None)
        options["_recursion"] = {"current": 0, "max": 100}
        options["_type"] = "furious.async.Async"

        self.assertEqual(options, job.to_dict())
Example #14
0
    def test_no_type(self):
        """Ensure that if not _type is in options, that it defaults to
        furious.async.Async.
        """
        from furious.async import Async
        from furious.async import async_from_options

        async_job = Async(dir)

        options = async_job.to_dict()
        options.pop("_type")

        result = async_from_options(options)

        self.assertIsInstance(result, Async)
Example #15
0
    def test_to_dict(self):
        """Ensure to_dict returns a dictionary representation of the Async."""
        from furious. async import Async

        task_args = {'other': 'zzz', 'nested': 1}
        headers = {'some': 'thing', 'fun': 1}
        options = {'headers': headers, 'task_args': task_args}

        job = Async('nonexistant', **options.copy())

        options['job'] = ('nonexistant', None, None)
        options['_recursion'] = {'current': 0, 'max': 100}
        options['_type'] = 'furious.async.Async'

        self.assertEqual(options, job.to_dict())
Example #16
0
    def test_to_dict(self):
        """Ensure to_dict returns a dictionary representation of the Async."""
        from furious.async import Async

        task_args = {'other': 'zzz', 'nested': 1}
        headers = {'some': 'thing', 'fun': 1}
        options = {'headers': headers, 'task_args': task_args, 'id': 'me',
                   'context_id': None}

        job = Async('nonexistant', **options.copy())

        options['job'] = ('nonexistant', None, None)
        options['_recursion'] = {'current': 0, 'max': 100}
        options['_type'] = 'furious.async.Async'

        self.assertEqual(options, job.to_dict())
Example #17
0
    def test_to_dict_with_callbacks(self):
        """Ensure to_dict correctly encodes callbacks."""
        from furious.async import Async

        def success_function():
            pass

        options = {'callbacks': {
            'success': self.__class__.test_to_dict_with_callbacks,
            'failure': "failure_function",
            'exec': Async(target=dir)
        }}

        job = Async('nonexistant', **options.copy())

        options['job'] = ('nonexistant', None, None)
        options['callbacks'] = {
            'success': ("furious.tests.test_async."
                        "TestAsync.test_to_dict_with_callbacks"),
            'failure': "failure_function",
            'exec': {'job': ('dir', None, None)}
        }

        self.assertEqual(options, job.to_dict())