def test_instrument(): assert not chirp.is_instrumented() chirp.instrument_site(True) py.test.raises(chirp.ChirpError, chirp.instrument_site, True) assert chirp.is_instrumented() chirp.instrument_site(False) assert not chirp.is_instrumented() settings.SKYLARK_CHIRP_INSTRUMENTED = True # This only get's triggered if we render a page, so let's do that request = get_request_fixture() c = RequestContext(request, {}) sa = SnippetAssembly('dummyapp/snippet/snippet.yaml', c) content = sa.dumps() assert chirp.is_instrumented() settings.SKYLARK_CHIRP_INSTRUMENTED = False
def prepare_chirp(self, page_instructions): chirp_instructions = page_instructions.chirp self.prepared_instructions['chirp'] = chirp_instructions for chirp_module in chirp_instructions: assert 'namespace' in chirp_module, ('You are missing the ' 'namespace attribute for this item') assert 'location' in chirp_module, ('You are missing the ' 'location attribute for this item') assert 'require' in chirp_module or 'tests' in chirp_module, ( 'You are missing the require list for this item') if not 'require' in chirp_module: chirp_module['require'] = [] chirp_module['needs_registration'] = True namespace = chirp_module['namespace'] location = chirp_module['location'] require = chirp_module['require'] tests = [] if chirp.is_instrumented(): tests = chirp_module.get('tests', tests) require.extend(tests) """ We're going to copy all the files that are in this directory to the cache. This is not ideal, as not all the files may be used but the alternative is we ask the user specifically which ones they need. Since this is within the context of Dojo, that may not make the most sense. """ self._prepare_assets(page_instructions, (location,))
def render(self): """ Takes a chunk of page instructions and renders a page according to the rules found within This return a string representing the HTML or similar output """ assert self.page_instructions.body, \ 'The body has not been specified in the page instructions ' + \ '(body: in your yaml file)' if self.render_full_page: assert self.page_instructions.title, \ 'The title has not been specified in the page ' + \ 'instructions (title: in your yaml file)' plan = plans.get_for_context(self.context, self.page_instructions.render_full_page) prepared_instructions = plan.prepare(self.page_instructions, omit_media=self.omit_media) render_context = copy.copy(self.context) render_context['cache_url'] = settings.SKYLARK_CACHE_URL render_context['doctype'] = self.doctype render_context['prepared_instructions'] = prepared_instructions render_context['is_instrumented'] = chirp.is_instrumented() if self.render_full_page: t = self.template_name else: t = self.snippet_template_name self.template = loader.get_template(t) return self.template.render(render_context)
def test_chirp_testcase_is_included(): assert not chirp.is_instrumented() chirp.instrument_site(True) request = get_request_fixture() c = RequestContext(request, {}) pa = PageAssembly('dummyapp/page/chirp.yaml', c) content = pa.dumps() assert 'dojo.require(\'ChirpTools.TestRunner' in content assert 'dojo.require(\'ChirpTools.Mvc' in content assert 'ChirpTools.TestRunner.TestCaseCollector' in content
def interface_start(request): """ Provides the main HTML for the test runner """ if not is_instrumented(): instrument_site(True) teps = [ i.__dict__ for i in test_registry.list() ] context = RequestContext(request, { 'test_count': len(test_registry), 'test_entry_points_json': simplejson.dumps(teps), 'url_deinstrument': reverse(deinstrument), }) pa = PageAssembly('chirp/testrunner/display/display.yaml', context) return pa.get_http_response()
def test_chirp_includes_tests(): assert not chirp.is_instrumented() chirp.instrument_site(True) request = get_request_fixture() c = RequestContext(request, {}) pa = PageAssembly('dummyapp/page/chirp.yaml', c) content = pa.dumps() assert "dojo.require('DynamicApp.Page.Test')" in content chirp.instrument_site(False) c = RequestContext(request, {}) pa = PageAssembly('dummyapp/page/chirp.yaml', c) content = pa.dumps() assert "dojo.require('DynamicApp.Page.Test')" not in content