On 19/05/2022 05.45, Salima Begum wrote: > Hi, > Thank you for your response. We are basically writing a unit test for > Account_security function with this unit test code. > > > Unit test code : > -------------------------------------------------------- > > def test_Account_security_url(self): > path = reverse('account-security') > assert resolve(path).view_name == 'account-security' > > --------------------------------------------------------- > > Here is the function for which we write above unit test, but the test is not > covering these red colored statements. So, we are wondering what could be the > issue here. > > > def Account_security(request): > try: > if ((request.session.get('email') is None) or > (request.session.get('email') == "")): > return HttpResponseRedirect("/home")
You'll always return here since your request doesn't have a session object with an email so the rest of the code never gets covered. I suggest you look into the basics of how you can test your Django views. There's tons of documentation on how to do that out there including the official Django documentation. Kind regards, Kasper Laudrup -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/57DCCB9B-9F18-4DE9-8B17-5128E5316AB3%40stacktrace.dk.