Can I find out if a view is called in the django test client?

I use a custom login screen for the django site I'm working on, and users will be prompted with a CAPTCHA call each time they log in. (It seems that the excess that I know, but for a number of complex reasons, it is impossible to establish a decent password policy that leaves the log open for brute force attacks)

I want to be able to tell from within the view if it is called by the django testing client so that in this particular case it can ignore the answer with quotation marks.

Is there any way to do this? (Preferably one that does not rely on any unique request headers that can be set by the client, as they can be tampered with)

Thanks!

+3
source share
1 answer

I would not base it on a test client call, I would have a parameter that indicates that the system is under testing. When you run the Django tests, you can give it another settings file that sets TESTING = True, and then imports your original settings. Then you can check settings.TESTING to decide whether to display captcha.

+1
source

Source: https://habr.com/ru/post/1717372/


All Articles