def test_amd_init_no_spec(self): from pyramid_amdjs.amd import amd_init self.config.add_amd_js( 'test-mod', 'pyramid_amdjs:tests/dir/test.js') self.request.matchdict['specname'] = 'unknown' resp = amd_init(self.request) self.assertIsInstance(resp, HTTPNotFound)
def test_bundles_amd(self): from pyramid_amdjs.amd import amd_init self.config.add_handlebars_bundle('test-bundle', 'pyramid_amdjs:tests/bundle/') self.request.matchdict['specname'] = '_' res = amd_init(self.request) self.assertIn('"test-bundle":"/_handlebars/test-bundle.js?_v=', res.text)
def test_bundles_amd(self): from pyramid_amdjs.amd import amd_init self.config.add_handlebars_bundle( 'test-bundle', 'pyramid_amdjs:tests/bundle/') self.request.matchdict['specname'] = '_' res = amd_init(self.request) self.assertIn( '"test-bundle":"/_handlebars/test-bundle.js?_v=', res.text)
def test_amd_init_with_spec_handlebars(self): from pyramid_amdjs.amd import amd_init, ID_AMD_SPEC self.request.matchdict['specname'] = 'test' self.request.registry = self.registry self.registry[ID_AMD_SPEC] = { 'test': {'underscore': {'name': 'test', 'md5': '123', 'path': 'pyramid_amdjs:static/example.js'}} } resp = amd_init(self.request) self.assertIn( '"underscore": "/_amdjs/static/example.js?_v=123"', resp.text)
def test_amd_init_from_file(self): from pyramid_amdjs.amd import amd_init, RESOLVER, ID_AMD_SPEC self.request.params['_v'] = '123' self.request.matchdict['specname'] = 'test' self.registry[ID_AMD_SPEC] = \ {'test': {'pyramid': {}}, 'test-init': RESOLVER.resolve( 'pyramid_amdjs:tests/dir/test2.js').abspath()} resp = amd_init(self.request) self.assertIsInstance(resp, FileResponse) self.assertEqual('max-age=31536000', resp.headers['Cache-Control'])
def test_amd_init_with_v(self): from pyramid_amdjs.amd import amd_init, ID_AMD_SPEC self.request.params['_v'] = '123' self.request.matchdict['specname'] = 'test' self.registry[ID_AMD_SPEC] = \ {'test': {'pyramid': {'name': 'test', 'md5': '123', 'path': 'pyramid_amdjs:static/example.js'}}} resp = amd_init(self.request) self.assertEqual('max-age=31536000', resp.headers['Cache-Control']) self.assertIn( '"pyramid": "/_amdjs/static/example.js?_v=123"', resp.text)
def test_amd_mod_from_dir(self): from pyramid_amdjs.amd import amd_init self.config.add_amd_dir('pyramid_amdjs:tests/dir/') self.request.matchdict['specname'] = '_' resp = amd_init(self.request) self.assertIn( '"jca-globals": ' '"/_tests/test.js?_v=4ce2ec81952ee8e6d0058334361babbe"', resp.text) self.assertIn( '"test3.css": ' '"/_tests/test3.css?_v=6305443b362b239fad70ffc6d59c98df"', resp.text)
def test_bundles_amd_spec(self): from pyramid_amdjs.amd import amd_init, ID_AMD_SPEC self.registry[ID_AMD_SPEC] = { 'test': {'test-bundle': {'name': 'bundle', 'md5': '123', 'path': 'pyramid_amdjs:static/example.js'}} } self.config.add_handlebars_bundle( 'test-bundle', 'pyramid_amdjs:tests/bundle/') self.request.matchdict['specname'] = 'test' res = amd_init(self.request) self.assertIn( '"test-bundle":"/_amdjs/static/example.js?_v=123"', res.text)
def test_bundles_amd_spec(self): from pyramid_amdjs.amd import amd_init, ID_AMD_SPEC self.registry[ID_AMD_SPEC] = { 'test': { 'test-bundle': { 'name': 'bundle', 'md5': '123', 'path': 'pyramid_amdjs:static/example.js' } } } self.config.add_handlebars_bundle('test-bundle', 'pyramid_amdjs:tests/bundle/') self.request.matchdict['specname'] = 'test' res = amd_init(self.request) self.assertIn('"test-bundle":"/_amdjs/static/example.js?_v=123"', res.text)
def test_amd_mod_paths(self): from pyramid_amdjs.amd import amd_init self.config.add_amd_js( 'test-mod', 'pyramid_amdjs:tests/dir/test.js') self.config.add_amd_css( 'test-css', 'pyramid_amdjs:tests/dir/test3.css') self.request.matchdict['specname'] = '_' resp = amd_init(self.request) self.assertIn('var pyramid_amd_modules = {', resp.text) self.assertIn( '"test-mod": ' '"/_tests/test.js?_v=4ce2ec81952ee8e6d0058334361babbe"', resp.text) self.assertIn( '"test-css": ' '"/_tests/test3.css?_v=6305443b362b239fad70ffc6d59c98df"', resp.text)