示例#1
0
def test_post_to_closet():
    url = 'http://tankt.peermore.com:8080/closet/newtank'
    data = {'csrf_token': csrf, 'redir': 1}
    files = {'file': ('heg3.gif', open('test/heg3.gif', 'rb'), 'image/gif')}
    headers = {'cookie': cookie}
    response = requests.post(url,
                             data=data,
                             files=files,
                             headers=headers,
                             allow_redirects=False)

    assert response.status_code == 303
    assert response.headers[
        'location'] == 'http://tankt.peermore.com:8080/bags/newtank/tiddlers/heg3.gif'

    response = requests.get(response.headers['location'],
                            allow_redirects=False)
    assert response.status_code == 302
    assert response.headers['location'].startswith(
        'https://tank-binaries.s3.amazonaws.com/')

    requests_intercept.uninstall()
    response = requests.get(response.headers['location'],
                            allow_redirects=False)
    assert response.status_code == 200
    assert response.headers['content-type'] == 'image/gif'
    requests_intercept.install()
示例#2
0
文件: base.py 项目: smurfix/pybble
	def tearDown(self):
		if not skip_httpclient:
			http_client_intercept.uninstall()
		if not skip_httplib2:
			httplib2_intercept.uninstall()
		if not skip_requests:
			requests_intercept.uninstall()
		if not skip_urllib:
			urllib_intercept.uninstall_opener()
示例#3
0
def wsgi_intercept_app():
    """Creates WSGI app that receives input directly from requests via wsgi_intercept.
    This skips HTTP request to athana and can be used to test the tests"""
    from wsgi_intercept import requests_intercept, add_wsgi_intercept
    requests_intercept.install()
    app = make_app()
    add_wsgi_intercept(HOST, PORT, lambda: app)
    yield app
    requests_intercept.uninstall()
示例#4
0
def wsgi_intercept_app():
    """Creates WSGI app that receives input directly from requests via wsgi_intercept.
    This skips HTTP request to athana and can be used to test the tests"""
    from wsgi_intercept import requests_intercept, add_wsgi_intercept
    requests_intercept.install()
    app = make_app()
    add_wsgi_intercept(HOST, PORT, lambda: app)
    yield app
    requests_intercept.uninstall()
示例#5
0
def test_redirect_region():
    if client.REGION == 'US':
        # US region server doesn't support app router now
        return
    # setup
    old_app_router = client.app_router
    client.app_router = AppRouter('test_app_id')
    requests_intercept.install()

    def fake_app_router(environ, start_response):
        assert environ['PATH_INFO'] == '/1/route'
        start_response('200 OK', [('Content-Type', 'application/json')])
        return [
            json.dumps({
                'api_server': 'fake-redirect-server',
                'ttl': 3600,
            }).encode('utf-8')
        ]

    host, port = 'app-router.leancloud.cn', 443
    add_wsgi_intercept(host, port, lambda: fake_app_router)

    def fake_redirect_server(environ, start_response):
        start_response('307', [('Content-Type', 'application/json')])
        return [
            json.dumps({
                'api_server': 'fake-api-server',
                'ttl': 3600,
            }).encode('utf-8')
        ]

    host, port = 'fake-redirect-server', 443
    add_wsgi_intercept(host, port, lambda: fake_redirect_server)

    def fake_api_server(environ, start_response):
        start_response('200', [('Content-Type', 'application/json')])
        return [json.dumps({
            'result': 42,
        }).encode('utf-8')]

    host, port = 'fake-api-server', 443
    add_wsgi_intercept(host, port, lambda: fake_api_server)

    # test
    assert client.get('/redirectme').json()['result'] == 42

    # teardown
    client.app_router = old_app_router
    requests_intercept.uninstall()
