首页 > 移动平台 > 详细

[Python]Test Driven Development in Flask application

时间:2014-01-23 09:58:51      阅读:440      评论:0      收藏:0      [点我收藏+]

In this recipe, i will describe how to use TDD method to developer Flask application.

from unittest import TestCase, main
from flask import Flask
from flask import request

class MyTest(TestCase):
    
    def test_flask(self):
        app = Flask(__name__)
        app.testing = True
        app.config[‘SERVER_NAME‘] = ‘localhost:5000‘
        app.config[‘APPLICATION_ROOT‘] = ‘/demo‘
        
        @app.route(‘/‘)
        def index():
            return request.url
       
        ctx = app.test_request_context()      
        self.assertEqual(ctx.request.url,‘http://localhost:5000/demo/‘,‘it is equal‘)
        with app.test_client()as client :
            rv = client.get(‘/‘)
            self.assertEqual(rv.data, ‘http://localhost:5000/demo/‘)

if __name__ == ‘__main__‘:
    main()
    


[Python]Test Driven Development in Flask application

原文:http://blog.csdn.net/wonderfan/article/details/18697029

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!