Ejemplo n.º 1
0
    def test_facade(self):
        mtc = TestC( )
        mtc_f = Facade( mtc )

        self.assertEquals( mtc.methoda( ), mtc_f.methoda( ) )
        self.assertEquals( mtc.methodb( ), mtc_f.methodb( ) )
        self.assertEquals( mtc_f.methoda( ), "a" )

        self.assertEquals( mtc_f.increment( ), 1 )
        self.assertEquals( mtc_f.increment( ), 2 )
        self.assertEquals( mtc_f.increment( ), 3 )
        self.assertEquals( mtc_f.increment( ), 4 )
    def test_facade(self):
        mtc = TestC()
        mtc_f = Facade(mtc)

        self.assertEquals(mtc.methoda(), mtc_f.methoda())
        self.assertEquals(mtc.methodb(), mtc_f.methodb())
        self.assertEquals(mtc_f.methoda(), "a")

        self.assertEquals(mtc_f.increment(), 1)
        self.assertEquals(mtc_f.increment(), 2)
        self.assertEquals(mtc_f.increment(), 3)
        self.assertEquals(mtc_f.increment(), 4)
Ejemplo n.º 3
0
    def test_various_attribute_types_after_chaining(self):
        c = Facade(TestA()).getb().getc()

        # 'Primitives'
        self.assertEquals( c.primitive_a, 'a' )
        self.assertEquals( c.primitive_b, 1 )
        self.assertEquals( c.primitive_c, [ 1 ] )
        self.assertEquals( c.primitive_d, { 'a': 1 } )

        # Instance methods
        self.assertEquals( c.methoda(), 'a' )
        self.assertEquals( c.methodb(), 'b' )

        # Lambda functions
        self.assertEquals( c.lambda_function( 2 ), 4 )

        # Models
        self.assertEquals( c.some_model.a, 1 )
        self.assertEquals( c.some_model.b, 2 )

        # Classes
        self.assertEquals( c.test_a_class( ).wrapper__unwrap( ).__class__, TestA )
    def test_various_attribute_types_after_chaining(self):
        c = Facade(TestA()).getb().getc()

        # 'Primitives'
        self.assertEquals(c.primitive_a, 'a')
        self.assertEquals(c.primitive_b, 1)
        self.assertEquals(c.primitive_c, [1])
        self.assertEquals(c.primitive_d, {'a': 1})

        # Instance methods
        self.assertEquals(c.methoda(), 'a')
        self.assertEquals(c.methodb(), 'b')

        # Lambda functions
        self.assertEquals(c.lambda_function(2), 4)

        # Models
        self.assertEquals(c.some_model.a, 1)
        self.assertEquals(c.some_model.b, 2)

        # Classes
        self.assertEquals(c.test_a_class().wrapper__unwrap().__class__, TestA)
Ejemplo n.º 5
0
    def test_various_attribute_types(self):
        c = Facade(TestC())

        # 'Primitives'
        self.assertEquals(c.primitive_a, "a")
        self.assertEquals(c.primitive_b, 1)
        self.assertEquals(c.primitive_c, [1])
        self.assertEquals(c.primitive_d, {"a": 1})

        # Instance methods
        self.assertEquals(c.methoda(), "a")
        self.assertEquals(c.methodb(), "b")

        # Lambda functions
        self.assertEquals(c.lambda_function(2), 4)

        # Models
        self.assertEquals(c.some_model.a, 1)
        self.assertEquals(c.some_model.b, 2)

        # Classes
        self.assertEquals(c.test_a_class().wrapper__unwrap().__class__, TestA)
Ejemplo n.º 6
0
    def test_recache(self):
        mtc = TestC( )
        mtc_f = Facade( mtc )

        hashes = []

        self.assertEquals( mtc.methoda( ), mtc_f.methoda( ) )
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append( mtc_f.last_cached )
        self.assertEquals( mtc.methodb( ), mtc_f.methodb( ) )
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append( mtc_f.last_cached )
        self.assertEquals( mtc_f.methoda( ), "a" )
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append( mtc_f.last_cached )

        self.assertEquals( mtc_f.increment( ), 1 )
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append( mtc_f.last_cached )
        self.assertEquals( mtc_f.increment( ), 2 )
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append( mtc_f.last_cached )
        self.assertEquals( mtc_f.increment( ), 3 )
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append( mtc_f.last_cached )
        self.assertEquals( mtc_f.increment( ), 4 )
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append( mtc_f.last_cached )

        # Ensure hashes are now in db:
        for hash in hashes:
            self.assertIsNotNone(hash, "Hash is none. whoops.")
            cd = fetch( hash )
            self.assertTrue( cd is not None, "%s was not found" % hash )
            self.assertEquals( cd.hash, hash, "%s was not found" % hash )

        # Delete some:
        caliendo.util.recache( 'methodb', 'caliendo_test.py' )
        caliendo.util.recache( 'methoda', 'caliendo_test.py' )

        # Ensure they're gone:
        methodb = hashes[0]
        methoda = hashes[1]
        cd = fetch( methodb )

        self.assertIsNone( cd, "Method b failed to recache." )
        cd = fetch( methoda )

        self.assertIsNone( cd, "Method a failed to recache." )

        # Ensure the rest are there:
        hashes = hashes[3:]
        for hash in hashes:
            cd = fetch( hash )
            self.assertEquals( cd.hash, hash )

        # Delete them ALL:
        caliendo.util.recache()

        #Ensure they're all gone:
        for hash in hashes:
            cd = fetch( hash )
            self.assertIsNone( cd )
    def test_recache(self):
        mtc = TestC()
        mtc_f = Facade(mtc)

        hashes = []

        self.assertEquals(mtc.methoda(), mtc_f.methoda())
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append(mtc_f.last_cached)
        self.assertEquals(mtc.methodb(), mtc_f.methodb())
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append(mtc_f.last_cached)
        self.assertEquals(mtc_f.methoda(), "a")
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append(mtc_f.last_cached)

        self.assertEquals(mtc_f.increment(), 1)
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append(mtc_f.last_cached)
        self.assertEquals(mtc_f.increment(), 2)
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append(mtc_f.last_cached)
        self.assertEquals(mtc_f.increment(), 3)
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append(mtc_f.last_cached)
        self.assertEquals(mtc_f.increment(), 4)
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append(mtc_f.last_cached)

        # Ensure hashes are now in db:
        for hash in hashes:
            self.assertIsNotNone(hash, "Hash is none. whoops.")
            cd = fetch(hash)
            self.assertTrue(cd is not None, "%s was not found" % hash)
            self.assertEquals(cd.hash, hash, "%s was not found" % hash)

        # Delete some:
        caliendo.util.recache('methodb', 'caliendo_test.py')
        caliendo.util.recache('methoda', 'caliendo_test.py')

        # Ensure they're gone:
        methodb = hashes[0]
        methoda = hashes[1]
        cd = fetch(methodb)

        self.assertIsNone(cd, "Method b failed to recache.")
        cd = fetch(methoda)

        self.assertIsNone(cd, "Method a failed to recache.")

        # Ensure the rest are there:
        hashes = hashes[3:]
        for hash in hashes:
            cd = fetch(hash)
            self.assertEquals(cd.hash, hash)

        # Delete them ALL:
        caliendo.util.recache()

        #Ensure they're all gone:
        for hash in hashes:
            cd = fetch(hash)
            self.assertIsNone(cd)