def test_is_callable(self): dr = DajaxiceRequest(None, 'utilities.dajaxice.tests.test_registered_function') self.failUnless(dr._is_callable()) dr = DajaxiceRequest(None, 'utilities.dajaxice.tests.test_ajax_not_registered') self.failIf(dr._is_callable())
def handle(self, *app_labels, **options): compile_output = options.get('compile','yes') data = {'dajaxice_js_functions':DajaxiceRequest.get_js_functions(), 'DAJAXICE_URL_PREFIX': DajaxiceRequest.get_media_prefix(), 'DAJAXICE_XMLHTTPREQUEST_JS_IMPORT':DajaxiceRequest.get_xmlhttprequest_js_import(), 'DAJAXICE_JSON2_JS_IMPORT':DajaxiceRequest.get_json2_js_import(), 'DAJAXICE_EXCEPTION':DajaxiceRequest.get_exception_message(), } js = render_to_string('dajaxice/dajaxice.core.js', data ) if compile_output.lower() == "closure": print self.complie_js_with_closure(js) else: print js
def test_get_js_functions(self): js_functions = DajaxiceRequest.get_js_functions() callables = ['utilities.dajaxice.tests.ajax.test_registered_function', 'utilities.dajaxice.tests.ajax.test_string', 'utilities.dajaxice.tests.ajax.test_ajax_exception', 'utilities.dajaxice.tests.ajax.test_foo', 'utilities.dajaxice.tests.ajax.test_foo_with_params'] functions = [f.rsplit('.',1)[1] for f in callables] self.failUnlessEqual(len(js_functions), 1) self.failUnlessEqual(dajaxice_functions._callable, callables) sub = js_functions[0] self.failUnlessEqual(len(sub.sub_modules), 1) self.failUnlessEqual(len(sub.functions), 0) self.failUnlessEqual(sub.name, 'dajaxice') sub = js_functions[0].sub_modules[0] self.failUnlessEqual(len(sub.sub_modules), 0) self.failUnlessEqual(len(sub.functions), 5) self.failUnlessEqual(sub.functions, functions) self.failUnlessEqual(sub.name, 'tests')
def test_get_ajax_function(self): # Test modern Import with a real ajax function dr = DajaxiceRequest(None, 'utilities.dajaxice.tests.test_foo') function = dr._modern_get_ajax_function() self.failUnless(hasattr(function, '__call__') ) # Test old Import with a real ajax function dr = DajaxiceRequest(None, 'utilities.dajaxice.tests.test_foo') function = dr._old_get_ajax_function() self.failUnless(hasattr(function, '__call__') ) # Test modern Import without a real ajax function dr = DajaxiceRequest(None, 'utilities.dajaxice.tests.test_foo2') self.failUnlessRaises(DajaxiceImportError, dr._modern_get_ajax_function) # Test old Import without a real ajax function dr = DajaxiceRequest(None, 'utilities.dajaxice.tests.test_foo2') self.failUnlessRaises(DajaxiceImportError, dr._old_get_ajax_function)
def dajaxice_js_import(context): return { 'DAJAXICE_MEDIA_PREFIX': DajaxiceRequest.get_media_prefix() }