Herramientas de usuario

Herramientas del sitio


wiki2:python:flask:testing

¡Esta es una revisión vieja del documento!


Flask Testing

Basic

Live Server

import urllib2
from flask import Flask
from flask.ext.testing import LiveServerTestCase
 
class MyTest(LiveServerTestCase):
 
    def create_app(self):
        app = Flask(__name__)
        app.config['TESTING'] = True
        # Default port is 5000
        app.config['LIVESERVER_PORT'] = 8943
        return app
 
    def test_server_is_up_and_running(self):
        response = urllib2.urlopen(self.get_server_url())
        self.assertEqual(response.code, 200)

Not rendering templates

You need to set render_templates to False. Also use assert_template_used to know if the template was rendered.

class TestNotRenderTemplates(TestCase):
 
    render_templates = False
 
    def test_assert_mytemplate_used(self):
        response = self.client.get("/template/")
 
        self.assert_template_used('mytemplate.html')
wiki2/python/flask/testing.1439139821.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)