Created
January 29, 2014 19:24
-
-
Save vladzloteanu/8695023 to your computer and use it in GitHub Desktop.
Flask test client using full URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from flask import Flask, request | |
app = Flask(__name__) | |
app.testing = True | |
@app.route('/action') | |
def action(): | |
return "" | |
class MyTestCase(unittest.TestCase): | |
def test_get_with_path(self): | |
with app.test_client() as c: | |
rv = c.get('/action?vodka=42') | |
assert 'vodka' in request.args # assertion OK | |
def test_get_with_complete_url(self): | |
with app.test_client() as c: | |
rv = c.get('http://domain.com/action?vodka=42') | |
assert 'vodka' in request.args # assertion error | |
def test_post_with_complete_url(self): | |
with app.test_client() as c: | |
rv = c.post('http://domain.com/action?vodka=42', data={'gin': 43}) | |
assert 'gin' in request.form # assertion OK | |
assert 'vodka' in request.args # assertion error | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment