How can I fake request.POST and GET params for unit testing in Flask?

后端 未结 5 1132
广开言路
广开言路 2020-12-30 18:33

I would like to fake request parameters for unit testing. How can I achieve this in Flask?

5条回答
  •  囚心锁ツ
    2020-12-30 19:26

    I still had issue with this when testing post form data for logging in this worked for me.

    def login(self, username, password):
        return self.app.post('/', data='Client_id=' + username +'&Password=' + password,
                             follow_redirects=True,content_type='application/x-www-form-urlencoded')
    

    I found this is out this way.

    Chrome: Developer mode --> Doc --> HTML doc that was requested --> Headers Tab --> Form data --> view source

提交回复
热议问题