1. John Chandler
  2. django-fluidproxy

Source

django-fluidproxy / tests.py

import unittest

from django.conf import settings
settings.configure( CACHE_BACKEND = 'locmem://' )

from django.core.cache import cache
from fom.session       import Fluid

from django_fluidproxy import FluidAPIProxy


SANDBOX_URL = "http://sandbox.fluidinfo.com"


class TestFluidAPIProxy( unittest.TestCase ):
    """ Tests the FluidAPIProxy class instantiation """
    def test_none_fluiddb_session( self ):
        """ Tests raising of TypeError if we supply None as a FluidDB session """
        self.assertRaises( TypeError, FluidAPIProxy, None )

    def test_object_fluiddb_session( self ):
        """ Tests raising of TypeError if we supply a non-Fluid object as a FluidDB session """
        class Dummy( object ):
            pass
        
        self.assertRaises( TypeError, FluidAPIProxy, Dummy() )

    def test_valid_fluiddb_session( self ):
        """ Tests successful instantiation if FluidDB session supplied """
        fluid = Fluid( SANDBOX_URL )

        self.assertTrue( FluidAPIProxy( fluid ) )

    def test_fluiddb_session_stored( self ):
        """ Tests supplied FluidDB session is stored """
        fluid = Fluid( SANDBOX_URL )
        proxy = FluidAPIProxy( fluid )
        
        self.assertEqual( proxy.fluid, fluid )


class TestFluidAPIProxyCaching( unittest.TestCase ):
    """ Tests the caching capability of the FluidAPIProxy class """
    def setUp( self ):
        cache.clear()
        self.proxy = FluidAPIProxy( fluid=Fluid(SANDBOX_URL) )

    def test_preload_path( self ):
        """ Tests preloading cache for a simple path """
        key   = "fluidproxy:a16b1ac35cb8cf6d6e2939d12fe68cee5860d9bc"
        value = 1234
        
        self.proxy.preload( "/metaljoe/test/foo", value=value )

        self.assertEqual( cache.get(key), value )

    def test_unload_path( self ):
        """ Tests unloading cache for a simple path """
        key   = "fluidproxy:a16b1ac35cb8cf6d6e2939d12fe68cee5860d9bc"
        value = 1234

        cache.set( key, value )
        self.proxy.unload( "/metaljoe/test/foo" )

        self.assertEqual( cache.get(key), None )

    def test_get_path( self ):
        """ Tests retrieving a simple, cached path """
        path  = "/metaljoe/test/foo"
        value = 1234
        
        self.proxy.preload( path, value=value )

        self.assertEqual( self.proxy.get(path), value )
        

if __name__ == "__main__":
    unittest.main()