def test_amd_init_with_spec_url(self): from ptah.amd import amd_init, ID_AMD_MODULE, ID_AMD_SPEC self.registry[ID_AMD_MODULE] = {'ptah': 'ptah:static/ptah.js'} self.registry[ID_AMD_SPEC] = \ {'test': {'ptah': {'url': 'http://test.com/example.js'}}} self.request.matchdict['specname'] = 'test' resp = amd_init(self.request) self.assertEqual(resp.status, '200 OK') self.registry[ID_AMD_SPEC] = \ {'test': {'ptah': {'name':'test', 'path':'ptah:static/example.js'}}} resp = amd_init(self.request) self.assertIn('"ptah": "http://example.com/_amd_test/t"', resp.text)
def test_amd_init_no_spec(self): from ptah.amd import amd_init self.config.register_amd_module( 'test-mod', 'ptah:tests/dir/test.js') self.request.matchdict['specname'] = 'unknown' resp = amd_init(self.request) self.assertIsInstance(resp, HTTPNotFound)
def test_amd_init_with_spec_mustache(self): from ptah.amd import amd_init, ID_AMD_MODULE, ID_AMD_SPEC self.request.matchdict['specname'] = 'test' self.registry[ID_AMD_SPEC] = \ {'test': {'ptah-templates': {'name':'test', 'path':'ptah:static/example.js'}}} resp = amd_init(self.request) self.assertIn( '"ptah-templates":"http://example.com/_amd_test/t"', resp.text)
def test_bundles_amd(self): from ptah.amd import amd_init self.config.register_mustache_bundle( 'test-bundle', 'ptah:tests/bundle/') self.request.matchdict['specname'] = '_' res = amd_init(self.request) self.assertIn( '"test-bundle":"http://example.com/_mustache/test-bundle"',res.text)
def test_amd_mod_paths(self): from ptah.amd import amd_init self.config.register_amd_module( 'test-mod', 'ptah:tests/dir/test.js') self.request.matchdict['specname'] = '_' resp = amd_init(self.request) self.assertIn('var ptah_amd_modules = {', resp.text) self.assertIn( '"test-mod": "http://example.com/_tests/test"', resp.text)