示例#1
0
文件: __init__.py 项目: chi1/trinitee
 def setUp(self):
     self.dajaxice = Dajaxice()
示例#2
0
文件: __init__.py 项目: chi1/trinitee
class DajaxiceModuleTest(unittest.TestCase):
    def setUp(self):
        self.dajaxice = Dajaxice()
        
    def test_is_callable(self):
        self.dajaxice._callable.append('test')
        
        self.assertTrue(self.dajaxice.is_callable('test'))
        self.assertFalse(self.dajaxice.is_callable('other'))
    
    def test_get_functions(self):
        self.dajaxice._registry = []
        self.failUnlessEqual(self.dajaxice.get_functions(), [])
        
        self.dajaxice._registry = [DajaxiceModule('a.function','a.function'), DajaxiceModule('b.function','b.function')]
        self.failUnlessEqual(len(self.dajaxice.get_functions()), 2)
        
        self.failUnlessEqual(type(self.dajaxice.get_functions()[0]), DajaxiceModule)
        self.failUnlessEqual(type(self.dajaxice.get_functions()[1]), DajaxiceModule)
    
    def test_exist_module(self):
        self.dajaxice._registry = [DajaxiceModule('a.function','a.function'), DajaxiceModule('b.function','b.function')]
        self.failUnlessEqual(self.dajaxice._exist_module('a'), 0)
        self.failUnlessEqual(self.dajaxice._exist_module('b'), 1)
        self.assertFalse(self.dajaxice._exist_module('c'))
    
    def test_register(self):
        from ajax import test_foo, test_foo_with_params
        self.dajaxice.register(test_foo)
        self.dajaxice.register(test_foo_with_params)
        
        name = '%s.%s' % (test_foo.__module__, test_foo.__name__)
        name2 = '%s.%s' % (test_foo_with_params.__module__, test_foo_with_params.__name__)
        
        self.assertTrue(name in self.dajaxice._callable)
        self.assertTrue(name2 in self.dajaxice._callable)
        self.failUnlessEqual(len(self.dajaxice._callable), 2)
        
        self.failUnlessEqual(len(self.dajaxice._registry), 1)
        self.failUnlessEqual(type(self.dajaxice._registry[0]), DajaxiceModule)
        #further testing is needed