def test_reload_changectx_working_dir(self): app = create_app(repo_path=self.repo_path, revision_id=REVISION_WORKING_DIR) client = app.test_client() rv = client.get('/') self.assertTrue(b'post/lorem-ipsum' in rv.data) self.assertTrue(b'post/example-post' in rv.data) commands.add(self.ui, self.repo) rv = client.get('/') self.assertTrue(b'post/lorem-ipsum' in rv.data) self.assertTrue(b'post/example-post' in rv.data) commands.commit(self.ui, self.repo, message=b'foo', user=b'foo') rv = client.get('/') self.assertTrue(b'post/lorem-ipsum' in rv.data) self.assertTrue(b'post/example-post' in rv.data) with codecs.open(os.path.join(self.repo_path, app.config['CONTENT_DIR'], 'about.rst'), 'a', encoding='utf-8') as fp: fp.write('\n\nTHIS IS A TEST!\n') rv = client.get('/about/') self.assertTrue(b'THIS IS A TEST!' in rv.data) commands.commit(self.ui, self.repo, message=b'foo', user=b'foo') rv = client.get('/about/') self.assertTrue(b'THIS IS A TEST!' in rv.data) with codecs.open(os.path.join(self.repo_path, app.config['CONTENT_DIR'], 'about.rst'), 'a', encoding='utf-8') as fp: fp.write('\n\nTHIS IS another TEST!\n') rv = client.get('/about/') self.assertTrue(b'THIS IS another TEST!' in rv.data) commands.commit(self.ui, self.repo, message=b'foo', user=b'foo') rv = client.get('/about/') self.assertTrue(b'THIS IS another TEST!' in rv.data)
def test_reload_changectx_working_dir(self): app = create_app(repo_path=self.repo_path, revision_id=REVISION_WORKING_DIR) client = app.test_client() rv = client.get('/') self.assertTrue('post/lorem-ipsum' in rv.data) self.assertTrue('post/example-post' in rv.data) commands.add(self.ui, self.repo) rv = client.get('/') self.assertTrue('post/lorem-ipsum' in rv.data) self.assertTrue('post/example-post' in rv.data) commands.commit(self.ui, self.repo, message='foo', user='******') rv = client.get('/') self.assertTrue('post/lorem-ipsum' in rv.data) self.assertTrue('post/example-post' in rv.data) with codecs.open(os.path.join(self.repo_path, app.config['CONTENT_DIR'], 'about.rst'), 'a', encoding='utf-8') as fp: fp.write('\n\nTHIS IS A TEST!\n') rv = client.get('/about/') self.assertTrue('THIS IS A TEST!' in rv.data) commands.commit(self.ui, self.repo, message='foo', user='******') rv = client.get('/about/') self.assertTrue('THIS IS A TEST!' in rv.data) with codecs.open(os.path.join(self.repo_path, app.config['CONTENT_DIR'], 'about.rst'), 'a', encoding='utf-8') as fp: fp.write('\n\nTHIS IS another TEST!\n') rv = client.get('/about/') self.assertTrue('THIS IS another TEST!' in rv.data) commands.commit(self.ui, self.repo, message='foo', user='******') rv = client.get('/about/') self.assertTrue('THIS IS another TEST!' in rv.data)
def test_up2date_changectx_working_dir(self): app = create_app(repo_path=self.repo_path, revision_id=REVISION_WORKING_DIR) with app.test_request_context(): app.preprocess_request() self.assertRaises(TemplateNotFound, app.jinja_loader.get_source, app.jinja_env, 'test.html') new_file = os.path.join(self.repo_path, app.template_folder, 'test.html') with codecs.open(new_file, 'w', encoding='utf-8') as fp: fp.write('foo') with app.test_request_context(): app.preprocess_request() contents, filename, up2date = app.jinja_loader.get_source( app.jinja_env, 'test.html') self.assertEqual('foo', contents) self.assertEqual(filename, os.path.join(app.template_folder, 'test.html')) app.preprocess_request() self.assertFalse(up2date()) commands.commit(self.ui, self.repo, message='foo', user='******', addremove=True) contents, filename, up2date = app.jinja_loader.get_source( app.jinja_env, 'test.html') self.assertEqual('foo', contents) app.preprocess_request() self.assertFalse(up2date())
def setUp(self): self.repo_path = mkdtemp() self.ui = ui.ui() self.ui.setconfig('ui', 'quiet', True) HgRepository.create_repo(self.repo_path) self.repo = hg.repository(self.ui, self.repo_path) commands.commit(self.ui, self.repo, message='foo', user='******', addremove=True) self.app = create_app(repo_path=self.repo_path, revision_id=REVISION_DEFAULT)
def test_up2date_changectx_default(self): app = create_app(repo_path=self.repo_path, autoinit=False) new_file = os.path.join(self.repo_path, 'foo') with codecs.open(new_file, 'w', encoding='utf-8') as fp: fp.write('foo') commands.commit(self.ui, self.repo, message='foo', user='******', addremove=True) app.blohg.init_repo(REVISION_DEFAULT) with app.test_request_context(): app.preprocess_request() self.assertRaises(TemplateNotFound, app.jinja_loader.get_source, app.jinja_env, 'test.html') new_file = os.path.join(self.repo_path, app.template_folder, 'test.html') with codecs.open(new_file, 'w', encoding='utf-8') as fp: fp.write('foo') with app.test_request_context(): app.preprocess_request() self.assertRaises(TemplateNotFound, app.jinja_loader.get_source, app.jinja_env, 'test.html') commands.commit(self.ui, self.repo, message='foo', user='******', addremove=True) with app.test_request_context(): app.preprocess_request() contents, filename, up2date = app.jinja_loader.get_source( app.jinja_env, 'test.html') self.assertEqual('foo', contents) self.assertEqual(filename, os.path.join(app.template_folder, 'test.html')) app.preprocess_request() self.assertTrue(up2date()) with codecs.open(new_file, 'a', encoding='utf-8') as fp: fp.write('bar') app.preprocess_request() self.assertTrue(up2date()) commands.commit(self.ui, self.repo, message='foo', user='******', addremove=True) app.preprocess_request() self.assertFalse(up2date()) contents, filename, up2date = app.jinja_loader.get_source( app.jinja_env, 'test.html') self.assertEqual('foobar', contents) self.assertEqual(filename, os.path.join(app.template_folder, 'test.html')) app.preprocess_request() self.assertTrue(up2date())
def test_list_templates(self): app = create_app(repo_path=self.repo_path, revision_id=REVISION_WORKING_DIR) default_templates_dir = os.path.join(os.path.dirname( os.path.abspath(__file__)), '..', 'templates') templates_dir = os.path.join(self.repo_path, app.template_folder) real_files = os.listdir(default_templates_dir) + \ os.listdir(templates_dir) with app.test_request_context(): app.preprocess_request() self.assertEqual(sorted(real_files), sorted(app.jinja_loader.list_templates()))
def test_list_templates(self): app = create_app(repo_path=self.repo_path, revision_id=REVISION_WORKING_DIR) default_templates_dir = os.path.join( os.path.dirname(os.path.abspath(__file__)), '..', 'templates') templates_dir = os.path.join(self.repo_path, app.template_folder) real_files = os.listdir(default_templates_dir) + \ os.listdir(templates_dir) with app.test_request_context(): app.preprocess_request() self.assertEqual(sorted(real_files), sorted(app.jinja_loader.list_templates()))
def test_reload_changectx_default(self): app = create_app(repo_path=self.repo_path, autoinit=False) commands.add(self.ui, self.repo) commands.forget(self.ui, self.repo, u2hg(os.path.join(self.repo_path, app.config['CONTENT_DIR']))) commands.commit(self.ui, self.repo, message=b'foo', user=b'foo') app.blohg.init_repo(REVISION_DEFAULT) client = app.test_client() rv = client.get('/') self.assertFalse(b'post/lorem-ipsum' in rv.data) self.assertFalse(b'post/example-post' in rv.data) commands.add(self.ui, self.repo) rv = client.get('/') self.assertFalse(b'post/lorem-ipsum' in rv.data) self.assertFalse(b'post/example-post' in rv.data) commands.commit(self.ui, self.repo, message=b'foo', user=b'foo') rv = client.get('/') self.assertTrue(b'post/lorem-ipsum' in rv.data) self.assertTrue(b'post/example-post' in rv.data) with codecs.open(os.path.join(self.repo_path, app.config['CONTENT_DIR'], 'about.rst'), 'a', encoding='utf-8') as fp: fp.write('\n\nTHIS IS A TEST!\n') rv = client.get('/about/') self.assertFalse(b'THIS IS A TEST!' in rv.data) commands.commit(self.ui, self.repo, message=b'foo', user=b'foo') rv = client.get('/about/') self.assertTrue(b'THIS IS A TEST!' in rv.data) with codecs.open(os.path.join(self.repo_path, app.config['CONTENT_DIR'], 'about.rst'), 'a', encoding='utf-8') as fp: fp.write('\n\nTHIS IS another TEST!\n') rv = client.get('/about/') self.assertTrue(b'THIS IS A TEST!' in rv.data) self.assertFalse(b'THIS IS another TEST!' in rv.data) commands.commit(self.ui, self.repo, message=b'foo', user=b'foo') rv = client.get('/about/') self.assertTrue(b'THIS IS A TEST!' in rv.data) self.assertTrue(b'THIS IS another TEST!' in rv.data)
def test_reload_changectx_default(self): app = create_app(repo_path=self.repo_path, autoinit=False) commands.add(self.ui, self.repo) commands.forget(self.ui, self.repo, os.path.join(self.repo_path, app.config['CONTENT_DIR'])) commands.commit(self.ui, self.repo, message='foo', user='******') app.blohg.init_repo(REVISION_DEFAULT) client = app.test_client() rv = client.get('/') self.assertFalse('post/lorem-ipsum' in rv.data) self.assertFalse('post/example-post' in rv.data) commands.add(self.ui, self.repo) rv = client.get('/') self.assertFalse('post/lorem-ipsum' in rv.data) self.assertFalse('post/example-post' in rv.data) commands.commit(self.ui, self.repo, message='foo', user='******') rv = client.get('/') self.assertTrue('post/lorem-ipsum' in rv.data) self.assertTrue('post/example-post' in rv.data) with codecs.open(os.path.join(self.repo_path, app.config['CONTENT_DIR'], 'about.rst'), 'a', encoding='utf-8') as fp: fp.write('\n\nTHIS IS A TEST!\n') rv = client.get('/about/') self.assertFalse('THIS IS A TEST!' in rv.data) commands.commit(self.ui, self.repo, message='foo', user='******') rv = client.get('/about/') self.assertTrue('THIS IS A TEST!' in rv.data) with codecs.open(os.path.join(self.repo_path, app.config['CONTENT_DIR'], 'about.rst'), 'a', encoding='utf-8') as fp: fp.write('\n\nTHIS IS another TEST!\n') rv = client.get('/about/') self.assertTrue('THIS IS A TEST!' in rv.data) self.assertFalse('THIS IS another TEST!' in rv.data) commands.commit(self.ui, self.repo, message='foo', user='******') rv = client.get('/about/') self.assertTrue('THIS IS A TEST!' in rv.data) self.assertTrue('THIS IS another TEST!' in rv.data)
def test_setup_app(self): app = create_app(repo_path=self.repo_path, autoinit=False) self.assertTrue(hasattr(app, 'blohg')) self.assertTrue(isinstance(app.jinja_loader, ChoiceLoader), 'Invalid Jinja2 loader.')
#!/usr/bin/env python from blohg import create_app application = create_app('/var/www/blog/')
def _create_app(repo_path, disable_embedded_extensions): return create_app(repo_path=os.path.abspath(repo_path), autoinit=False, embedded_extensions=not disable_embedded_extensions, debug=True)