class IntegrationTest(unittest.TestCase): def setUp(self): self._renderer = LocalRenderer(_BASE_PATH) def testCronAndPublicFiles(self): '''Runs cron then requests every public file. Cron needs to be run first because the public file requests are offline. ''' if _EXPLICIT_TEST_FILES is not None: return print('Running cron...') start_time = time.time() try: render_content, render_status, _ = self._renderer.Render( '/cron/stable') self.assertEqual(200, render_status) self.assertEqual('Success', render_content) finally: print('Took %s seconds' % (time.time() - start_time)) public_files = _GetPublicFiles() print('Rendering %s public files...' % len(public_files.keys())) start_time = time.time() try: for path, content in _GetPublicFiles().iteritems(): def check_result(render_content, render_status, _): self.assertEqual( 200, render_status, 'Got %s when rendering %s' % (render_status, path)) # This is reaaaaally rough since usually these will be tiny templates # that render large files. At least it'll catch zero-length responses. self.assertTrue( len(render_content) >= len(content), 'Content was "%s" when rendering %s' % (render_content, path)) check_result(*self._renderer.Render(path)) # Samples are internationalized, test some locales. if path.endswith('/samples.html'): for lang in ['en-US', 'es', 'ar']: check_result(*self._renderer.Render( path, headers={'Accept-Language': '%s;q=0.8' % lang})) finally: print('Took %s seconds' % (time.time() - start_time)) def testExplicitFiles(self): '''Tests just the files in _EXPLICIT_TEST_FILES. ''' if _EXPLICIT_TEST_FILES is None: return for filename in _EXPLICIT_TEST_FILES: print('Rendering %s...' % filename) start_time = time.time() try: render_content, render_status, _ = self._renderer.Render( filename, always_online=True) self.assertEqual(200, render_status) self.assertTrue(render_content != '') finally: print('Took %s seconds' % (time.time() - start_time)) @DisableLogging('warning') def testFileNotFound(self): render_content, render_status, _ = self._renderer.Render( '/extensions/notfound.html', always_online=True) self.assertEqual(404, render_status)
def testSiteVerificationFile(self): response = LocalRenderer.Render('/' + SITE_VERIFICATION_FILE) self.assertEqual(200, response.status)
if opts.render: if opts.render.find('#') >= 0: (path, iterations) = opts.render.rsplit('#', 1) extra_iterations = int(iterations) - 1 else: path = opts.render extra_iterations = 0 if opts.stat: import cProfile, pstats, StringIO pr = cProfile.Profile() pr.enable() elif opts.time: start_time = time.time() response = LocalRenderer.Render(path) if response.status != 200: print('Error status: %s' % response.status) exit(1) for _ in range(extra_iterations): LocalRenderer.Render(path) if opts.stat: pr.disable() s = StringIO.StringIO() pstats.Stats(pr, stream=s).sort_stats(opts.stat).print_stats() print(s.getvalue()) elif opts.time: print('Took %s seconds' % (time.time() - start_time)) else:
def testFileNotFound(self): response = LocalRenderer.Render('/extensions/notfound') self.assertEqual(404, response.status)