class Webapp(object): def __init__(self, app): super(Webapp, self).__init__() self.app = app self.loopback = FlaskLoopback(self.app) self.hostname = str(uuid.uuid1()) def activate(self): self.loopback.activate_address((self.hostname, 80)) def deactivate(self): self.loopback.deactivate_address((self.hostname, 80)) def _request(self, method, path, *args, **kwargs): raw_response = kwargs.pop("raw_response", False) if path.startswith("/"): path = path[1:] assert not path.startswith("/") returned = requests.request( method, "http://{0}/{1}".format(self.hostname, path), *args, **kwargs) if raw_response: return returned returned.raise_for_status() return returned.json()
def url(request, flask_app): address = str(uuid1()) returned = URL('http://{0}'.format(address)) webapp = FlaskLoopback(flask_app) webapp.activate_address((address, 80)) @request.addfinalizer def finalize(): webapp.deactivate_address((address, 80)) return returned
def _get_client_context(): from flask_app.app import app from flask.ext.loopback import FlaskLoopback from backslash import Backslash as BackslashClient app.config['PROPAGATE_EXCEPTIONS'] = True address = str(uuid4()) loopback = FlaskLoopback(app) loopback.activate_address((address, 80)) try: yield BackslashClient('http://{0}'.format(address)) finally: loopback.deactivate_address((address, 80))
def _get_client_context(): from flask_app.app import create_app from flask.ext.loopback import FlaskLoopback from backslash import Backslash as BackslashClient app = create_app({'DEBUG': True, 'TESTING': True, 'SECRET_KEY': 'dummy', 'SECURITY_PASSWORD_SALT': 'dummy'}) with app.app_context(): address = str(uuid4()) loopback = FlaskLoopback(app) loopback.activate_address((address, 80)) try: yield BackslashClient('http://{0}'.format(address)) finally: loopback.deactivate_address((address, 80))
def __init__(self, app): super(Webapp, self).__init__() self.app = app self.loopback = FlaskLoopback(self.app) self.hostname = str(uuid.uuid1())
def __init__(self, app): super(Webapp, self).__init__() self.app = app self.loopback = FlaskLoopback(self.app) self.hostname = str(uuid4()) self.url = URL('http://{0}'.format(self.hostname))