Example #1
0
    def test_update_options_supersede_init_opts(self):
        """Ensure update_options supersedes the options set in init."""
        from furious. async import Async

        options = {
            'value': 1,
            'other': 'zzz',
            'nested': {
                1: 1
            },
            'id': 'wrong',
            'context_id': None,
            'parent_id': 'parentid'
        }

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

        job.update_options(value=23, other='stuff', id='right')

        options['value'] = 23
        options['other'] = 'stuff'
        options['id'] = 'right'

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

        options['_recursion'] = {'current': 0, 'max': 100}

        self.assertEqual(options, job._options)
Example #2
0
    def test_update_options_supersede_init_opts(self):
        """Ensure update_options supersedes the options set in init."""
        from furious.async import Async

        options = {
            "value": 1,
            "other": "zzz",
            "nested": {1: 1},
            "id": "wrong",
            "context_id": None,
            "parent_id": "parentid",
        }

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

        job.update_options(value=23, other="stuff", id="right")

        options["value"] = 23
        options["other"] = "stuff"
        options["id"] = "right"

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

        options["_recursion"] = {"current": 0, "max": 100}

        self.assertEqual(options, job._options)
Example #3
0
    def test_context_id(self):
        """Ensure context_id returns the context_id."""
        from furious.async import Async

        job = Async("somehting")
        job.update_options(context_id="blarghahahaha")
        self.assertEqual(job.context_id, "blarghahahaha")
Example #4
0
    def add(self, target, args=None, kwargs=None, **options):
        """Add an Async job to this context.

        Takes an Async object or the arguments to construct an Async
        object as arguments.  Returns the newly added Async object.
        """
        from furious.async import Async
        from furious.batcher import Message

        if self._tasks_inserted:
            raise errors.ContextAlreadyStartedError(
                "This Context has already had its tasks inserted.")

        if not isinstance(target, (Async, Message)):
            target = Async(target, args, kwargs, **options)

        target.update_options(_context_id=self.id)

        if self.persist_async_results:
            target.update_options(persist_result=True)

        self._tasks.append(target)
        self._options['_task_ids'].append(target.id)

        return target
Example #5
0
    def add(self, target, args=None, kwargs=None, **options):
        """Add an Async job to this context.

        Takes an Async object or the arguments to construct an Async
        object as arguments.  Returns the newly added Async object.
        """
        from furious. async import Async
        from furious.batcher import Message

        if self._tasks_inserted:
            raise errors.ContextAlreadyStartedError(
                "This Context has already had its tasks inserted.")

        if not isinstance(target, (Async, Message)):
            target = Async(target, args, kwargs, **options)

        target.update_options(_context_id=self.id)

        if self.persist_async_results:
            target.update_options(persist_result=True)

        self._tasks.append(target)
        self._options['_task_ids'].append(target.id)

        return target
Example #6
0
    def test_context_id(self):
        """Ensure context_id returns the context_id."""
        from furious. async import Async

        job = Async('somehting')
        job.update_options(context_id='blarghahahaha')
        self.assertEqual(job.context_id, 'blarghahahaha')
Example #7
0
    def test_update_id(self):
        """Ensure using update options to update an id works."""
        from furious.async import Async

        job = Async("somehting")
        job.update_options(id="newid")

        self.assertEqual(job.id, "newid")
        self.assertEqual(job.get_options()["id"], "newid")
Example #8
0
    def test_update_id(self):
        """Ensure using update options to update an id works."""
        from furious. async import Async

        job = Async('somehting')
        job.update_options(id='newid')

        self.assertEqual(job.id, 'newid')
        self.assertEqual(job.get_options()['id'], 'newid')
Example #9
0
    def test_update_id(self):
        """Ensure using update options to update an id works."""
        from furious.async import Async

        job = Async('somehting')
        job.update_options(id='newid')

        self.assertEqual(job.id, 'newid')
        self.assertEqual(job.get_options()['id'], 'newid')
Example #10
0
    def test_update_options(self):
        """Ensure update_options updates the options."""
        from furious.async import Async

        options = {'value': 1, 'other': 'zzz', 'nested': {1: 1}}

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

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

        self.assertEqual(options, job._options)
Example #11
0
    def test_update_options(self):
        """Ensure update_options updates the options."""
        from furious. async import Async

        options = {'value': 1, 'other': 'zzz', 'nested': {1: 1}}

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

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

        options['_recursion'] = {'current': 0, 'max': 100}

        self.assertEqual(options, job._options)
Example #12
0
    def test_update_options(self):
        """Ensure update_options updates the options."""
        from furious.async import Async

        options = {'value': 1, 'other': 'zzz', 'nested': {1: 1}, 'id': 'xx'}

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

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

        options['_recursion'] = {'current': 0, 'max': 100}

        self.assertEqual(options, job._options)
Example #13
0
    def test_update_options_supersede_init_opts(self):
        """Ensure update_options supersedes the options set in init."""
        from furious.async import Async

        options = {'value': 1, 'other': 'zzz', 'nested': {1: 1}}

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

        job.update_options(value=23, other='stuff')

        options['value'] = 23
        options['other'] = 'stuff'

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

        self.assertEqual(options, job._options)
Example #14
0
    def test_update_options_supersede_init_opts(self):
        """Ensure update_options supersedes the options set in init."""
        from furious.async import Async

        options = {'value': 1, 'other': 'zzz', 'nested': {1: 1}, 'id': 'wrong'}

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

        job.update_options(value=23, other='stuff', id='right')

        options['value'] = 23
        options['other'] = 'stuff'
        options['id'] = 'right'

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

        options['_recursion'] = {'current': 0, 'max': 100}

        self.assertEqual(options, job._options)
Example #15
0
    def test_update_options(self):
        """Ensure update_options updates the options."""
        from furious.async import Async

        options = {
            "value": 1,
            "other": "zzz",
            "nested": {1: 1},
            "id": "xx",
            "context_id": None,
            "parent_id": "parentid",
        }

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

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

        options["_recursion"] = {"current": 0, "max": 100}

        self.assertEqual(options, job._options)