class InterfaceResourceTestCase(unittest.TestCase, TwistedWebInterfaceTestCaseMixin):
    
    def setUp(self):
        TwistedWebInterfaceTestCaseMixin.setUp(self)
        module = Bar()
        self.manager.register(module)
        self.resource = InterfaceResource(self.twisted_web_interface)
    
    def test_render(self):
        """
        Tests rendering the root resource
        
        Verifies:
            * list of registered interfaces is returned as json
        """
        response = set(simplejson.loads(self.resource.render(None)))
        check = set(['authenticate', 'challenge_response', 'foo','foo2'])
        self.assertEquals(response, check)
    
    def test_get_root_resource(self):
        """
        Tests root url
        
        Verifies:
            * returns list of interfaces that can be called
        """
        resource = self.resource.getChildWithDefault('', None)
        self.assertEqual(self.resource, self.resource)
    
    def test_get_interface_resource(self):
        """
        Tests retrieving a resource for an interface
        
        Verifies:
            * a function resource is returned
        """
        resource = self.resource.getChildWithDefault('foo', None)
        self.assert_(isinstance(resource, (FunctionResource,)))
    
    def test_get_invalid_interface(self):
        """
        Tests requesting a resource that does not exist:
        
        Verifies:
            * returns 404
        """
        resource = self.resource.getChildWithDefault('invalid path', None)
        self.assert_(isinstance(resource, (NoResource,)), 'invalid path should return 404 object')
 def setUp(self):
     TwistedWebInterfaceTestCaseMixin.setUp(self)
     module = Bar()
     self.manager.register(module)
     self.resource = InterfaceResource(self.twisted_web_interface)