我遇到了与Flask-Restful API服务器的ajax请求中的unicode相关的奇怪问题.问题仅出现在一台计算机上,而不是另一台计算机上.
我有一个宁静的课.您可能会注意到字符字段设置为unicode.
class PostListApi(Resource):
def __init__(self):
self.reqparse = reqparse.RequestParser()
self.reqparse.add_argument('body', type = unicode, required = True, help = 'No description provided', location = 'json')
self.reqparse.add_argument('longitude', type = float, required = False, help = 'Unknown address', location = 'json')
self.reqparse.add_argument('latitude', type = float, required = False, help = 'Unknown address', location = 'json')
self.reqparse.add_argument('address', type = unicode, required = True, help = 'No address specified', location = 'json')
self.reqparse.add_argument('scheduled', type = str, required = True, help = 'Not scheduled correctly', …Run Code Online (Sandbox Code Playgroud) 我一直在尝试测试使用PyMongo的Flask应用程序.应用程序工作正常,但是当我执行单元测试时,我不断收到一条错误消息"工作在应用程序上下文之外".每次运行需要访问Mongo数据库的任何单元测试时,都会抛出此消息.
我一直在关注这个单元测试指南:http: //flask.pocoo.org/docs/testing/
我的应用程序的设计很简单,类似于标准的Flask教程.
有没有人有同样的问题?
class BonjourlaVilleTestCase(unittest.TestCase):
container = {}
def register(self, nickname, password, email, agerange):
"""Helper function to register a user"""
return self.app.post('/doregister', data={
'nickname' : nickname,
'agerange' : agerange,
'password': password,
'email': email
}, follow_redirects=True)
def setUp(self):
app.config.from_envvar('app_settings_unittests', silent=True)
for x in app.config.iterkeys():
print "Conf Key=%s, Value=%s" % (x, app.config[x])
self.app = app.test_client()
self.container["mongo"] = PyMongo(app)
self.container["mailer"] = Mailer(app)
self.container["mongo"].safe = True
app.container = self.container
def tearDown(self):
self.container["mongo"].db.drop()
pass
def test_register(self):
nickname = "test_nick"
password = …Run Code Online (Sandbox Code Playgroud)