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")
>         dict_act = {}
>         email = request.session.get('email')
>         email = request.session.get('email')
>         # save_url = save_current_url(request, email)
>         # Based on logged in user email filtering list of objects.
>         account = vk_Account_history.objects.filter(email=email)
>         # Calculating logged in time.
>         for i in account:
>             some_date = diff_time_Acnt(i)
>             dict_act[i.id] = some_date
>         return render(request, 'account_security.html', {'account':
> account, 'fullname': fullname(email),
>             some_date = diff_time_Acnt(i)
>             dict_act[i.id] = some_date
>         return render(request, 'account_security.html', {'account':
> account, 'fullname': fullname(email),
>                                                          'name':
> first_last_initial(email),
>                                                          'time':
> settings.SESSION_IDLE_TIMEOUT,
>                                                          'some_date':
> dict_act,
>                                                          })
>     except Exception as e:
>         logging.error(e)
>         return render(request, 'account_security.html', {'account':
> account, 'fullname': fullname(email),
>         logging.error(e)
>         return render(request, 'account_security.html', {'account':
> account, 'fullname': fullname(email),
>                                                          'name':
> first_last_initial(email),
>                                                          'time':
> settings.SESSION_IDLE_TIMEOUT,
>                                                          'some_date':
> dict_act,
>                                                          })




Likewise it's happening in other tests also.

Thank you
~Salima

On Thu, May 19, 2022 at 2:24 AM Kasper Laudrup <laud...@stacktrace.dk>
wrote:

> On 18/05/2022 09.20, Salima Begum wrote:
> > How to write a test case for total function without missing any
> > statement. Please help me out how to write a test case for above
> > function.
> >
>
> You inject values in your test case to make sure all branches are covered.
>
> Sometimes that requires a bit more trickery with mocking out some things
> but in the case of the function you've shown it should be fairly simple
> to achieve 100% test coverage, at least from the point of a coverage tool.
>
> Any specific parts you're having issues with? I can't help to notice
> that you return the exact same thing to the use in the case of any
> exception but only log the exception. That seems wrong but I'm not sure
> if that's related to your question.
>
> 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/5e56c8b0-e5f6-9c9b-a9fd-77b5eedcd0d1%40stacktrace.dk
> .
>

-- 
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/CAMSz6bnhpcwNJeWtVu%3DNvEpSTVYe2s8bU6Ww4_FH6JgUjiCaag%40mail.gmail.com.

Reply via email to