Test coverage report: ftp_deploy.server.views.login

# ftp_deploy.server.views.login: 28 total statements, 100.0% covered

Generated: Thu 2013-12-19 21:13 GMT

Source file: /var/www/service.dev/service/ftp_deploy/server/views/login.py

Stats: 21 executed, 0 missed, 7 excluded, 17 ignored

1. `from django.http import HttpResponseRedirect`
2. `from django.contrib import messages`
3. `from django.contrib.auth import authenticate, login, logout`
4. `from django.core.urlresolvers import reverse, reverse_lazy`
5. `from django.shortcuts import redirect`
6. `from django.views.generic import FormView, View`
7. ``
8. `from ftp_deploy.server.forms import LoginForm`
9. ``
10. ``
11. `class loginView(FormView):`
12. ``
13. `"""View for login"""`
14. ``
15. `form_class = LoginForm`
16. `template_name = 'ftp_deploy/login/login.html'`
17. `success_url = reverse_lazy('ftpdeploy_dashboard')`
18. ``
19. `def get(self, request, *args, **kwargs):`
20. `if self.request.user.is_authenticated():`
21. `return HttpResponseRedirect(reverse('ftpdeploy_dashboard'))`
22. `return super(loginView, self).get(request, *args, **kwargs)`
23. ``
24. `def form_valid(self, form):`
25. `username = form.cleaned_data['username']`
26. `password = form.cleaned_data['password']`
27. `user = authenticate(username=username, password=password)`
28. `if user is not None:`
29. `login(self.request, user)`
30. `else:`
31. `messages.error(self.request, 'Username or Password incorrect.')`
32. `return HttpResponseRedirect(reverse('ftpdeploy_login'))`
33. ``
34. `return super(loginView, self).form_valid(form)`
35. ``
36. ``
37. `class logoutView(View):`
38. ``
39. `"""View for logout"""`
40. ``
41. `def get(self, request, *args, **kwargs):`
42. `logout(request)`
43. `return redirect(reverse('ftpdeploy_login'))`
44. ``
45. ``