def wrap_interface(self):
     """
     Wraps the interface in an implementation specific class
     
     Verifies:
         * interface is just returned, by default this does nothing
     """
     api = TestAPI()
     module = Bar()
     wrapped = api.wrap_interface(module.foo)
     self.assertEqual(wrapped, module.foo)
 def test_register_attribute(self):
     """
     Registering an interface
     
     Verifies:
         * registering an attribute
         * deregistering interface
     """
     module = Bar()
     api = TestAPI()
     
     api.register_interface(module, 'xoo')
     self.assert_('xoo' in api._registered_interfaces)
     api.deregister_interface(module, 'xoo')
     self.assertFalse('xoo' in api._registered_interfaces)
 def test_register_function(self):
     """
     Registering an interface
     
     Verifies:
         * registering a function
         * deregistering interface
     """
     module = Bar()
     api = TestAPI()
     
     api.register_interface(module, module.foo)
     self.assert_('foo' in api._registered_interfaces)
     api.deregister_interface(module, module.foo)
     self.assertFalse('foo' in api._registered_interfaces)
 def test_register_attribute_alternate_name(self):
     """
     Registering an interface
     
     Verifies:
         * registering an attribute with an alternate name
         * deregistering interface
     """
     module = Bar()
     api = TestAPI()
     
     api.register_interface(module, module.foo, name='TEST_NAME')
     self.assert_('TEST_NAME' in api._registered_interfaces)
     api.deregister_interface(module, module.foo, name='TEST_NAME')
     self.assertFalse('TEST_NAME' in api._registered_interfaces)
 def test_clean_sessions(self):
     """
     removes expired sessions
     
     Verifies:
         * expired sessions are removed
         * non_expired sessions are not
     """
     api = TestAPI()
     
     session0 = {'expire':datetime.now()-timedelta(1)}
     session1 = {'expire':datetime.now()+timedelta(0,0,0,100)}
     session2 = {'expire':datetime.now()+timedelta(1)}
     api.sessions = {0:session0, 1:session1, 2:session2}
     
     # expire expired sessions
     api._clean_sessions()
     self.assertFalse(0 in api.sessions)
     self.assert_(1 in api.sessions)
     self.assert_(2 in api.sessions)
     
     # wait for second session to expire
     time.sleep(.15)
     api._clean_sessions()
     self.assertFalse(1 in api.sessions, api.sessions)
     self.assert_(2 in api.sessions)
 def test_get_interface_name(self):
     """
     Tests generating interface name from different input
     
     Verifies:
         * name from function
         * name from attribute
         * name included in params
     """
     module = Bar()
     api = TestAPI()
     
     name = api._interface_name(module, module.foo)
     self.assertEqual('foo', name)
     
     name = api._interface_name(module, 'xoo')
     self.assertEqual('xoo', name)
     
     name = api._interface_name(module, module.foo, name='TEST_NAME')
     self.assertEqual('TEST_NAME', name)
     
     name = api._interface_name(module, 'xoo', name='TEST_NAME')
     self.assertEqual('TEST_NAME', name)
 def test_replace_interface(self):
     """
     Registering interface with existing name
     
     Verifies:
         * existing interface is replaced
     """
     module = Bar()
     api = TestAPI()
     api.register_interface(module, module.foo)
     
     # replace with named function
     api.register_interface(module, module.bar, name='foo')
     self.assert_('foo' in api._registered_interfaces)
     self.assertEqual(module.bar, api._registered_interfaces['foo'])
     
     # replace with function
     api.register_interface(module, module.foo)
     self.assert_('foo' in api._registered_interfaces)
     self.assertEqual(module.foo, api._registered_interfaces['foo'])