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()
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()
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()
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()
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()
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()
def tearDown(self): requests_intercept.uninstall()
def deinit_test_server(): # Remove the intercept. remove_wsgi_intercept('localhost', 8080) requests_intercept.uninstall()
def fin(): requests_intercept.uninstall() cherrypy.engine.exit()
def uninstall(): requests_intercept.uninstall()
def end_mock(self): requests_intercept.uninstall() wsgi_intercept.remove_wsgi_intercept()
def teardown(): requests_intercept.uninstall()
def finalize(): remove_wsgi_intercept(HOST, PORT) uninstall()
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()
def wsgi(): requests_intercept.install() add_wsgi_intercept(host, port, bottle.default_app) yield requests_intercept.uninstall()
def teardown_module(module): data_teardown(testbed) requests_intercept.uninstall()