예제 #1
0
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()
예제 #2
0
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()
예제 #3
0
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
예제 #4
0
파일: db.py 프로젝트: boazin/backslash
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))
예제 #5
0
파일: db.py 프로젝트: omergertel/backslash
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))
예제 #6
0
 def __init__(self, app):
     super(Webapp, self).__init__()
     self.app = app
     self.loopback = FlaskLoopback(self.app)
     self.hostname = str(uuid.uuid1())
예제 #7
0
 def __init__(self, app):
     super(Webapp, self).__init__()
     self.app = app
     self.loopback = FlaskLoopback(self.app)
     self.hostname = str(uuid.uuid1())
예제 #8
0
 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))