def test_static_folder_from_disk(self): bp = BlohgBlueprint('foo', __name__, static_folder='st') app = Flask(__name__) app.register_blueprint(bp) view_func = app.view_functions['foo.static'] # poor test, but should be enough :) self.assertEquals(view_func.__name__, 'send_static_file')
def test_static_folder_from_repo_module(self, get_root_path): get_root_path.return_value = ':repo:ext' bp = BlohgBlueprint('foo', __name__, static_folder='st') app = Flask(__name__) app.register_blueprint(bp) view_func = app.view_functions['foo.static'] self.assertIsInstance(view_func, BlohgStaticFile) self.assertEquals(view_func.directory, 'ext/st')
def test_jinja_loader_from_disk(self): bp = BlohgBlueprint('foo', __name__, template_folder='templ') fake_dir = os.path.join(cwd, 'templ') self.assertEquals(len(bp.jinja_loader.searchpath), 1) self.assertEquals(bp.jinja_loader.searchpath[0], fake_dir)
def test_jinja_loader_from_repo_module(self, get_root_path): get_root_path.return_value = ':repo:ext' bp = BlohgBlueprint('foo', __name__, template_folder='templ') self.assertIsInstance(bp.jinja_loader, BlohgLoader) self.assertEquals(bp.jinja_loader.template_folder, 'ext/templ')
# -*- coding: utf-8 -*- import os import ipaddress import hglib from flask import request from blohg.ext import BlohgBlueprint, BlohgExtension ext = BlohgExtension(__name__) deploy = BlohgBlueprint('deploy', __name__, url_prefix='/deploy') BB_RANGE1 = ipaddress.ip_network(u'104.192.143.192/28', strict=False) BB_RANGE2 = ipaddress.ip_network(u'104.192.143.208/28', strict=False) @deploy.route('/', methods=['POST']) def update_blog(): addr = ipaddress.ip_address(unicode(request.headers.get('X-Real-IP'))) if addr in BB_RANGE1 or addr in BB_RANGE2: client = hglib.open(os.getcwd()) updated = client.pull(update=True) client.close() return 'Repository updated: {}'.format(updated), 200 else: return "Address {} is not authorized".format(str(addr)), 403 @ext.setup_extension def setup_extension(app): app.register_blueprint(deploy)