예제 #1
0
    def setUp(self):
        super(BrowserClientTest, self).setUp()
        self.browser = Browser()

        # Build the path to the example.html file
        path = os.path.dirname(os.path.abspath(__file__))
        path = os.path.join(path, 'helpers', 'example.html')
        self.path = 'file://%s' % path
예제 #2
0
    def setUp(self):
        super(TestBrowser, self).setUp()
        self.browser = Browser()

        # Build the path to the example.html file
        path = os.path.dirname(os.path.abspath(__file__))
        path = os.path.join(path, 'helpers', 'example.html')
        self.path = 'file://%s' % path
        with open(path, 'r') as f:
            self.html = f.read()
예제 #3
0
    def setUp(self):
        super(TestBrowserRedirection, self).setUp()
        self.browser = Browser()

        from wsgiref.simple_server import make_server
        import threading
        import random

        self.port = random.randint(8000, 9999)

        class WSGIRunner(threading.Thread):

            def __init__(self, app, port):
                super(WSGIRunner, self).__init__()
                self.server = make_server('', port, app)

            def run(self):
                self.server.serve_forever()

            def stop(self):
                self.server.shutdown()
                self.join()

        def app(environ, start_response):
            """
            A sample WSGI app that forcibly redirects all requests to /
            """
            if environ['PATH_INFO'] == '/':
                response_headers = [('Content-type', 'text/plain')]
                start_response('200 OK', response_headers)
                return [
                    bytes('Hello world!', 'utf-8') if PY3 else 'Hello world!'
                ]

            response_headers = [
                ('Location', '/'),
                ('Content-type', 'text/plain')
            ]
            start_response('302 Found', response_headers)
            return [bytes('', 'utf-8') if PY3 else '']

        self.runner = WSGIRunner(app, self.port)
        self.runner.start()
예제 #4
0
from zombie import Browser
b = Browser()
b.visit('https://github.com/ryanpetrello/python-zombie')