示例#1
0
    def test_to_dict_with_callbacks(self):
        """Ensure to_dict correctly encodes callbacks."""
        import copy

        from furious.async import Async
        from furious.context import Context

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

        context = Context(**copy.deepcopy(options))

        # This stuff gets dumped out by to_dict().
        options.update({
            'insert_tasks': 'furious.context.context._insert_tasks',
            'persistence_engine': 'persistence_engine',
            '_tasks_inserted': False,
            '_task_ids': [],
            'callbacks': {
                'success': ("furious.tests.context.test_context."
                            "TestContext.test_to_dict_with_callbacks"),
                'failure': "failure_function",
                'exec': {'job': ('dir', None, None),
                         '_recursion': {'current': 0, 'max': 100},
                         '_type': 'furious.async.Async'}
            }
        })

        self.assertEqual(options, context.to_dict())
    def test_to_dict_with_callbacks(self):
        """Ensure to_dict correctly encodes callbacks."""
        import copy

        from furious. async import Async
        from furious.context import Context

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

        context = Context(**copy.deepcopy(options))

        # This stuff gets dumped out by to_dict().
        options.update({
            'id': 'someid',
            'insert_tasks': 'furious.context.context._insert_tasks',
            'persistence_engine': 'persistence_engine',
            '_tasks_inserted': False,
            '_task_ids': [],
            'callbacks': {
                'success': ("furious.tests.context.test_context."
                            "TestContext.test_to_dict_with_callbacks"),
                'failure':
                "failure_function",
                'exec': {
                    'job': ('dir', None, None),
                    'id': 'blargh',
                    'context_id': 'contextid',
                    'parent_id': 'parentid',
                    '_recursion': {
                        'current': 0,
                        'max': 100
                    },
                    '_type': 'furious.async.Async'
                }
            }
        })

        self.assertEqual(options, context.to_dict())
 def test_store_context(self):
     from furious.extras.appengine.ndb_persistence import store_context
     from furious.extras.appengine.ndb_persistence import load_context
     from furious.extras.appengine.ndb_persistence import ContextPersist
     from furious.context import Context
     ctx = Context()
     ctx.add('test', args=[1, 2])
     ctx_dict = ctx.to_dict()
     store_context(ctx.id, ctx_dict)
     ctx_persisted = ContextPersist.get_by_id(ctx.id)
     self.assertIsNotNone(ctx_persisted)
     reloaded_ctx = load_context(ctx.id)
     self.assertEqual(reloaded_ctx, ctx_dict)
示例#4
0
    def test_persist_persists(self):
        """Calling persist with an engine persists the Context."""
        from furious.context import Context

        persistence_engine = Mock()
        persistence_engine.func_name = "persistence_engine"
        persistence_engine.im_class.__name__ = "engine"

        context = Context(persistence_engine=persistence_engine)

        context.persist()

        persistence_engine.store_context.assert_called_once_with(context.id, context.to_dict())
示例#5
0
    def test_persist_persists(self):
        """Calling persist with an engine persists the Context."""
        from furious.context import Context

        persistence_engine = Mock()
        persistence_engine.func_name = 'persistence_engine'
        persistence_engine.im_class.__name__ = 'engine'

        context = Context(persistence_engine=persistence_engine)

        context.persist()

        persistence_engine.store_context.assert_called_once_with(
            context.id, context.to_dict())
    def test_save_context(self):
        """Ensure the passed in context gets serialized and set on the saved
        FuriousContext entity.
        """
        _id = "contextid"

        context = Context(id=_id)

        result = store_context(context)

        self.assertEqual(result.id(), _id)

        loaded_context = FuriousContext.from_id(result.id())

        self.assertEqual(context.to_dict(), loaded_context.to_dict())
    def test_save_context(self):
        """Ensure the passed in context gets serialized and set on the saved
        FuriousContext entity.
        """
        _id = "contextid"

        context = Context(id=_id)

        result = store_context(context)

        self.assertEqual(result.id(), _id)

        loaded_context = FuriousContext.from_id(result.id())

        self.assertEqual(context.to_dict(), loaded_context.to_dict())
示例#8
0
    def test_to_dict(self):
        """Ensure to_dict returns a dictionary representation of the Context.
        """
        import copy

        from furious.context import Context

        options = {"persistence_engine": "persistence_engine", "unkown": True}

        context = Context(**copy.deepcopy(options))

        # This stuff gets dumped out by to_dict().
        options.update(
            {"insert_tasks": "furious.context.context._insert_tasks", "_tasks_inserted": False, "_task_ids": []}
        )

        self.assertEqual(options, context.to_dict())
示例#9
0
    def test_to_dict_with_callbacks(self):
        """Ensure to_dict correctly encodes callbacks."""
        import copy

        from furious.async import Async
        from furious.context import Context

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

        context = Context(**copy.deepcopy(options))

        # This stuff gets dumped out by to_dict().
        options.update(
            {
                "id": "someid",
                "insert_tasks": "furious.context.context._insert_tasks",
                "persistence_engine": "persistence_engine",
                "_tasks_inserted": False,
                "_task_ids": [],
                "callbacks": {
                    "success": ("furious.tests.context.test_context." "TestContext.test_to_dict_with_callbacks"),
                    "failure": "failure_function",
                    "exec": {
                        "job": ("dir", None, None),
                        "id": "blargh",
                        "context_id": "contextid",
                        "parent_id": "parentid",
                        "_recursion": {"current": 0, "max": 100},
                        "_type": "furious.async.Async",
                    },
                },
            }
        )

        self.assertEqual(options, context.to_dict())
示例#10
0
    def test_to_dict(self):
        """Ensure to_dict returns a dictionary representation of the Context.
        """
        import copy

        from furious.context import Context

        options = {
            'persistence_engine': 'persistence_engine',
            'unkown': True,
        }

        context = Context(**copy.deepcopy(options))

        # This stuff gets dumped out by to_dict().
        options.update({
            'insert_tasks': 'furious.context.context._insert_tasks',
            '_tasks_inserted': False,
            '_task_ids': [],
        })

        self.assertEqual(options, context.to_dict())
示例#11
0
    def test_to_dict(self):
        """Ensure to_dict returns a dictionary representation of the Context.
        """
        import copy

        from furious.context import Context

        options = {
            'persistence_engine': 'persistence_engine',
            'unkown': True,
        }

        context = Context(**copy.deepcopy(options))

        # This stuff gets dumped out by to_dict().
        options.update({
            'insert_tasks': 'furious.context.context._insert_tasks',
            '_tasks_inserted': False,
            '_task_ids': [],
        })

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