6π
Iβve recently started using Twill via django-test-utils to unit test some of my Django work.
Instead of hardcoding URLs and/or using reverse I use things like twill.follow('Blog')
(to follow a βBlogβ link on the page).
This lets you really test the behavior of your website, just like a web browser would see it, and can catch things the other methods canβt. For example, it would fail if you accidentally removed the βBlogβ link from your navigation links.
10π
I would recommend to use βOption A. reverse()β because it enables you to decouple your test from the location at which the view is mounted.
for example if β/blog/test-blog/β becomes β/blog/test-better-url-blog/β for test will still be pertinent.
- Django redirect() with anchor (#) parameters
- Django __call__() missing 1 required keyword-only argument: 'manager'
- Validating a Django model field based on another field's value?
- Coverage in parallel for django tests
1π
It is better to use the reverse function to get the urls by view names. This will not only test your views but also ensures that your view names keep the same.
See it as internal API testing. You would recognize if some of your URLs are broken and get reminded to update your {% url %} tags in the templates.