Skip to content

Instantly share code, notes, and snippets.

@vladzloteanu
Created January 29, 2014 19:24
Show Gist options
  • Save vladzloteanu/8695023 to your computer and use it in GitHub Desktop.
Save vladzloteanu/8695023 to your computer and use it in GitHub Desktop.
Flask test client using full URL
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