How should I test a database-driven Django CMS for 404 errors?

杀马特。学长 韩版系。学妹 提交于 2019-12-05 11:53:27

This is a much simpler problem than the one given in your previous question. It has quite a few solutions.

Google Webmaster Tools

If you don't mind a slight delay, you can make use of Google Webmaster Tools which will report all 404 errors detected by it's crawler.

Django TestCase

The very thing I was reluctant to recommend in the previous question. Why I am suggesting it now? Well the problem seems simpler. You don't need all the data in your live database. So it's much easier and quicker to create your fixtures.

You probably have a read only replica that you are using for backup. If you invoke ./manage.py test with the -k flag on the read only replica you can actually do quite a lot of testing. You can do quite a bit more if your code does not use any manual transactions.

A scraping framework

Though not exactly designed for finding 404 errors, a web scraping framework such as 404 can be used against your site to detect both internal and external 404 errors.

python requests

You can write a pytest test case to read all the URLs on your site and hit them using python requests or any other http api. By not using django unit tests, you are not troubled by having to setup a test database. pytest can asked to pull the data direct from your live server.

Selenium / Beautifullsoup

Similar to scraping framework above. This too can be used with pytest so that you don't need to set up a test database. Read access can be granted to a test user account on the main database.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!