Commits

John Chandler committed 6db9148

Major restructuring of project code

Comments (0)

Files changed (7)

 syntax: glob
 
-# Python pyc files
+# Python files
 *.pyc
+*.egg-info
 

django_fluidproxy.py

-# The MIT License
-#
-# Copyright (c) 2010 John Chandler
-# 
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-# 
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-# 
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-
-import hashlib
-
-from django.core.cache import cache
-from fom.session       import Fluid
-
-
-def generate_cache_key( path ):
-    """ Returns a key suitable for calls to cache """
-    h = hashlib.sha1()
-    h.update( path )
-    
-    return "fluidproxy:%s" % h.hexdigest()
-    
-
-class FluidAPIProxy( object ):
-    """ A FluidDB API proxy class for use with Django.
-        Uses Django's caching framework to cache FluidDB GET requests to:
-        - Reduce network usage
-        - Improve performance
-        - Make it easier to test FluidDB calls without hitting the network
-    """
-    def __init__( self, fluid ):
-        """ fluid: FluidDB session object """
-        if not isinstance( fluid, Fluid ):
-            raise TypeError( "Argument fluid requires Fluid session object" )  # FIXME: sucky for anyone using a Mock FluidDB session
-        self.fluid = fluid
-
-    def get( self, path ):
-        """ Make a proxied FluidDB API call """
-        return cache.get( generate_cache_key(path) )
-
-    def preload( self, path, value=None ):
-        """ Preload proxy cache
-            path  = FluidDB path e.g. /path/to/tag
-            value = value of path
-        """        
-        cache.set( generate_cache_key(path), value )
-
-    def unload( self, path ):
-        """ Unload proxy cache
-            path = FluidDB path e.g. /path/to/tag
-        """
-        cache.delete( generate_cache_key(path) )
-    

fluidproxy/__init__.py

Empty file added.

fluidproxy/django_fluidproxy.py

+# The MIT License
+#
+# Copyright (c) 2010 John Chandler
+# 
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+# 
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+import hashlib
+
+from django.core.cache import cache
+from fom.session       import Fluid
+
+
+def generate_cache_key( path ):
+    """ Returns a key suitable for calls to cache """
+    h = hashlib.sha1()
+    h.update( path )
+    
+    return "fluidproxy:%s" % h.hexdigest()
+    
+
+class FluidAPIProxy( object ):
+    """ A FluidDB API proxy class for use with Django.
+        Uses Django's caching framework to cache FluidDB GET requests to:
+        - Reduce network usage
+        - Improve performance
+        - Make it easier to test FluidDB calls without hitting the network
+    """
+    def __init__( self, fluid ):
+        """ fluid: FluidDB session object """
+        if not isinstance( fluid, Fluid ):
+            raise TypeError( "Argument fluid requires Fluid session object" )  # FIXME: sucky for anyone using a Mock FluidDB session
+        self.fluid = fluid
+
+    def get( self, path ):
+        """ Make a proxied FluidDB API call """
+        return cache.get( generate_cache_key(path) )
+
+    def preload( self, path, value=None ):
+        """ Preload proxy cache
+            path  = FluidDB path e.g. /path/to/tag
+            value = value of path
+        """        
+        cache.set( generate_cache_key(path), value )
+
+    def unload( self, path ):
+        """ Unload proxy cache
+            path = FluidDB path e.g. /path/to/tag
+        """
+        cache.delete( generate_cache_key(path) )
+    

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()
+    
+from setuptools import setup
+
+setup( name="django_fluidproxy",
+       version="0.0.0",
+       author="John Chandler",
+       author_email="metaljoe@metaljoe.plus.com",
+       license="MIT",
+       url="http://bitbucket.org/metaljoe/django-fluidproxy",
+       test_suite="fluidproxy.tests"
+     )

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()
-