Example #1
0
    def test_fromDatabase(self):
        """
        The values should be mutated according to the rules of fromDatabase
        """
        class Foo(object):
            a = Property(fromDatabase=(lambda x:x+'db'))


        foo = reconstitute([(Foo.a, 'hey')])
        self.assertEqual(foo.a, 'heydb')
Example #2
0
    def test_tuple(self):
        """
        You can reconstitute a class with a tuple of attributes.
        """
        class Foo(object):
            a = Property()
            b = Property()


        zipped = zip([Foo.a, Foo.b], [1, 'hello'])
        foo = reconstitute(zipped)
        self.assertTrue(isinstance(foo, Foo))
        self.assertEqual(foo.a, 1)
        self.assertEqual(foo.b, 'hello')
Example #3
0
    def test_multiple(self):
        """
        If multiple classes are represented in the properties, return multiple classes
        """
        class Foo(object):
            a = Property()
        class Bar(object):
            b = Property()

        foo, bar = reconstitute([
            (Foo.a, 'hey'),
            (Bar.b, 'ho'),
        ])
        self.assertEqual(foo.a, 'hey')
        self.assertEqual(bar.b, 'ho')
Example #4
0
    def test_init(self):
        """
        __init__ should not be called
        """
        class Foo(object):
            a = Property()
            b = Property()
            init_called = False

            def __init__(self):
                self.init_called = True


        foo = reconstitute([(Foo.a, 'hey'), (Foo.b, 'something')])
        self.assertTrue(isinstance(foo, Foo))
        self.assertEqual(foo.init_called, False, "Should not have called "
                         "__init__")