示例#6
0
def test_redirect_region():
    if client.REGION == 'US':
        # US region server doesn't support app router now
        return
    # setup
    old_app_router = client.app_router
    client.app_router = AppRouter('test_app_id')
    requests_intercept.install()

    def fake_app_router(environ, start_response):
        assert environ['PATH_INFO'] == '/1/route'
        start_response('200 OK', [('Content-Type', 'application/json')])
        return [json.dumps({
            'api_server': 'fake-redirect-server',
            'ttl': 3600,
        }).encode('utf-8')]

    host, port = 'app-router.leancloud.cn', 443
    add_wsgi_intercept(host, port, lambda: fake_app_router)

    def fake_redirect_server(environ, start_response):
        start_response('307', [('Content-Type', 'application/json')])
        return [json.dumps({
            'api_server': 'fake-api-server',
            'ttl': 3600,
        }).encode('utf-8')]

    host, port = 'fake-redirect-server', 443
    add_wsgi_intercept(host, port, lambda: fake_redirect_server)


    def fake_api_server(environ, start_response):
        start_response('200', [('Content-Type', 'application/json')])
        return [json.dumps({
            'result': 42,
        }).encode('utf-8')]

    host, port = 'fake-api-server', 443
    add_wsgi_intercept(host, port, lambda: fake_api_server)

    # test
    assert client.get('/redirectme').json()['result'] == 42

    # teardown
    client.app_router = old_app_router
    requests_intercept.uninstall()
示例#7
0
def test_post_to_closet():
    url = 'http://tankt.peermore.com:8080/closet/newtank'
    data = {'csrf_token': csrf, 'redir': 1}
    files = {'file': ('heg3.gif', open('test/heg3.gif', 'rb'), 'image/gif')}
    headers = {'cookie': cookie}
    response = requests.post(url, data=data, files=files, headers=headers,
            allow_redirects=False)

    assert response.status_code == 303
    assert response.headers['location'] == 'http://tankt.peermore.com:8080/bags/newtank/tiddlers/heg3.gif'

    response = requests.get(response.headers['location'], allow_redirects=False)
    assert response.status_code == 302
    assert response.headers['location'].startswith(
            'https://tank-binaries.s3.amazonaws.com/')

    requests_intercept.uninstall()
    response = requests.get(response.headers['location'], allow_redirects=False)
    assert response.status_code == 200
    assert response.headers['content-type'] == 'image/gif'
    requests_intercept.install()
示例#8
0
 def tearDown(self):
     requests_intercept.uninstall()
示例#9
0
def deinit_test_server():
    # Remove the intercept.
    remove_wsgi_intercept('localhost', 8080)
    requests_intercept.uninstall()
示例#10
0
 def fin():
     requests_intercept.uninstall()
     cherrypy.engine.exit()
示例#11
0
def uninstall():
    requests_intercept.uninstall()
示例#12
0
 def end_mock(self):
     requests_intercept.uninstall()
     wsgi_intercept.remove_wsgi_intercept()
示例#13
0
def teardown():
    requests_intercept.uninstall()
示例#14
0
 def finalize():
     remove_wsgi_intercept(HOST, PORT)
     uninstall()
示例#15
0
 def finalize():
     remove_wsgi_intercept(HOST, PORT)
     uninstall()
示例#16
0
 def tearDown(self):
     # Uninstall the requests library intercept.
     requests_intercept.uninstall()
     # Initialize the intercepts for archive and publishing.
     uninstall_intercept()
def after_all(context):
    from wsgi_intercept import requests_intercept
    requests_intercept.uninstall()
    context.runner.teardown_databases(context.old_db_config)
    context.runner.teardown_test_environment()
示例#18
0
 def tearDown(self):
     # Uninstall the requests library intercept.
     requests_intercept.uninstall()
     # Initialize the intercepts for archive and publishing.
     uninstall_intercept()
示例#19
0
def wsgi():
    requests_intercept.install()
    add_wsgi_intercept(host, port, bottle.default_app)
    yield
    requests_intercept.uninstall()
示例#20
0
def teardown_module(module):
    data_teardown(testbed)
    requests_intercept.uninstall()
示例#21
0
def teardown():
    requests_intercept.uninstall()
示例#22
0
 def fin():
     requests_intercept.uninstall()
     cherrypy.engine.exit()