Testing Whether A Url Is Giving 500 Error Or Not In Django
I want to test Urls whether am getting 500 error or not. In normal case where login is not required I get status_code 200 but where login is required, it gives me 302 error. So, h
Solution 1:
The 302 is because your user is being redirected to the login screen.
If you want to test views that require authentication, you'll need to authenticate the user first.
Luckily, this is very easy to do. See the docs.
# Create a new user
User.objects.create_user(
username='fred',
password='secret'
)
# Start up a test client
c = Client()
# Authenticate the user on the client
c.login(username='fred', password='secret')
# Do your thing
response = c.get(reverse('event-dashboard'))
self.assertEqual(response.status_code, 200)
Post a Comment for "Testing Whether A Url Is Giving 500 Error Or Not In Django"