Пример #1
0
    def test_protected_attribute_access(self):
        user_id = 2  # Wizard ID
        with exchange.ObjectExchange(connection) as x:
            wizard = x.get_object(user_id)
            self.assertEqual(wizard._location_id,
                             wizard.get_location().get_id())

        with exchange.ObjectExchange(connection, ctx=user_id) as x:
            wizard = x.get_object(user_id)
            eval_verb = x.get_verb(user_id, 'eval')

            # since this will raise AttributeError, the model will attempt to find a verb by that name
            self.assertRaises(SyntaxError, code.r_eval, wizard,
                              'caller._owner_id')
            self.assertRaises(SyntaxError, code.r_eval, wizard,
                              'caller._origin_id')
            self.assertRaises(SyntaxError, code.r_eval, wizard,
                              'caller.__dict__')
            self.assertRaises(SyntaxError, code.r_eval, wizard,
                              'caller.__slots__')

            self.assertRaises(errors.NoSuchVerbError, code.r_eval, wizard,
                              'getattr(caller, "_owner_id")')
            self.assertRaises(errors.NoSuchVerbError, code.r_eval, wizard,
                              'getattr(caller, "_origin_id")')
            self.assertRaises(errors.NoSuchVerbError, code.r_eval, wizard,
                              'getattr(caller, "__dict__")')
            self.assertRaises(errors.NoSuchVerbError, code.r_eval, wizard,
                              'getattr(caller, "__slots__")')
Пример #2
0
def get_exchange(ctx=None):
    """
    Get an ObjectExchange instance for the provided context.
    """
    if(ctx):
        return exchange.ObjectExchange(connection, queue=True, ctx=ctx)
    else:
        return exchange.ObjectExchange(connection)
Пример #3
0
def load_python(connection, python_path):
    """
    Execute a provided Python bootstrap file against the provided database.
    """
    with exchange.ObjectExchange(connection) as x:
        exec(compile(open(python_path).read(), python_path, 'exec'), globals(),
             dict(exchange=x))
Пример #4
0
    def test_basic_rollback(self):
        try:
            with exchange.ObjectExchange(connection) as x:
                x.instantiate('object', name="Test Object")
                raise RuntimeError()
        except:
            pass

        self.assertRaises(errors.NoSuchObjectError, x.get_object,
                          "Test Object")
Пример #5
0
    def test_parser_rollback(self):
        created = False
        user_id = 2  # Wizard ID
        try:
            with exchange.ObjectExchange(connection) as x:
                caller = x.get_object(user_id)
                parser.parse(caller, 'exec create_object("Test Object")')
                if (x.get_object('Test Object')):
                    created = True
                parser.parse(caller, 'exec nosuchobject()')
        except:
            pass

        self.assertTrue(created, "'Test Object' not created.")
        self.assertRaises(errors.NoSuchObjectError, x.get_object,
                          "Test Object")
Пример #6
0
    def setUp(self):
        self.exchange = exchange.ObjectExchange(connection)

        self.wizard = self.exchange.get_object('wizard')
        self.user = self.exchange.get_object('user')
Пример #7
0
def initialize_plugins(connection):
    for plugin in plugins.iterate():
        with exchange.ObjectExchange(connection) as x:
            if not (callable(getattr(plugin, 'initialize', None))):
                continue
            plugin.initialize(x)
Пример #8
0
 def setUp(self):
     self.exchange = exchange.ObjectExchange(connection)
Пример #9
0
 def setUp(self):
     self.exchange = exchange.ObjectExchange(connection)
     self.exchange.queue = test.Anything(flush=lambda: None, )