2013-11-13 13:20:58 +00:00
|
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
2013-12-04 22:19:51 +00:00
|
|
|
from werkzeug.test import Client
|
2013-11-13 13:20:58 +00:00
|
|
|
|
|
|
|
class FakeIP(object):
|
|
|
|
|
|
|
|
def __init__(self, app, ip):
|
|
|
|
self.app = app
|
|
|
|
self.ip = ip
|
|
|
|
|
|
|
|
def __call__(self, environ, start_response):
|
|
|
|
environ['REMOTE_ADDR'] = self.ip
|
|
|
|
return self.app(environ, start_response)
|
|
|
|
|
|
|
|
|
2013-12-04 22:19:51 +00:00
|
|
|
class JSONClient(Client):
|
|
|
|
|
|
|
|
def open(self, *args, **kwargs):
|
|
|
|
kwargs.setdefault('content_type', 'application/json')
|
|
|
|
return super(JSONClient, self).open(*args, **kwargs)
|
|
|
|
|
|
|
|
|
2013-11-13 13:20:58 +00:00
|
|
|
class Dummy:
|
|
|
|
|
|
|
|
status = 200
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def read(self):
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
|
|
pass
|
|
|
|
|
|
|
|
curl = lambda method, host, path: Dummy()
|
|
|
|
loads = lambda data: json.loads(data.decode('utf-8'))
|