0

We are testing a Python Flask application using flask.app.test_client like explained here
Our application works with JWT tokens for authentication purpose, so all API call's must have the token specified. Is there way to provide JWT as header to app.tests_client ?
Below is the testing code snippet,

from app import app   # our flask application
import unittest
class AppTests(unittest.TestCase):
    def setUp(self):
        self.app = app.app.test_client()
    def tearDown(self):
        pass
    def test_info_page(self):
        info_rs = self.app.get('/info')  ## --> this request should go with header JWT token.
        self.assertEqual(info_rs.status_code, 200)
AArias
  • 2,558
  • 3
  • 26
  • 36
  • Is this what you want? https://stackoverflow.com/questions/25860304/how-do-i-set-response-headers-in-flask . – deathangel908 May 07 '18 at 09:45
  • 1
    If you want to add headers to the request itself, you can use this answer https://stackoverflow.com/a/18266224/3872976 – deathangel908 May 07 '18 at 09:46
  • yes @deathangel908 , this is https://stackoverflow.com/questions/18263844/flask-and-werkzeug-testing-a-post-request-with-custom-headers/18266224#18266224 what i was looking for, Thanks. – Reddysekhar Gaduputi May 07 '18 at 09:53

0 Answers0