If POST is successfully sent to the endpoint of the form, I redirect back to the same endpoint with some URL parameters that my client side code can interact with.
@bp.route('/submit', methods=['GET', 'POST']) def submit(): form = SubmissionForm() labels = current_app.config['TRELLO_LABELS'] if form.validate_on_submit(): submission = Submission().create( title=form.data['title'], email=form.data['email'], card_id=card.id, card_url=card.url)
But I ran into some problems trying to write a test for this code, since I cannot figure out how to verify that these URL parameters are in my redirect URL. My incomplete test code:
import pytest @pytest.mark.usefixtures('session') class TestRoutes: def test_submit_post(self, app, mocker): with app.test_request_context('/submit', method='post', query_string=dict( email=' email@example.com ', title='foo', pitch='foo', format='IN-DEPTH', audience='INTERMEDIATE', description='foo', notes='foo')): assert resp.status_code == 200
I tried several different methods to test this. With and without a context manager, I test_client deep into the source of Flask and Werkzeug on the pages test_client and test_request_context .
I just want to verify that the URL parameters for success and id exist when redirecting after a valid POST.
source share