Пример #1
0
    def test_name(self):
        uniques = [False, True]
        hases = [True, True, False, False, False]
        e = test.Anything(
            is_unique_name=lambda name: uniques.pop(),
            has=lambda *a, **kw: hases.pop(),
            instantiate=lambda *a, **kw: p,
            get_property=lambda *a, **kw: p,
            get_context=lambda: o,
            is_allowed=lambda *a: True,
            is_wizard=lambda *a: False,
            save=lambda s: True,
        )
        e.ctx = test.Anything(get_id=lambda: -1)

        o = interface.Object(e)
        p = interface.Property(o)

        self.assertRaises(ValueError, o.set_name, 'phil', real=True)
        o.set_name('phil', real=True)

        #import pdb; pdb.set_trace()
        self.assertEqual(o.get_name(), 'phil')
        self.assertEqual(o.name, 'phil')

        o.set_name('phil-prop')

        self.assertEqual(o.get_name(real=True), 'phil')
        self.assertEqual(o.get_name(), 'phil-prop')
        self.assertEqual(o.name, 'phil-prop')
Пример #2
0
    def test_id(self):
        e = test.Anything()
        o = interface.Object(e)
        p = interface.Property(o)
        p.set_id(1024)

        self.assertEqual(p.get_id(), 1024)
        self.assertRaises(RuntimeError, p.set_id, 2048)
Пример #3
0
    def test_value(self):
        e = test.Anything(
            get_context=lambda: o,
            is_allowed=lambda *a: True,
            save=lambda s: True,
            is_wizard=lambda *a: False,
        )
        o = interface.Object(e)
        p = interface.Property(o)
        p.set_value('prop')

        self.assertEqual(p.get_value(), 'prop')
Пример #4
0
    def test_origin(self):
        e = test.Anything(
            instantiate=lambda *a, **kw: (a, kw),
            get_context=lambda: o,
            is_allowed=lambda *a: True,
            is_wizard=lambda *a: False,
        )
        o = interface.Object(e)
        o.set_id(1024)
        p = interface.Property(o)

        self.assertEqual(p.get_origin(), (('object', ), {'id': 1024}))
Пример #5
0
    def test_is_readable(self):
        results = [True, False, True]
        e = test.Anything(
            is_allowed=lambda *a, **kw: results.pop(),
            get_context=lambda: o,
            instantiate=lambda *a, **kw: o,
            is_wizard=lambda *a: False,
        )
        o = interface.Object(e)
        p = interface.Property(o)

        self.assertEqual(p.is_readable(), True)
        self.assertRaises(errors.PermissionError, p.get_value)
Пример #6
0
    def test_origin(self):
        e = test.Anything(
            instantiate=lambda *a, **kw: origin,
            get_context=lambda: None,
        )

        origin = interface.Object(e)
        p = interface.Property(origin)

        self.assertEqual(p.get_origin(), origin)
        self.assertEqual(p.origin, origin)

        v = interface.Verb(origin)
        self.assertEqual(v.get_origin(), origin)
        self.assertEqual(v.origin, origin)
Пример #7
0
    def _mkproperty(self, record):
        """
        Instantiate a interface.Property
        """
        origin = self.instantiate('object', id=record['origin_id'])
        p = interface.Property(origin)

        p._name = record['name']
        p._origin_id = record['origin_id']
        p._type = record.get('type', 'string')
        p._owner_id = record.get('owner_id', None)

        val = record.get('value', '')
        p._value = ason.loads(val, exchange=self) if val else val

        return p
Пример #8
0
    def test_owner(self):
        e = test.Anything(
            instantiate=lambda *a, **kw: owner,
            get_context=lambda: None,
            save=lambda s: True,
        )

        owner = interface.Object(e)
        owner_mock = test.Anything(get_id=lambda: 1024, )
        subject = interface.Object(e)
        subject2 = interface.Property(subject)
        subject3 = interface.Verb(subject)

        subject.set_owner(owner_mock)
        self.assertEqual(subject.get_owner(), owner)
        self.assertEqual(subject.owner, owner)

        subject2.set_owner(owner_mock)
        self.assertEqual(subject2.get_owner(), owner)
        self.assertEqual(subject2.owner, owner)

        subject3.set_owner(owner_mock)
        self.assertEqual(subject3.get_owner(), owner)
        self.assertEqual(subject3.owner, owner)